diff options
author | 2021-10-05 23:43:14 +0200 | |
---|---|---|
committer | 2021-10-05 23:43:14 +0200 | |
commit | 5127a88a1f904f1b238d3a9e3de50fafd8d81f5c (patch) | |
tree | a1995bac234e7b583256cc4e01ea5ce86578d07e | |
parent | Merge pull request #1854 from python-discord/minor-changes-to-typing-patch (diff) | |
parent | Merge branch 'main' into infract-then-dm (diff) |
Merge pull request #1806 from python-discord/infract-then-dm
Apply infractions before DMing
-rw-r--r-- | bot/exts/moderation/infraction/_scheduler.py | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/bot/exts/moderation/infraction/_scheduler.py b/bot/exts/moderation/infraction/_scheduler.py index 8e844822d..ddd4c6366 100644 --- a/bot/exts/moderation/infraction/_scheduler.py +++ b/bot/exts/moderation/infraction/_scheduler.py @@ -149,22 +149,19 @@ class InfractionScheduler: else: expiry_msg = f" until {expiry}" if expiry else " permanently" - dm_result = "" - dm_log_text = "" + dm_result = constants.Emojis.failmail + dm_log_text = "\nDM: **Failed**" expiry_log_text = f"\nExpires: {expiry}" if expiry else "" log_title = "applied" log_content = None failed = False - # DM the user about the infraction if it's not a shadow/hidden infraction. + # DM the user about the infraction if it's a ban/kick and not a shadow/hidden infraction. # This needs to happen before we apply the infraction, as the bot cannot # 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"]: - dm_result = f"{constants.Emojis.failmail} " - dm_log_text = "\nDM: **Failed**" - + if not infraction["hidden"] and infr_type 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: " @@ -226,7 +223,13 @@ class InfractionScheduler: log.error(f"Deletion of {infr_type} infraction #{id_} failed with error code {e.status}.") infr_message = "" 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 + # 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" # Send a confirmation message to the invoking context. log.trace(f"Sending infraction #{id_} confirmation message.") @@ -250,7 +253,6 @@ class InfractionScheduler: footer=f"ID {infraction['id']}" ) - log.info(f"Applied {purge}{infr_type} infraction #{id_} to {user}.") return not failed async def pardon_infraction( |