fix(moderation): fixed the connect method
Some checks failed
Pylint / Pylint (push) Failing after 1m14s

This commit is contained in:
Seaswimmer 2023-10-04 09:42:22 -04:00
parent 9f6cc2968f
commit dbb02c0892
No known key found for this signature in database
GPG key ID: 5019678FD9CF50D8

View file

@ -32,8 +32,11 @@ class Moderation(commands.Cog):
logging.fatal("Failed to create tables, due to MySQL connection configuration being unset.") logging.fatal("Failed to create tables, due to MySQL connection configuration being unset.")
return return
guilds: list[discord.Guild] = self.bot.guilds guilds: list[discord.Guild] = self.bot.guilds
for guild in guilds: try:
await self.create_guild_table(guild) for guild in guilds:
await self.create_guild_table(guild)
except ConnectionRefusedError:
return
@commands.Cog.listener('on_guild_join') @commands.Cog.listener('on_guild_join')
async def db_generate_guild_join(self, guild: discord.Guild): async def db_generate_guild_join(self, guild: discord.Guild):
@ -47,7 +50,10 @@ class Moderation(commands.Cog):
if conf: if conf:
logging.fatal("Failed to create a table for %s, due to MySQL connection configuration being unset.", guild.id) logging.fatal("Failed to create a table for %s, due to MySQL connection configuration being unset.", guild.id)
return return
await self.create_guild_table(guild) try:
await self.create_guild_table(guild)
except ConnectionRefusedError:
return
async def connect(self): async def connect(self):
"""Connects to the MySQL database, and returns a connection object.""" """Connects to the MySQL database, and returns a connection object."""
@ -64,7 +70,7 @@ class Moderation(commands.Cog):
host=await self.config.mysql_address(), host=await self.config.mysql_address(),
user=await self.config.mysql_user(), user=await self.config.mysql_user(),
password=await self.config.mysql_password(), password=await self.config.mysql_password(),
database=await self.config.mysql_db() database=await self.config.mysql_database()
) )
return connection return connection
except mysql.connector.ProgrammingError as e: except mysql.connector.ProgrammingError as e: