diff --git a/bot.py b/bot.py index 128f51f..4d895f1 100644 --- a/bot.py +++ b/bot.py @@ -393,8 +393,53 @@ async def ssldomains(ctx): await ctx.response.send_message("Domains in the SSL expiry notification list:\n" + "\n".join(domains),ephemeral=True) +@tree.command(name="sslremove", description="Remove a domain from the SSL expiry notification list") +async def sslremove(ctx, domain: str): + # Get user id + userid = str(ctx.user.id) + # Get all domains for user + domains = [] + with open("/mnt/sslnotify.txt", "r") as file: + lines = file.readlines() + for line in lines: + line = line.strip() + if not line: + continue + if line.startswith(userid): + _, dom = line.split(",") + domains.append(dom) + if not domains: + await ctx.response.send_message("You have no domains in the SSL expiry notification list",ephemeral=True) + return + + if domain not in domains: + await ctx.response.send_message("Domain not found in the SSL expiry notification list",ephemeral=True) + return + + with open("/mnt/sslnotify.txt", "w") as file: + for line in lines: + line = line.strip() + if not line: + continue + if not line.startswith(userid): + file.write(line + "\n") + for dom in domains: + if domain != dom: + file.write(userid + "," + dom + "\n") + + await ctx.response.send_message("Domain removed from the SSL expiry notification list",ephemeral=True) +@tree.command(name="manualsslcheck", description="Manually check SSL certificate") +async def manualsslcheck(ctx): + if (ctx.user.id != ADMINID): + await log("User: " + str(ctx.user.name) + " tried to use the manualsslcheck command") + await ctx.response.send_message("You don't have permission to use this command",ephemeral=True) + + await ctx.response.send_message("SSL checking",ephemeral=True) + await checkForSSLExpiry() + await ctx.response.send_message("SSL check complete",ephemeral=True) + # When the bot is ready @client.event @@ -403,12 +448,12 @@ async def on_ready(): ADMINID = client.application.owner.id await tree.sync() updateStatus() + await checkForSSLExpiry() -client.run(TOKEN) # Every 12 hours check for SSL expiry scheduler = AsyncIOScheduler() scheduler.add_job(checkForSSLExpiry, 'interval', hours=12) scheduler.start() -checkForSSLExpiry() \ No newline at end of file +client.run(TOKEN) \ No newline at end of file