|
7 | 7 | import discord |
8 | 8 | from discord.ext import commands as dcmd |
9 | 9 | from dotenv import load_dotenv |
| 10 | +import lavalink |
10 | 11 |
|
11 | 12 | import teapot |
| 13 | +from teapot.event_handler.loader import EventHandlerLoader |
12 | 14 |
|
13 | 15 | print(f""" |
14 | 16 | _____ _ |
|
70 | 72 | db.execute( |
71 | 73 | 'CREATE TABLE IF NOT EXISTS `channels` (`channel_id` BIGINT, `channel_name` TINYTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci') |
72 | 74 | db.execute( |
73 | | - "CREATE TABLE IF NOT EXISTS `users` (`user_id` BIGINT, `user_name` TINYTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci, `user_discriminator` INT) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci") |
| 75 | + "CREATE TABLE IF NOT EXISTS `users` (`user_id` BIGINT, `user_name` TINYTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci, `user_display_name` TINYTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci") |
74 | 76 | db.execute( |
75 | 77 | "CREATE TABLE IF NOT EXISTS `bot_logs` (`timestamp` TEXT, `type` TINYTEXT, `class` TINYTEXT, `message` MEDIUMTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci") |
76 | 78 | teapot.managers.database.create_table( |
|
83 | 85 | print( |
84 | 86 | f"Connected to database ({teapot.config.db_host()}:{teapot.config.db_port()}) in {round(time.perf_counter() - time_start, 2)}s") |
85 | 87 |
|
86 | | -intents = discord.Intents.default() |
| 88 | + |
| 89 | +intents = discord.Intents.all() |
87 | 90 | intents.members = True |
| 91 | +intents.message_content = True |
88 | 92 | intents.typing = False |
89 | 93 | bot = dcmd.Bot(intents=intents, command_prefix=teapot.config.bot_prefix(), help_command=None) |
90 | 94 |
|
| 95 | +event_handler_loader = EventHandlerLoader(bot) # Event Handler |
| 96 | + |
| 97 | + |
91 | 98 | @bot.event |
92 | 99 | async def on_ready(): |
93 | 100 | print(f"Connected to Discord API in {round(time.perf_counter() - discord_time_start, 2)}s") |
94 | 101 | time_start = time.perf_counter() |
| 102 | + |
95 | 103 | # load cogs |
96 | 104 | teapot.events.__init__(bot) |
97 | | - teapot.cogs.cmds.__init__(bot) |
98 | | - teapot.cogs.music.setup(bot) |
99 | | - teapot.cogs.osu.setup(bot) |
100 | | - teapot.cogs.github.setup(bot) |
101 | | - teapot.cogs.cat.setup(bot) |
102 | | - teapot.cogs.neko.setup(bot) |
103 | | - teapot.cogs.nqn.setup(bot) |
| 105 | + # Initialize lavalink client once here so cogs do not need to recreate it |
| 106 | + if not hasattr(bot, 'lavalink'): |
| 107 | + print("Initializing Lavalink client...") |
| 108 | + bot.lavalink = lavalink.Client(bot.user.id) |
| 109 | + bot.lavalink.add_node(teapot.config.lavalink_host(), teapot.config.lavalink_port(), teapot.config.lavalink_password(), 'zz', 'default') |
| 110 | + bot.add_listener(bot.lavalink.voice_update_handler, 'on_socket_response') |
| 111 | + extensions = [ |
| 112 | + 'teapot.cogs.cmds', |
| 113 | + 'teapot.cogs.osu', |
| 114 | + 'teapot.cogs.github', |
| 115 | + 'teapot.cogs.cat', |
| 116 | + 'teapot.cogs.neko', |
| 117 | + 'teapot.cogs.nqn', |
| 118 | + 'teapot.cogs.music' # TODO: WIP |
| 119 | + ] |
| 120 | + |
| 121 | + for extension in extensions: |
| 122 | + try: |
| 123 | + await bot.load_extension(extension) |
| 124 | + print(f"✓ Successfully loaded module: {extension}") |
| 125 | + except Exception as e: |
| 126 | + print(f"✗ Failed to load {extension}: {e}") |
| 127 | + import traceback |
| 128 | + traceback.print_exc() |
104 | 129 | if teapot.config.storage_type() == "mysql": |
105 | 130 | for guild in bot.guilds: |
106 | 131 | teapot.managers.database.create_guild_table(guild) |
107 | 132 | elif teapot.config.storage_type() == "sqlite": |
108 | 133 | print("[!] Warning: SQLite storage has not been implemented yet. MySQL is recommended") # WIP |
| 134 | + |
109 | 135 | print(f"Registered commands and events in {round(time.perf_counter() - time_start, 2)}s") |
| 136 | + print(f"total of commands loaded: {len(bot.commands)}") |
| 137 | + print(f"Modules loaded: {list(bot.cogs.keys())}") |
| 138 | + |
110 | 139 | await bot.change_presence(status=discord.Status.online, |
111 | 140 | activity=discord.Game(teapot.config.bot_status())) # Update Bot status |
112 | 141 |
|
|
0 commit comments