Skip to content

Commit

Permalink
modified: cogs/afk.py
Browse files Browse the repository at this point in the history
	modified:   cogs/remind.py
  • Loading branch information
Revulate committed Oct 16, 2024
1 parent d37ae8b commit f175503
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
17 changes: 12 additions & 5 deletions cogs/afk.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ def __init__(self, bot):
self.db_path = "bot.db"
self.last_afk_message_time = {}

async def event_ready(self):
await self.setup_database()

async def setup_database(self):
async with aiosqlite.connect(self.db_path) as db:
await db.execute(
Expand All @@ -22,10 +25,14 @@ async def setup_database(self):
return_time REAL,
active INTEGER NOT NULL DEFAULT 1
)
"""
"""
)
await db.commit()

async def close_database(self):
# Placeholder for closing any persistent connections if needed.
pass

@commands.command(name="afk", aliases=["sleep", "gn", "work", "food", "gaming", "bed"])
async def afk_command(self, ctx: commands.Context, *, reason: str = None):
user_id = ctx.author.id
Expand All @@ -48,7 +55,7 @@ async def afk_command(self, ctx: commands.Context, *, reason: str = None):
"""
INSERT OR REPLACE INTO afk (user_id, username, afk_time, reason, return_time, active)
VALUES (?, ?, ?, ?, NULL, 1)
""",
""",
(user_id, username, afk_time, full_reason),
)
await conn.commit()
Expand Down Expand Up @@ -76,7 +83,7 @@ async def rafk_command(self, ctx: commands.Context):
UPDATE afk
SET active = 1, return_time = NULL
WHERE user_id = ?
""",
""",
(user_id,),
)
await conn.commit()
Expand Down Expand Up @@ -120,7 +127,7 @@ async def _handle_afk_return(self, message, user_id, username):
UPDATE afk
SET active = 0, return_time = ?
WHERE user_id = ?
""",
""",
(time.time(), user_id),
)
await conn.commit()
Expand Down Expand Up @@ -165,4 +172,4 @@ def format_duration_string(self, duration):


def prepare(bot):
bot.add_cog(Afk(bot))
bot.add_cog(Afk(bot))
10 changes: 7 additions & 3 deletions cogs/remind.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,14 @@ async def setup_database(self):
active INTEGER NOT NULL DEFAULT 1,
created_at TEXT NOT NULL
)
"""
"""
)
await db.commit()

async def close_database(self):
# Placeholder for closing any persistent connections if needed.
pass

@commands.Cog.event()
async def event_ready(self):
await self.setup_database()
Expand Down Expand Up @@ -162,7 +166,7 @@ async def save_reminder(self, reminder: Reminder):
INSERT INTO reminders (id, user_id, username, target_id, target_name, channel_id, channel_name,
message, remind_time, private, trigger_on_message, active, created_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""",
""",
(
reminder.id,
reminder.user.id,
Expand Down Expand Up @@ -218,4 +222,4 @@ def row_to_reminder(self, row):


def prepare(bot):
bot.add_cog(Remind(bot))
bot.add_cog(Remind(bot))

0 comments on commit f175503

Please sign in to comment.