aboutsummaryrefslogtreecommitdiffstats
path: root/main.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--main.py43
1 files changed, 28 insertions, 15 deletions
diff --git a/main.py b/main.py
index e0de844..6c8c35b 100644
--- a/main.py
+++ b/main.py
@@ -7,6 +7,7 @@ import asyncio
7import logging 7import logging
8import os 8import os
9import sys 9import sys
10import argparse
10 11
11import discord 12import discord
12from discord.ext import commands 13from discord.ext import commands
@@ -14,13 +15,16 @@ from dotenv import load_dotenv
14 15
15from cogs.utils import settings 16from cogs.utils import settings
16 17
17# Configure logging 18
18logging.basicConfig( 19def setup_logging(debug: bool = False):
19 level=logging.INFO, 20 """Configure logging based on debug flag."""
20 format="%(levelname)s - %(filename)s - %(name)s - %(message)s", 21 level = logging.DEBUG if debug else logging.INFO
21 handlers=[logging.StreamHandler(sys.stdout)], 22 logging.basicConfig(
22) 23 level=level,
23logger = logging.getLogger(__name__) 24 format="%(levelname)s - %(filename)s - %(name)s - %(message)s",
25 handlers=[logging.StreamHandler(sys.stdout)],
26 )
27
24 28
25# Create a new event loop and set it as the current loop 29# Create a new event loop and set it as the current loop
26loop = asyncio.new_event_loop() 30loop = asyncio.new_event_loop()
@@ -32,17 +36,26 @@ bot = commands.Bot(intents=intents, loop=loop)
32 36
33@bot.event 37@bot.event
34async def on_ready(): 38async def on_ready():
39 logger = logging.getLogger(__name__)
35 logger.info("ŁUKASZ SPERMA AKTYWACJA") 40 logger.info("ŁUKASZ SPERMA AKTYWACJA")
36 41
37 channel = bot.get_channel(1081667823799111804) 42 channel_id = os.getenv("STATUS_CHANNEL_ID")
38 43 if channel_id:
39 await channel.send("ŁUKASZ SPERMA AKTYWACJA") 44 channel = bot.get_channel(int(channel_id))
45 if channel:
46 await channel.send("ŁUKASZ SPERMA AKTYWACJA")
40 47
41 await settings.load_settings() 48 await settings.load_settings()
42 49
43 50
44if __name__ == "__main__": 51if __name__ == "__main__":
52 parser = argparse.ArgumentParser(description="Run Senator Sperma bot")
53 parser.add_argument("--debug", action="store_true", help="Enable debug logging")
54 args, unknown = parser.parse_known_args()
55
45 load_dotenv() 56 load_dotenv()
57 setup_logging(args.debug)
58
46 extensions = [ 59 extensions = [
47 "cogs.vclogs", 60 "cogs.vclogs",
48 "cogs.compression", 61 "cogs.compression",
@@ -53,7 +66,7 @@ if __name__ == "__main__":
53 "cogs.math_commands", 66 "cogs.math_commands",
54 "cogs.downloader", 67 "cogs.downloader",
55 "cogs.say", 68 "cogs.say",
56 "cogs.jarvis", 69 "cogs.assistant",
57 "cogs.music.play_commands", 70 "cogs.music.play_commands",
58 "cogs.music.stop", 71 "cogs.music.stop",
59 "cogs.music.join", 72 "cogs.music.join",
@@ -62,14 +75,14 @@ if __name__ == "__main__":
62 "cogs.cron", 75 "cogs.cron",
63 "cogs.qr", 76 "cogs.qr",
64 "cogs.plot", 77 "cogs.plot",
78 "cogs.voice",
65 ] 79 ]
66 80
67 try: 81 try:
68 for i, extension in enumerate(extensions, 1): 82 for i, extension in enumerate(extensions, 1):
69 bot.load_extension(extension) 83 bot.load_extension(extension)
70 logger.info(f"Loaded {i}/{len(extensions)} extensions") 84 logging.getLogger(__name__).info(f"Loaded {i}/{len(extensions)} extensions")
71 85
72 # Run the bot with the token from environment variables
73 token = os.getenv("TOKEN") 86 token = os.getenv("TOKEN")
74 if not token: 87 if not token:
75 raise ValueError( 88 raise ValueError(
@@ -79,5 +92,5 @@ if __name__ == "__main__":
79 bot.run(token) 92 bot.run(token)
80 93
81 except Exception as e: 94 except Exception as e:
82 logger.error(f"Error starting the bot: {e}") 95 logging.getLogger(__name__).error(f"Error starting the bot: {e}")
83 sys.exit(1) 96 sys.exit(1) \ No newline at end of file