This repository has been archived on 2025-01-25. You can view files and clone it, but cannot push or open issues or pull requests.
aquabot/code/cogs/count.py
2025-01-25 22:58:41 -06:00

40 lines
1.1 KiB
Python

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))