diff options
| author | 2021-10-05 22:57:13 +0100 | |
|---|---|---|
| committer | 2021-10-05 22:57:13 +0100 | |
| commit | dcd1b457dfa9e2651617fe72f1e50e7b6f8f21ef (patch) | |
| tree | 39868b2a6e05d82cf6385fa42c80599e7fb38031 | |
| parent | Merge branch 'main' into ignore-infra-mods-errors (diff) | |
| parent | Merge pull request #1806 from python-discord/infract-then-dm (diff) | |
Merge branch 'main' into ignore-infra-mods-errors
| -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( | 
