From a2b5b10625126b7e98643af9fe40569c9e004047 Mon Sep 17 00:00:00 2001 From: salmonik Date: Sat, 18 Apr 2026 00:24:50 +0200 Subject: refactor + preparing bot for public use Signed-off-by: salmonik --- main.py | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) (limited to 'main.py') diff --git a/main.py b/main.py index e0de844..6c8c35b 100644 --- a/main.py +++ b/main.py @@ -7,6 +7,7 @@ import asyncio import logging import os import sys +import argparse import discord from discord.ext import commands @@ -14,13 +15,16 @@ from dotenv import load_dotenv from cogs.utils import settings -# Configure logging -logging.basicConfig( - level=logging.INFO, - format="%(levelname)s - %(filename)s - %(name)s - %(message)s", - handlers=[logging.StreamHandler(sys.stdout)], -) -logger = logging.getLogger(__name__) + +def setup_logging(debug: bool = False): + """Configure logging based on debug flag.""" + level = logging.DEBUG if debug else logging.INFO + logging.basicConfig( + level=level, + format="%(levelname)s - %(filename)s - %(name)s - %(message)s", + handlers=[logging.StreamHandler(sys.stdout)], + ) + # Create a new event loop and set it as the current loop loop = asyncio.new_event_loop() @@ -32,17 +36,26 @@ bot = commands.Bot(intents=intents, loop=loop) @bot.event async def on_ready(): + logger = logging.getLogger(__name__) logger.info("ŁUKASZ SPERMA AKTYWACJA") - channel = bot.get_channel(1081667823799111804) - - await channel.send("ŁUKASZ SPERMA AKTYWACJA") + channel_id = os.getenv("STATUS_CHANNEL_ID") + if channel_id: + channel = bot.get_channel(int(channel_id)) + if channel: + await channel.send("ŁUKASZ SPERMA AKTYWACJA") await settings.load_settings() if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Run Senator Sperma bot") + parser.add_argument("--debug", action="store_true", help="Enable debug logging") + args, unknown = parser.parse_known_args() + load_dotenv() + setup_logging(args.debug) + extensions = [ "cogs.vclogs", "cogs.compression", @@ -53,7 +66,7 @@ if __name__ == "__main__": "cogs.math_commands", "cogs.downloader", "cogs.say", - "cogs.jarvis", + "cogs.assistant", "cogs.music.play_commands", "cogs.music.stop", "cogs.music.join", @@ -62,14 +75,14 @@ if __name__ == "__main__": "cogs.cron", "cogs.qr", "cogs.plot", + "cogs.voice", ] try: for i, extension in enumerate(extensions, 1): bot.load_extension(extension) - logger.info(f"Loaded {i}/{len(extensions)} extensions") + logging.getLogger(__name__).info(f"Loaded {i}/{len(extensions)} extensions") - # Run the bot with the token from environment variables token = os.getenv("TOKEN") if not token: raise ValueError( @@ -79,5 +92,5 @@ if __name__ == "__main__": bot.run(token) except Exception as e: - logger.error(f"Error starting the bot: {e}") - sys.exit(1) + logging.getLogger(__name__).error(f"Error starting the bot: {e}") + sys.exit(1) \ No newline at end of file -- cgit v1.2.3