[Modlog API] Stop modlog.get_case() from erroring if no modlog channel is set up (#5866)

Co-authored-by: Dav <dav@mail.stopdavabuse.de>
Co-authored-by: Flame442 <34169552+Flame442@users.noreply.github.com>
This commit is contained in:
Dav 2022-12-19 01:23:57 +01:00 committed by GitHub
parent 333e359bbb
commit 4dd496c67f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -689,7 +689,8 @@ class Case:
if message is None: if message is None:
message_id = data.get("message") message_id = data.get("message")
if message_id is not None: if message_id is not None:
message = mod_channel.get_partial_message(message_id) if mod_channel is not None:
message = mod_channel.get_partial_message(message_id)
user_objects = {"user": None, "moderator": None, "amended_by": None} user_objects = {"user": None, "moderator": None, "amended_by": None}
for user_key in tuple(user_objects): for user_key in tuple(user_objects):
@ -858,8 +859,11 @@ async def get_case(case_number: int, guild: discord.Guild, bot: Red) -> Case:
case = await _config.custom(_CASES, str(guild.id), str(case_number)).all() case = await _config.custom(_CASES, str(guild.id), str(case_number)).all()
if not case: if not case:
raise RuntimeError("That case does not exist for guild {}".format(guild.name)) raise RuntimeError("That case does not exist for guild {}".format(guild.name))
mod_channel = await get_modlog_channel(guild) try:
return await Case.from_json(mod_channel, bot, case_number, case) mod_channel = await get_modlog_channel(guild)
except RuntimeError:
mod_channel = None
return await Case.from_json(mod_channel, bot, case_number, case, guild=guild)
async def get_latest_case(guild: discord.Guild, bot: Red) -> Optional[Case]: async def get_latest_case(guild: discord.Guild, bot: Red) -> Optional[Case]:
@ -901,9 +905,12 @@ async def get_all_cases(guild: discord.Guild, bot: Red) -> List[Case]:
""" """
cases = await _config.custom(_CASES, str(guild.id)).all() cases = await _config.custom(_CASES, str(guild.id)).all()
mod_channel = await get_modlog_channel(guild) try:
mod_channel = await get_modlog_channel(guild)
except RuntimeError:
mod_channel = None
return [ return [
await Case.from_json(mod_channel, bot, case_number, case_data) await Case.from_json(mod_channel, bot, case_number, case_data, guild=guild)
for case_number, case_data in cases.items() for case_number, case_data in cases.items()
] ]