bot: Async the ssl check function
All checks were successful
Build Docker / Build Docker (push) Successful in 16s

This commit is contained in:
Nathan Woodburn 2023-10-01 22:53:54 +11:00
parent de5c8787ba
commit 0ac3b1592b
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1

6
bot.py
View File

@ -316,7 +316,7 @@ def updateStatus():
activity=discord.Activity(type=discord.ActivityType.watching, name=activityMessage) activity=discord.Activity(type=discord.ActivityType.watching, name=activityMessage)
client.loop.create_task(client.change_presence(activity=activity)) client.loop.create_task(client.change_presence(activity=activity))
def checkForSSLExpiry(): async def checkForSSLExpiry():
with open("/mnt/sslnotify.txt", "r") as file: with open("/mnt/sslnotify.txt", "r") as file:
lines = file.readlines() lines = file.readlines()
for line in lines: for line in lines:
@ -358,12 +358,12 @@ def checkForSSLExpiry():
if expiry_date < datetime.datetime.now() + datetime.timedelta(days=7): if expiry_date < datetime.datetime.now() + datetime.timedelta(days=7):
user = client.get_user(int(userid)) user = client.get_user(int(userid))
if user: if user:
user.send(f"SSL certificate for {domain} expires soon") await user.send(f"SSL certificate for {domain} expires soon")
else: else:
# Test by sending a message # Test by sending a message
user = client.get_user(int(userid)) user = client.get_user(int(userid))
if user: if user:
user.send(f"SSL certificate for {domain} is valid") await user.send(f"SSL certificate for {domain} is valid")
except Exception as e: except Exception as e:
print(e, flush=True) print(e, flush=True)
continue continue