diff options
| author | 2018-12-30 14:10:15 +0100 | |
|---|---|---|
| committer | 2018-12-30 14:10:15 +0100 | |
| commit | c74c6a44c288a25b3f1dba3053097a0468835830 (patch) | |
| tree | 6081eb3d5203b83fd3256be97427ca00af6f7313 | |
| parent | Merge pull request #233 from python-discord/warn-modlog (diff) | |
| parent | Merge branch 'master' into mod-dm-status (diff) | |
Merge pull request #223 from python-discord/mod-dm-status
Show when an infraction notified a user successfully via DM.
Diffstat (limited to '')
| -rw-r--r-- | bot/cogs/moderation.py | 107 | ||||
| -rw-r--r-- | bot/cogs/modlog.py | 12 | 
2 files changed, 80 insertions, 39 deletions
diff --git a/bot/cogs/moderation.py b/bot/cogs/moderation.py index 8add6fdde..ac08d3dd4 100644 --- a/bot/cogs/moderation.py +++ b/bot/cogs/moderation.py @@ -82,7 +82,7 @@ class Moderation(Scheduler):          :param reason: The reason for the warning.          """ -        await self.notify_infraction( +        notified = await self.notify_infraction(              user=user,              infr_type="Warning",              reason=reason @@ -92,12 +92,16 @@ class Moderation(Scheduler):          if response_object is None:              return +        dm_result = ":incoming_envelope: " if notified else "" +        action = f"{dm_result}:ok_hand: warned {user.mention}" +          if reason is None: -            result_message = f":ok_hand: warned {user.mention}." +            await ctx.send(f"{action}.")          else: -            result_message = f":ok_hand: warned {user.mention} ({reason})." +            await ctx.send(f"{action} ({reason}).") -        await ctx.send(result_message) +        if not notified: +            await self.log_notify_failure(user, ctx.author, "warning")          # Send a message to the mod log          await self.mod_log.send_log_message( @@ -121,7 +125,7 @@ class Moderation(Scheduler):          :param reason: The reason for the kick.          """ -        await self.notify_infraction( +        notified = await self.notify_infraction(              user=user,              infr_type="Kick",              reason=reason @@ -134,12 +138,16 @@ class Moderation(Scheduler):          self.mod_log.ignore(Event.member_remove, user.id)          await user.kick(reason=reason) +        dm_result = ":incoming_envelope: " if notified else "" +        action = f"{dm_result}:ok_hand: kicked {user.mention}" +          if reason is None: -            result_message = f":ok_hand: kicked {user.mention}." +            await ctx.send(f"{action}.")          else: -            result_message = f":ok_hand: kicked {user.mention} ({reason})." +            await ctx.send(f"{action} ({reason}).") -        await ctx.send(result_message) +        if not notified: +            await self.log_notify_failure(user, ctx.author, "kick")          # Send a log message to the mod log          await self.mod_log.send_log_message( @@ -163,7 +171,7 @@ class Moderation(Scheduler):          :param reason: The reason for the ban.          """ -        await self.notify_infraction( +        notified = await self.notify_infraction(              user=user,              infr_type="Ban",              duration="Permanent", @@ -178,12 +186,16 @@ class Moderation(Scheduler):          self.mod_log.ignore(Event.member_remove, user.id)          await ctx.guild.ban(user, reason=reason, delete_message_days=0) +        dm_result = ":incoming_envelope: " if notified else "" +        action = f"{dm_result}:ok_hand: permanently banned {user.mention}" +          if reason is None: -            result_message = f":ok_hand: permanently banned {user.mention}." +            await ctx.send(f"{action}.")          else: -            result_message = f":ok_hand: permanently banned {user.mention} ({reason})." +            await ctx.send(f"{action} ({reason}).") -        await ctx.send(result_message) +        if not notified: +            await self.log_notify_failure(user, ctx.author, "ban")          # Send a log message to the mod log          await self.mod_log.send_log_message( @@ -207,7 +219,7 @@ class Moderation(Scheduler):          :param reason: The reason for the mute.          """ -        await self.notify_infraction( +        notified = await self.notify_infraction(              user=user,              infr_type="Mute",              duration="Permanent", @@ -222,12 +234,16 @@ class Moderation(Scheduler):          self.mod_log.ignore(Event.member_update, user.id)          await user.add_roles(self._muted_role, reason=reason) +        dm_result = ":incoming_envelope: " if notified else "" +        action = f"{dm_result}:ok_hand: permanently muted {user.mention}" +          if reason is None: -            result_message = f":ok_hand: permanently muted {user.mention}." +            await ctx.send(f"{action}.")          else: -            result_message = f":ok_hand: permanently muted {user.mention} ({reason})." +            await ctx.send(f"{action} ({reason}).") -        await ctx.send(result_message) +        if not notified: +            await self.log_notify_failure(user, ctx.author, "mute")          # Send a log message to the mod log          await self.mod_log.send_log_message( @@ -255,7 +271,7 @@ class Moderation(Scheduler):          :param reason: The reason for the temporary mute.          """ -        await self.notify_infraction( +        notified = await self.notify_infraction(              user=user,              infr_type="Mute",              duration=duration, @@ -275,12 +291,16 @@ class Moderation(Scheduler):          loop = asyncio.get_event_loop()          self.schedule_task(loop, infraction_object["id"], infraction_object) +        dm_result = ":incoming_envelope: " if notified else "" +        action = f"{dm_result}:ok_hand: muted {user.mention} until {infraction_expiration}" +          if reason is None: -            result_message = f":ok_hand: muted {user.mention} until {infraction_expiration}." +            await ctx.send(f"{action}.")          else: -            result_message = f":ok_hand: muted {user.mention} until {infraction_expiration} ({reason})." +            await ctx.send(f"{action} ({reason}).") -        await ctx.send(result_message) +        if not notified: +            await self.log_notify_failure(user, ctx.author, "mute")          # Send a log message to the mod log          await self.mod_log.send_log_message( @@ -307,7 +327,7 @@ class Moderation(Scheduler):          :param reason: The reason for the temporary ban.          """ -        await self.notify_infraction( +        notified = await self.notify_infraction(              user=user,              infr_type="Ban",              duration=duration, @@ -329,12 +349,16 @@ class Moderation(Scheduler):          loop = asyncio.get_event_loop()          self.schedule_task(loop, infraction_object["id"], infraction_object) +        dm_result = ":incoming_envelope: " if notified else "" +        action = f"{dm_result}:ok_hand: banned {user.mention} until {infraction_expiration}" +          if reason is None: -            result_message = f":ok_hand: banned {user.mention} until {infraction_expiration}." +            await ctx.send(f"{action}.")          else: -            result_message = f":ok_hand: banned {user.mention} until {infraction_expiration} ({reason})." +            await ctx.send(f"{action} ({reason}).") -        await ctx.send(result_message) +        if not notified: +            await self.log_notify_failure(user, ctx.author, "ban")          # Send a log message to the mod log          await self.mod_log.send_log_message( @@ -629,7 +653,18 @@ class Moderation(Scheduler):              if infraction_object["expires_at"] is not None:                  self.cancel_expiration(infraction_object["id"]) -            await ctx.send(f":ok_hand: Un-muted {user.mention}.") +            notified = await self.notify_pardon( +                user=user, +                title="You have been unmuted.", +                content="You may now send messages in the server.", +                icon_url=Icons.user_unmute +            ) + +            dm_result = ":incoming_envelope: " if notified else "" +            await ctx.send(f"{dm_result}:ok_hand: Un-muted {user.mention}.") + +            if not notified: +                await self.log_notify_failure(user, ctx.author, "unmute")              # Send a log message to the mod log              await self.mod_log.send_log_message( @@ -643,13 +678,6 @@ class Moderation(Scheduler):                      Intended expiry: {infraction_object['expires_at']}                  """)              ) - -            await self.notify_pardon( -                user=user, -                title="You have been unmuted.", -                content="You may now send messages in the server.", -                icon_url=Icons.user_unmute -            )          except Exception:              log.exception("There was an error removing an infraction.")              await ctx.send(":x: There was an error removing the infraction.") @@ -1119,7 +1147,7 @@ class Moderation(Scheduler):          embed.title = f"Please review our rules over at {RULES_URL}"          embed.url = RULES_URL -        await self.send_private_embed(user, embed) +        return await self.send_private_embed(user, embed)      async def notify_pardon(              self, user: Union[User, Member], title: str, content: str, icon_url: str = Icons.user_verified @@ -1140,7 +1168,7 @@ class Moderation(Scheduler):          embed.set_author(name=title, icon_url=icon_url) -        await self.send_private_embed(user, embed) +        return await self.send_private_embed(user, embed)      async def send_private_embed(self, user: Union[User, Member], embed: Embed):          """ @@ -1155,11 +1183,22 @@ class Moderation(Scheduler):          try:              await user.send(embed=embed) +            return True          except (HTTPException, Forbidden):              log.debug(                  f"Infraction-related information could not be sent to user {user} ({user.id}). "                  "They've probably just disabled private messages."              ) +            return False + +    async def log_notify_failure(self, target: str, actor: Member, infraction_type: str): +        await self.mod_log.send_log_message( +            icon_url=Icons.token_removed, +            content=actor.mention, +            colour=Colour(Colours.soft_red), +            title="Notification Failed", +            text=f"Direct message was unable to be sent.\nUser: {target.mention}\nType: {infraction_type}" +        )      # endregion diff --git a/bot/cogs/modlog.py b/bot/cogs/modlog.py index 1d1546d5b..905f114c1 100644 --- a/bot/cogs/modlog.py +++ b/bot/cogs/modlog.py @@ -104,8 +104,9 @@ class ModLog:                  self._ignored[event].append(item)      async def send_log_message( -            self, icon_url: Optional[str], colour: Colour, title: Optional[str], text: str, thumbnail: str = None, -            channel_id: int = Channels.modlog, ping_everyone: bool = False, files: List[File] = None +            self, icon_url: Optional[str], colour: Colour, title: Optional[str], text: str, +            thumbnail: str = None, channel_id: int = Channels.modlog, ping_everyone: bool = False, +            files: List[File] = None, content: str = None      ):          embed = Embed(description=text) @@ -118,10 +119,11 @@ class ModLog:          if thumbnail is not None:              embed.set_thumbnail(url=thumbnail) -        content = None -          if ping_everyone: -            content = "@everyone" +            if content: +                content = f"@everyone\n{content}" +            else: +                content = "@everyone"          await self.bot.get_channel(channel_id).send(content=content, embed=embed, files=files)  |