Skip to content

Commit

Permalink
modified: .github/workflows/ci.yml
Browse files Browse the repository at this point in the history
	modified:   bot.py
	modified:   cogs/remind.py
  • Loading branch information
Revulate committed Oct 16, 2024
1 parent 3dddb66 commit c6823e5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 25 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ jobs:
}
EOF
# Set up the database to ensure all tables exist
python -c 'from utils import setup_database; setup_database()'
# Run database migrations if any
if [ -f "migrate.py" ]; then
python migrate.py
Expand Down
5 changes: 3 additions & 2 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ def __init__(self):
nick = os.getenv("BOT_NICK")
prefix = os.getenv("COMMAND_PREFIX", "#")
channels = os.getenv("TWITCH_CHANNELS", "").split(",")
channels = [channel.strip() for channel in channels] # To remove leading/trailing whitespace

# Check for missing critical environment variables
self._check_env_variables()

# Set initial_channels as an instance variable
self.initial_channels = [channel.strip() for channel in channels if isinstance(channel.strip(), str)]
self.initial_channels = [channel for channel in channels if isinstance(channel, str)]

super().__init__(
token=self.token,
Expand Down Expand Up @@ -271,4 +272,4 @@ async def main():


if __name__ == "__main__":
asyncio.run(main())
asyncio.run(main())
26 changes: 3 additions & 23 deletions cogs/remind.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from datetime import datetime, timezone, timedelta
import aiosqlite
from twitchio.ext import commands
from utils import parse_time, format_time_delta, normalize_username, fetch_user, get_channel
from utils import parse_time, format_time_delta, normalize_username, fetch_user, get_channel, setup_database


class Reminder:
Expand Down Expand Up @@ -41,27 +41,7 @@ def __init__(self, bot):
self.check_timed_reminders_task = None

async def setup_database(self):
async with aiosqlite.connect(self.db_path) as db:
await db.execute(
"""
CREATE TABLE IF NOT EXISTS reminders (
id TEXT PRIMARY KEY,
user_id INTEGER NOT NULL,
username TEXT NOT NULL,
target_id INTEGER NOT NULL,
target_name TEXT NOT NULL,
channel_id INTEGER NOT NULL,
channel_name TEXT NOT NULL,
message TEXT NOT NULL,
remind_time TEXT,
private INTEGER NOT NULL,
trigger_on_message INTEGER NOT NULL,
active INTEGER NOT NULL DEFAULT 1,
created_at TEXT NOT NULL
)
"""
)
await db.commit()
await setup_database(self.db_path)

async def close_database(self):
# Placeholder for closing any persistent connections if needed.
Expand Down Expand Up @@ -222,4 +202,4 @@ def row_to_reminder(self, row):


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

0 comments on commit c6823e5

Please sign in to comment.