aboutsummaryrefslogtreecommitdiff
path: root/code/cogs/count.py
diff options
context:
space:
mode:
Diffstat (limited to 'code/cogs/count.py')
-rw-r--r--code/cogs/count.py40
1 files changed, 40 insertions, 0 deletions
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