diff --git a/bot/client.py b/bot/client.py index 7f9a958..ea439ed 100644 --- a/bot/client.py +++ b/bot/client.py @@ -15,7 +15,7 @@ def __init__(self): try: db.connect() except Exception as e: - print("Error while connecting to the database: ", e) + print("[ERROR] Error while connecting to the database: ", e) self.db = db self.logger = Logger(self) @@ -28,7 +28,7 @@ async def setup_hook(self): To perform asynchronous setup after the bot is logged in but before it has connected to the Websocket, overwrite this coroutine.\n This is only called once, in login(), and will be called before any events are dispatched, making it a better solution than doing such setup in the on_ready() event. """ - print("Setting up the bot...") + print("[INFO] Setting up the bot...") self.fetch_guilds_config() @@ -37,12 +37,12 @@ async def setup_hook(self): async def on_guild_join(self, guild: discord.Guild): self.db.insert(TableName.GUILDS.value, {"guild_id": guild.id}) self.fetch_guilds_config() - print(f"Bot has been added to {guild.name}") + print(f"[INFO] Bot has been added to {guild.name}") async def on_guild_remove(self, guild: discord.Guild): self.db.delete(TableName.GUILDS.value, {"guild_id": guild.id}) self.fetch_guilds_config() - print(f"Bot has been removed from {guild.name}") + print(f"[INFO] Bot has been removed from {guild.name}") def fetch_guilds_config(self): self.guilds_config = {} @@ -55,7 +55,7 @@ def fetch_guilds_config(self): TableName.CHANNELS.value, ["channel_id"], {"guild_id": guild} ) self.guilds_config[guild] = {"blacklisted_channel": blacklisted_channel} - print("Guilds config fetched") + print("[INFO] Guilds config fetched") async def on_ready(self): await self.wait_until_ready() diff --git a/bot/cogs/leaderboard.py b/bot/cogs/leaderboard.py index 34a7693..994e7ec 100644 --- a/bot/cogs/leaderboard.py +++ b/bot/cogs/leaderboard.py @@ -48,7 +48,7 @@ async def leaderboard_thanks(self, interaction: discord.Interaction): await interaction.response.send_message(embed=embed) except discord.errors.HTTPException as e: - print(e) + print(f"[ERROR] {e}") async def setup(bot): diff --git a/bot/cogs/stats.py b/bot/cogs/stats.py index 6c73b5b..e8fbd34 100644 --- a/bot/cogs/stats.py +++ b/bot/cogs/stats.py @@ -47,7 +47,7 @@ async def stats_thanks( await interaction.response.send_message(embed=embed, ephemeral=True) except discord.errors.HTTPException as e: - print(e) + print(f"[ERROR] {e}") async def setup(bot): diff --git a/bot/config/cogs_list.py b/bot/config/cogs_list.py index a0f4a01..092ade4 100644 --- a/bot/config/cogs_list.py +++ b/bot/config/cogs_list.py @@ -17,6 +17,6 @@ async def load_cogs(bot: discord.Client, cog_list: list): for cog in cog_list: try: await bot.load_extension(cog) - print(f"Cog loaded: {cog}") + print(f"[INFO] Cog loaded: {cog}") except Exception as e: - print(f"Error loading cog {cog}: {e}") + print(f"[ERROR] Error loading cog {cog}: {e}") diff --git a/bot/database.py b/bot/database.py index 1ebbdba..0179496 100644 --- a/bot/database.py +++ b/bot/database.py @@ -24,7 +24,7 @@ def __init__(self, retry_interval=5, keep_alive_interval=60): def connect(self): while True: try: - print("Connecting to the database...") + print("[INFO] Connecting to the database...") self.db = mysql.connector.connect( host=os.getenv("DB_HOST", "localhost"), port=int(os.getenv("DB_PORT", 3306)), @@ -34,11 +34,11 @@ def connect(self): ) self.cursor = self.db.cursor(dictionary=True) self.init_db() - print("Connected to the database.") + print("[INFO] Connected to the database.") break except mysql.connector.Error as err: - print(f"Error: {err}") - print(f"Retrying in {self.retry_interval} seconds...") + print(f"[ERROR] Error: {err}") + print(f"[ERROR] Retrying in {self.retry_interval} seconds...") time.sleep(self.retry_interval) def start_keep_alive(self): @@ -53,7 +53,7 @@ def keep_alive(): else: self.connect() except mysql.connector.Error as err: - print(f"Keep-alive error: {err}") + print(f"[ERROR] Keep-alive error: {err}") self.connect() time.sleep(self.keep_alive_interval) @@ -62,7 +62,7 @@ def keep_alive(): def reconnect_if_needed(self): """Reconnect if the database connection is not available.""" if not self.db.is_connected(): - print("Lost connection to the database. Reconnecting...") + print("[ERROR] Lost connection to the database. Reconnecting...") self.connect() def init_db(self): @@ -131,7 +131,7 @@ def insert(self, table: str, data: dict): self.reconnect_if_needed() keys = ", ".join(data.keys()) values = ", ".join(["%s"] * len(data)) - print(f"INSERT INTO `{table}` ({keys}) VALUES ({values})", tuple(data.values())) + print(f"[DEBUG] INSERT INTO `{table}` ({keys}) VALUES ({values})", tuple(data.values())) self.cursor.execute( f"INSERT INTO `{table}` ({keys}) VALUES ({values})", tuple(data.values()) ) @@ -169,7 +169,7 @@ def select( query += f" ORDER BY {order_by}" if limit: query += f" LIMIT {limit}" - print(query, tuple(where.values()) if where else None) + print("[DEBUG]", query, tuple(where.values()) if where else None) self.cursor.execute(query, tuple(where.values()) if where else None) return self.cursor.fetchall() @@ -189,7 +189,7 @@ def update(self, table: str, data: dict, where: dict): set_clause = ", ".join([f"{key} = %s" for key in data.keys()]) where_clause = self._and.join([f"{key} = %s" for key in where.keys()]) values = tuple(data.values()) + tuple(where.values()) - print(f"UPDATE `{table}` SET {set_clause} WHERE {where_clause}", values) + print(f"[DEBUG] UPDATE `{table}` SET {set_clause} WHERE {where_clause}", values) self.cursor.execute( f"UPDATE `{table}` SET {set_clause} WHERE {where_clause}", values ) @@ -208,7 +208,7 @@ def delete(self, table: str, where: dict): """ self.reconnect_if_needed() where_clause = self._and.join([f"{key} = %s" for key in where.keys()]) - print(f"DELETE FROM `{table}` WHERE {where_clause}", tuple(where.values())) + print(f"[DEBUG] DELETE FROM `{table}` WHERE {where_clause}", tuple(where.values())) self.cursor.execute( f"DELETE FROM `{table}` WHERE {where_clause}", tuple(where.values()) ) diff --git a/bot/events/points.py b/bot/events/points.py index ad9fad5..ec57547 100644 --- a/bot/events/points.py +++ b/bot/events/points.py @@ -106,7 +106,7 @@ async def give_role( await self.bot.logger.error( f"Guild: {guild_id}\nFailed to add role {role.name} to {member.name}: {e}" ) - print(f"Failed to add role {role.name} to {member.name}: {e}") + print(f"[ERROR] Failed to add role {role.name} to {member.name}: {e}") def create_user_points(self, guild_id: int, user_id: int, points: int = 0) -> None: """Create a new points record for a user.""" @@ -259,7 +259,7 @@ async def process_message(self, message: discord.Message) -> None: f"Processing message for points: {message.jump_url}```{message.content.replace('`', '`')}```" ) except Exception as e: - print(f"Error logging message: {e}") + print(f"[ERROR] Error logging message: {e}") mentioned_users = self.validator.get_mentioned_users(message) if not mentioned_users: diff --git a/bot/logger.py b/bot/logger.py index 1f11c19..6c55b8a 100644 --- a/bot/logger.py +++ b/bot/logger.py @@ -14,21 +14,21 @@ async def setup(self): self.channel = await self.bot.fetch_channel(channel_id) print( - f"Logger initialized with channel: {self.channel.name} ({self.channel.id})" + f"[INFO] Logger initialized with channel: {self.channel.name} ({self.channel.id})" ) async def info(self, message: str): - print(f"[INFO]: {message}") + print(f"[INFO]: {message[:10]}") await self.channel.send(f"[INFO] {message}") async def warning(self, message: str): - print(f"[WARNING]: {message}") + print(f"[WARNING]: {message[:10]}") await self.channel.send(f"[WARNING] {message}") async def error(self, message: str): - print(f"[ERROR]: {message}") + print(f"[ERROR]: {message[:10]}") await self.channel.send(f"[ERROR] {message}") async def debug(self, message: str): - print(f"[DEBUG]: {message}") + print(f"[DEBUG]: {message[:10]}") await self.channel.send(f"[DEBUG] {message}") diff --git a/main.py b/main.py index 4b6c88b..be2a7e3 100644 --- a/main.py +++ b/main.py @@ -11,20 +11,20 @@ # Load the appropriate .env file if environment == "dev": - print("Loading development env variable") + print("[INFO] Loading development env variable") load_dotenv(".env.local") else: - print("Loading production env variable") + print("[INFO] Loading production env variable") load_dotenv("stack.env") Thanks_Bot = Client() if __name__ == "__main__": if environment == "dev": - print("Dev mode launched running ...") + print("[INFO] Dev mode launched running ...") Thanks_Bot.run(os.getenv("TOKEN")) elif environment == "prod": - print("Prod mode launched running ...") + print("[INFO] Prod mode launched running ...") Thanks_Bot.run(os.getenv("TOKEN")) else: - print("Invalid environment") + print("[ERROR] Invalid environment")