[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,6 +689,7 @@ class Case:
if message is None:
message_id = data.get("message")
if message_id is not None:
if mod_channel is not None:
message = mod_channel.get_partial_message(message_id)
user_objects = {"user": None, "moderator": None, "amended_by": None}
@ -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()
if not case:
raise RuntimeError("That case does not exist for guild {}".format(guild.name))
try:
mod_channel = await get_modlog_channel(guild)
return await Case.from_json(mod_channel, bot, case_number, case)
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]:
@ -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()
try:
mod_channel = await get_modlog_channel(guild)
except RuntimeError:
mod_channel = None
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()
]