fix(moderation): added proper error handling to cog_load and db_generate_guild_join
Some checks failed
Pylint / Pylint (push) Failing after 1m19s
Some checks failed
Pylint / Pylint (push) Failing after 1m19s
This commit is contained in:
parent
3d2092ec3b
commit
9f6cc2968f
1 changed files with 19 additions and 1 deletions
|
@ -22,6 +22,15 @@ class Moderation(commands.Cog):
|
|||
|
||||
async def cog_load(self):
|
||||
"""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
|
||||
for guild in guilds:
|
||||
await self.create_guild_table(guild)
|
||||
|
@ -29,6 +38,15 @@ class Moderation(commands.Cog):
|
|||
@commands.Cog.listener('on_guild_join')
|
||||
async def db_generate_guild_join(self, guild: discord.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)
|
||||
|
||||
async def connect(self):
|
||||
|
@ -40,7 +58,7 @@ class Moderation(commands.Cog):
|
|||
'mysql_password'
|
||||
])
|
||||
if conf:
|
||||
raise LookupError
|
||||
raise LookupError("MySQL connection details not set properly!")
|
||||
try:
|
||||
connection = mysql.connector.connect(
|
||||
host=await self.config.mysql_address(),
|
||||
|
|
Loading…
Reference in a new issue