From 3c18d552c2c9eb15834b33687915a7b16c98883b Mon Sep 17 00:00:00 2001 From: Parker Date: Sat, 25 Jan 2025 22:58:41 -0600 Subject: reupload --- code/cogs/count.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 code/cogs/count.py (limited to 'code/cogs/count.py') diff --git a/code/cogs/count.py b/code/cogs/count.py new file mode 100644 index 0000000..67e0139 --- /dev/null +++ b/code/cogs/count.py @@ -0,0 +1,40 @@ +from discord.ext import commands, tasks +import aiosqlite +import sqlite3 + +class Count(commands.Cog): + def __init__(self, bot): + self.bot = bot + + async def cog_load(self): + self.dump_count.start() + + + @tasks.loop(seconds=5) + async def dump_count(self): + try: + cur = await aiosqlite.connect("./code/count/count.db") + count = await cur.execute("SELECT count FROM count") + count = await count.fetchone() + if count is None: + await cur.execute("INSERT INTO count (count) VALUES (?)", (self.bot.count_hold,)) + else: + await cur.execute("UPDATE count SET count = count + ?", (self.bot.count_hold,)) + await cur.commit() + await cur.close() + self.bot.count_hold = 0 + except sqlite3.OperationalError: + try: + await cur.commit() + await cur.close() + except: + pass + + + @commands.Cog.listener() + async def on_app_command_completion(self, interaction, command): + self.bot.count_hold += 1 + + +async def setup(bot): + await bot.add_cog(Count(bot)) \ No newline at end of file -- cgit v1.2.3-70-g09d2