From 2ac733f33d923aa9a2372322af70feb9401b38ca Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Wed, 27 Sep 2023 18:11:27 +1000 Subject: [PATCH] bot: Add try for TLSA missing --- bot.py | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/bot.py b/bot.py index d4ab153..89a4583 100644 --- a/bot.py +++ b/bot.py @@ -196,7 +196,11 @@ async def ssl(ctx, domain: str): message = message + "\n## TLSA Record from webserver:\n`" + tlsa_server + "`\n" + else: + message = message + "\n## Website Certificate:\n:x: No certificate found\n" + message = message + "\n## TLSA Record from webserver:\n:x: No certificate found\n" + try: # Check for TLSA record response = resolver.resolve("_443._tcp."+domain, "TLSA") tlsa_records = [] @@ -212,25 +216,26 @@ async def ssl(ctx, domain: str): message = message + "\n## Result:\n:white_check_mark: TLSA record matches certificate\n" else: message = message + "\n## Result:\n:x: TLSA record does not match certificate\n" + + except: + message = message + "\n## TLSA Records from DNS:\n:x: No TLSA record found\n" + message = message + "\n## Result:\n:x: No TLSA record found\n" - # If message is too long, send it in 2 messages - if (len(message) > 2000): - # Split on the last line under 2000 characters - message1 = message[:2000] - message1 = message1[:message1.rfind("\n")] - message2 = message[len(message1):] - - - await ctx.response.send_message(message1) - await ctx.channel.send(message2) - - - else: - await ctx.response.send_message(message) + # If message is too long, send it in 2 messages + if (len(message) > 2000): + # Split on the last line under 2000 characters + message1 = message[:2000] + message1 = message1[:message1.rfind("\n")] + message2 = message[len(message1):] + + + await ctx.response.send_message(message1) + await ctx.channel.send(message2) + + else: - ctx.response.send_message(f"No certificate found for {domain}") - return + await ctx.response.send_message(message) # Catch all exceptions except Exception as e: