fix(moderation): added proper error handling to cog_load and db_generate_guild_join
Some checks failed
Pylint / Pylint (push) Failing after 1m19s

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

View file

@ -22,6 +22,15 @@ class Moderation(commands.Cog):
async def cog_load(self): async def cog_load(self):
"""This method prepares the database schema for all of the guilds the bot is currently in.""" """This method prepares the database schema for all of the guilds the bot is currently in."""
conf = await self.check_conf([
'mysql_address',
'mysql_database',
'mysql_user',
'mysql_password'
])
if conf:
logging.fatal("Failed to create tables, due to MySQL connection configuration being unset.")
return
guilds: list[discord.Guild] = self.bot.guilds guilds: list[discord.Guild] = self.bot.guilds
for guild in guilds: for guild in guilds:
await self.create_guild_table(guild) await self.create_guild_table(guild)
@ -29,6 +38,15 @@ class Moderation(commands.Cog):
@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):
"""This method prepares the database schema whenever the bot joins a guild.""" """This method prepares the database schema whenever the bot joins a guild."""
conf = await self.check_conf([
'mysql_address',
'mysql_database',
'mysql_user',
'mysql_password'
])
if conf:
logging.fatal("Failed to create a table for %s, due to MySQL connection configuration being unset.", guild.id)
return
await self.create_guild_table(guild) await self.create_guild_table(guild)
async def connect(self): async def connect(self):
@ -40,7 +58,7 @@ class Moderation(commands.Cog):
'mysql_password' 'mysql_password'
]) ])
if conf: if conf:
raise LookupError raise LookupError("MySQL connection details not set properly!")
try: try:
connection = mysql.connector.connect( connection = mysql.connector.connect(
host=await self.config.mysql_address(), host=await self.config.mysql_address(),