diff options
| author | 2019-01-01 13:07:04 +0100 | |
|---|---|---|
| committer | 2019-01-01 13:07:04 +0100 | |
| commit | 1c95a6888e74391e7cc822db9b22a5b7617a517d (patch) | |
| tree | 9a8b6246067618d5ee2743ec0255cc273179918c | |
| parent | Remove the cursed trailing whitespace (diff) | |
| parent | Merge pull request #223 from python-discord/mod-dm-status (diff) | |
Merge branch 'master' into invite-filter-fix
| -rw-r--r-- | bot/cogs/moderation.py | 133 | ||||
| -rw-r--r-- | bot/cogs/modlog.py | 12 | ||||
| -rw-r--r-- | bot/constants.py | 2 | ||||
| -rw-r--r-- | config-default.yml | 2 |
4 files changed, 110 insertions, 39 deletions
diff --git a/bot/cogs/moderation.py b/bot/cogs/moderation.py index 6e958b912..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,29 @@ 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( + icon_url=Icons.user_warn, + colour=Colour(Colours.soft_red), + title="Member warned", + thumbnail=user.avatar_url_as(static_format="png"), + text=textwrap.dedent(f""" + Member: {user.mention} (`{user.id}`) + Actor: {ctx.message.author} + Reason: {reason} + """) + ) @with_role(*MODERATION_ROLES) @command(name="kick") @@ -108,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 @@ -121,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( @@ -150,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", @@ -165,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( @@ -194,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", @@ -209,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( @@ -242,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, @@ -262,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( @@ -294,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, @@ -316,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( @@ -361,6 +398,19 @@ class Moderation(Scheduler): await ctx.send(result_message) + # Send a message to the mod log + await self.mod_log.send_log_message( + icon_url=Icons.user_warn, + colour=Colour(Colours.soft_red), + title="Member shadow warned", + thumbnail=user.avatar_url_as(static_format="png"), + text=textwrap.dedent(f""" + Member: {user.mention} (`{user.id}`) + Actor: {ctx.message.author} + Reason: {reason} + """) + ) + @with_role(*MODERATION_ROLES) @command(name="shadow_kick", hidden=True, aliases=['shadowkick', 'skick']) async def shadow_kick(self, ctx: Context, user: Member, *, reason: str = None): @@ -603,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( @@ -617,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.") @@ -1093,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 @@ -1114,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): """ @@ -1129,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) diff --git a/bot/constants.py b/bot/constants.py index 5e7927ed9..99ef98da2 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -292,6 +292,8 @@ class Icons(metaclass=YAMLGetter): user_unmute: str user_verified: str + user_warn: str + pencil: str remind_blurple: str diff --git a/config-default.yml b/config-default.yml index e7145289d..3a1ad8052 100644 --- a/config-default.yml +++ b/config-default.yml @@ -72,6 +72,8 @@ style: user_unmute: "https://cdn.discordapp.com/emojis/472472639206719508.png" user_verified: "https://cdn.discordapp.com/emojis/470326274519334936.png" + user_warn: "https://cdn.discordapp.com/emojis/470326274238447633.png" + pencil: "https://cdn.discordapp.com/emojis/470326272401211415.png" remind_blurple: "https://cdn.discordapp.com/emojis/477907609215827968.png" |