From acc3e6f15942f39d402764ffd308cd2b21476150 Mon Sep 17 00:00:00 2001 From: Izan Date: Wed, 6 Oct 2021 14:32:45 +0100 Subject: Attempt infraction before DMing Prevents users getting sent an infraction message when the infraction then fails. This time it won't DM for notes :p --- bot/exts/moderation/infraction/_scheduler.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/bot/exts/moderation/infraction/_scheduler.py b/bot/exts/moderation/infraction/_scheduler.py index ddd4c6366..73403f10b 100644 --- a/bot/exts/moderation/infraction/_scheduler.py +++ b/bot/exts/moderation/infraction/_scheduler.py @@ -149,8 +149,8 @@ class InfractionScheduler: else: expiry_msg = f" until {expiry}" if expiry else " permanently" - dm_result = constants.Emojis.failmail - dm_log_text = "\nDM: **Failed**" + dm_result = "" + dm_log_text = "" expiry_log_text = f"\nExpires: {expiry}" if expiry else "" log_title = "applied" log_content = None @@ -166,6 +166,9 @@ class InfractionScheduler: if await _utils.notify_infraction(user, infr_type.replace("_", " ").title(), expiry, user_reason, icon): dm_result = ":incoming_envelope: " dm_log_text = "\nDM: Sent" + else: + dm_result = f"{constants.Emojis.failmail} " + dm_log_text = "\nDM: **Failed**" end_msg = "" if infraction["actor"] == self.bot.user.id: @@ -225,11 +228,16 @@ class InfractionScheduler: else: log.info(f"Applied {purge}{infr_type} infraction #{id_} to {user}.") infr_message = f" **{purge}{' '.join(infr_type.split('_'))}** to {user.mention}{expiry_msg}{end_msg}" - if infr_type not in ("ban", "kick"): # If we haven't already tried to send the DM + + # If we need to DM and haven't already tried to + if not infraction["hidden"] and infr_type not in ("ban", "kick"): # Accordingly display whether the user was successfully notified via DM. if await _utils.notify_infraction(user, infr_type.replace("_", " ").title(), expiry, user_reason, icon): dm_result = ":incoming_envelope: " dm_log_text = "\nDM: Sent" + else: + dm_result = f"{constants.Emojis.failmail} " + dm_log_text = "\nDM: **Failed**" # Send a confirmation message to the invoking context. log.trace(f"Sending infraction #{id_} confirmation message.") -- cgit v1.2.3 From 1df1527401169479a2e72d1a3b1838907954a73c Mon Sep 17 00:00:00 2001 From: Izan Date: Sun, 10 Oct 2021 11:02:46 +0100 Subject: Remove redundant `else` clauses --- bot/exts/moderation/infraction/_scheduler.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/bot/exts/moderation/infraction/_scheduler.py b/bot/exts/moderation/infraction/_scheduler.py index 6f1af86d3..f6fa5a3c3 100644 --- a/bot/exts/moderation/infraction/_scheduler.py +++ b/bot/exts/moderation/infraction/_scheduler.py @@ -165,13 +165,10 @@ class InfractionScheduler: dm_result = f"{constants.Emojis.failmail} " dm_log_text = "\nDM: **Failed**" - # Accordingly display whether the user was successfully notified via DM. + # Accordingly update whether the user was successfully notified via DM. if await _utils.notify_infraction(user, infr_type.replace("_", " ").title(), expiry, user_reason, icon): dm_result = ":incoming_envelope: " dm_log_text = "\nDM: Sent" - else: - dm_result = f"{constants.Emojis.failmail} " - dm_log_text = "\nDM: **Failed**" end_msg = "" if infraction["actor"] == self.bot.user.id: @@ -233,13 +230,13 @@ class InfractionScheduler: # If we need to DM and haven't already tried to if not infraction["hidden"] and infr_type not in ("ban", "kick"): - # Accordingly display whether the user was successfully notified via DM. + dm_result = f"{constants.Emojis.failmail} " + dm_log_text = "\nDM: **Failed**" + + # Accordingly update whether the user was successfully notified via DM. if await _utils.notify_infraction(user, infr_type.replace("_", " ").title(), expiry, user_reason, icon): dm_result = ":incoming_envelope: " dm_log_text = "\nDM: Sent" - else: - dm_result = f"{constants.Emojis.failmail} " - dm_log_text = "\nDM: **Failed**" # Send a confirmation message to the invoking context. log.trace(f"Sending infraction #{id_} confirmation message.") -- cgit v1.2.3 From 371869ad39628df306270ba16a76e96c6ccd3dad Mon Sep 17 00:00:00 2001 From: TizzySaurus <47674925+TizzySaurus@users.noreply.github.com> Date: Mon, 11 Oct 2021 11:50:31 +0100 Subject: Only send DM before applying infraction for ban/kick --- bot/exts/moderation/infraction/_scheduler.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/exts/moderation/infraction/_scheduler.py b/bot/exts/moderation/infraction/_scheduler.py index f6fa5a3c3..1bdfbb943 100644 --- a/bot/exts/moderation/infraction/_scheduler.py +++ b/bot/exts/moderation/infraction/_scheduler.py @@ -161,7 +161,7 @@ class InfractionScheduler: # send DMs to user that it doesn't share a guild with. If we were to # apply kick/ban infractions first, this would mean that we'd make it # impossible for us to deliver a DM. See python-discord/bot#982. - if not infraction["hidden"]: + if not infraction["hidden"] and infr_type in {"ban", "kick"}: dm_result = f"{constants.Emojis.failmail} " dm_log_text = "\nDM: **Failed**" @@ -229,7 +229,7 @@ class InfractionScheduler: infr_message = f" **{purge}{' '.join(infr_type.split('_'))}** to {user.mention}{expiry_msg}{end_msg}" # If we need to DM and haven't already tried to - if not infraction["hidden"] and infr_type not in ("ban", "kick"): + if not infraction["hidden"] and infr_type not in {"ban", "kick"}: dm_result = f"{constants.Emojis.failmail} " dm_log_text = "\nDM: **Failed**" -- cgit v1.2.3