diff options
author | Parker <contact@pkrm.dev> | 2024-05-18 20:06:51 -0500 |
---|---|---|
committer | Parker <contact@pkrm.dev> | 2024-05-18 20:06:51 -0500 |
commit | 32ab780b461c1c2b5e3e34c35b5902ed7006b95e (patch) | |
tree | b8717f5d5136b36c3d9bfe9e00346a7747003596 /code/bot.py | |
parent | f0ec1c5a896744e4cdaa377a50b6277562a29f7f (diff) |
Create CordArr
Diffstat (limited to 'code/bot.py')
-rw-r--r-- | code/bot.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/code/bot.py b/code/bot.py new file mode 100644 index 0000000..4b3d96d --- /dev/null +++ b/code/bot.py @@ -0,0 +1,51 @@ +import discord +from discord.ext import commands +from discord.ext import tasks +import datetime +import sqlite3 +import os + +from validate_config import create_config +from global_variables import LOG, BOT_TOKEN + + +class MyBot(commands.Bot): + def __init__(self): + super().__init__( + command_prefix="#", + intents=discord.Intents.default(), + ) + + async def setup_hook(self): + create_config() + delete_old_temp_accounts.start() + for ext in os.listdir("./code/cogs"): + if ext.endswith(".py"): + await self.load_extension(f"cogs.{ext[:-3]}") + + +bot = MyBot() +bot.remove_command("help") + + +@bot.event +async def on_ready(): + LOG.info(f"{bot.user} has connected to Discord.") + + +@tasks.loop(seconds=60) +async def delete_old_temp_accounts(): + # Delete all of the temporary Jellyfin accounts that have passed + # their expiration time + db = sqlite3.connect("cordarr.db") + cursor = db.cursor() + cursor.execute( + "DELETE FROM jellyfin_accounts WHERE deletion_time < ?", + (datetime.datetime.now(),), + ) + db.commit() + db.close() + + +if __name__ == "__main__": + bot.run(BOT_TOKEN) |