aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar ks129 <[email protected]>2020-11-07 09:57:23 +0200
committerGravatar ks129 <[email protected]>2020-11-07 09:57:23 +0200
commit6a81f714c6648d7dd12982b38c7161cdee9e602e (patch)
treea346bfffcbd6402d00befd6e0c219fc860fdcbdc
parentUse result instead exception for watchchannel closing task (diff)
Catch not found exception in scheduler
-rw-r--r--bot/exts/moderation/infraction/_scheduler.py29
-rw-r--r--bot/exts/moderation/infraction/infractions.py16
2 files changed, 30 insertions, 15 deletions
diff --git a/bot/exts/moderation/infraction/_scheduler.py b/bot/exts/moderation/infraction/_scheduler.py
index ed67e3b26..6efa5b1e0 100644
--- a/bot/exts/moderation/infraction/_scheduler.py
+++ b/bot/exts/moderation/infraction/_scheduler.py
@@ -79,6 +79,16 @@ class InfractionScheduler:
except discord.NotFound:
# When user joined and then right after this left again before action completed, this can't add roles
log.info(f"Can't reapply {infraction['type']} to user {infraction['user']} because user left again.")
+ except discord.HTTPException as e:
+ if e.code == 10007:
+ log.info(f"Can't reapply {infraction['type']} to user {infraction['user']} because user left again.")
+ else:
+ log.warning(
+ (
+ f"Got unexpected HTTPException (HTTP {e.status}, Discord code {e.code})"
+ f"when awaiting {infraction['type']} coroutine for {infraction['user']}."
+ )
+ )
else:
log.info(f"Re-applied {infraction['type']} to user {infraction['user']} upon rejoining.")
@@ -160,6 +170,8 @@ class InfractionScheduler:
if expiry:
# Schedule the expiration of the infraction.
self.schedule_expiration(infraction)
+ except discord.NotFound:
+ log.info(f"Can't apply {infraction['type']} to user {infraction['user']} because user left from guild.")
except discord.HTTPException as e:
# Accordingly display that applying the infraction failed.
# Don't use ctx.message.author; antispam only patches ctx.author.
@@ -171,6 +183,10 @@ class InfractionScheduler:
log_msg = f"Failed to apply {' '.join(infr_type.split('_'))} infraction #{id_} to {user}"
if isinstance(e, discord.Forbidden):
log.warning(f"{log_msg}: bot lacks permissions.")
+ elif e.code == 10007:
+ log.info(
+ f"Can't apply {infraction['type']} to user {infraction['user']} because user left from guild."
+ )
else:
log.exception(log_msg)
failed = True
@@ -342,10 +358,17 @@ class InfractionScheduler:
log.warning(f"Failed to deactivate infraction #{id_} ({type_}): bot lacks permissions.")
log_text["Failure"] = "The bot lacks permissions to do this (role hierarchy?)"
log_content = mod_role.mention
+ except discord.NotFound:
+ log.info(f"Can't pardon {infraction['type']} for user {infraction['user']} because user left from guild.")
except discord.HTTPException as e:
- log.exception(f"Failed to deactivate infraction #{id_} ({type_})")
- log_text["Failure"] = f"HTTPException with status {e.status} and code {e.code}."
- log_content = mod_role.mention
+ if e.code == 10007:
+ log.info(
+ f"Can't pardon {infraction['type']} for user {infraction['user']} because user left from guild."
+ )
+ else:
+ log.exception(f"Failed to deactivate infraction #{id_} ({type_})")
+ log_text["Failure"] = f"HTTPException with status {e.status} and code {e.code}."
+ log_content = mod_role.mention
# Check if the user is currently being watched by Big Brother.
try:
diff --git a/bot/exts/moderation/infraction/infractions.py b/bot/exts/moderation/infraction/infractions.py
index 8abb199db..746d4e154 100644
--- a/bot/exts/moderation/infraction/infractions.py
+++ b/bot/exts/moderation/infraction/infractions.py
@@ -277,18 +277,10 @@ class Infractions(InfractionScheduler, commands.Cog):
self.mod_log.ignore(Event.member_update, user.id)
async def action() -> None:
- try:
- await user.add_roles(self._muted_role, reason=reason)
- except discord.HTTPException as e:
- if e.code == 10007:
- log.info(f"User {user} ({user.id}) left from guild. Can't give Muted role.")
- else:
- log.warning(
- f"Got response {e.code} (HTTP {e.status}) while giving muted role to {user} ({user.id})."
- )
- else:
- log.trace(f"Attempting to kick {user} from voice because they've been muted.")
- await user.move_to(None, reason=reason)
+ await user.add_roles(self._muted_role, reason=reason)
+
+ log.trace(f"Attempting to kick {user} from voice because they've been muted.")
+ await user.move_to(None, reason=reason)
await self.apply_infraction(ctx, infraction, user, action())