-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
74 lines (63 loc) · 2.21 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import discord
from discord.ext import commands
import logging
import asyncio
import sys
from config import TOKEN, LICENSE_CHANNEL_ID, check_config
# Setup logging
logging.basicConfig(
level=logging.DEBUG, # Changed to DEBUG level
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler('bot.log'),
logging.StreamHandler()
]
)
logger = logging.getLogger('bot')
class LicenseBot(commands.Bot):
def __init__(self):
intents = discord.Intents.default()
intents.message_content = True
super().__init__(command_prefix='/', intents=intents)
async def setup_hook(self):
logger.debug("Setting up bot hooks and commands...")
await self.load_extension('cogs.license_manager')
logger.debug("Syncing command tree...")
await self.tree.sync()
logger.debug("Command tree sync complete")
async def on_ready(self):
logging.info(f'Logged in as {self.user.name} ({self.user.id})')
# Removed channel purge functionality
bot = LicenseBot()
async def startup_checks():
try:
logger.debug("Starting configuration check...")
check_config()
logger.debug("Configuration validated successfully")
logger.debug("Testing storage connection...")
from json_storage import JsonStorage
storage = JsonStorage()
storage.test_connection()
logger.debug("Storage connection successful")
return True
except Exception as e:
logger.error(f"Startup check failed: {str(e)}", exc_info=True)
return False
async def main():
try:
if not await startup_checks():
logger.error("Startup checks failed. Exiting...")
sys.exit(1)
async with bot:
await bot.start(TOKEN)
except Exception as e:
logger.error(f"Fatal error: {str(e)}")
sys.exit(1)
if __name__ == '__main__':
try:
asyncio.run(main())
except KeyboardInterrupt:
logger.info("Bot shutdown by user")
except Exception as e:
logger.error(f"Unexpected error: {str(e)}")
sys.exit(1)