Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions bot/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()

Expand All @@ -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 = {}
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion bot/cogs/leaderboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion bot/cogs/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions bot/config/cogs_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
20 changes: 10 additions & 10 deletions bot/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand All @@ -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):
Expand All @@ -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)

Expand All @@ -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):
Expand Down Expand Up @@ -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())
)
Expand Down Expand Up @@ -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()

Expand All @@ -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
)
Expand All @@ -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())
)
Expand Down
4 changes: 2 additions & 2 deletions bot/events/points.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions bot/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
10 changes: 5 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")