From bf531350d50c200f9dfa06525c97d6ad1a9f75d1 Mon Sep 17 00:00:00 2001 From: scragly <29337040+scragly@users.noreply.github.com> Date: Thu, 27 Dec 2018 00:59:26 +1000 Subject: Add DM emoji indicator for infr notify success. --- bot/cogs/moderation.py | 89 +++++++++++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 40 deletions(-) diff --git a/bot/cogs/moderation.py b/bot/cogs/moderation.py index 6e958b912..0fc47c9df 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,13 @@ 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(result_message) + await ctx.send(f"{action} ({reason}).") @with_role(*MODERATION_ROLES) @command(name="kick") @@ -108,7 +109,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 +122,13 @@ 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(result_message) + await ctx.send(f"{action} ({reason}).") # Send a log message to the mod log await self.mod_log.send_log_message( @@ -150,7 +152,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 +167,13 @@ 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(result_message) + await ctx.send(f"{action} ({reason}).") # Send a log message to the mod log await self.mod_log.send_log_message( @@ -194,7 +197,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 +212,13 @@ 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(result_message) + await ctx.send(f"{action} ({reason}).") # Send a log message to the mod log await self.mod_log.send_log_message( @@ -242,7 +246,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 +266,13 @@ 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(result_message) + await ctx.send(f"{action} ({reason}).") # Send a log message to the mod log await self.mod_log.send_log_message( @@ -294,7 +299,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 +321,13 @@ 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(result_message) + await ctx.send(f"{action} ({reason}).") # Send a log message to the mod log await self.mod_log.send_log_message( @@ -603,7 +609,15 @@ 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}.") # Send a log message to the mod log await self.mod_log.send_log_message( @@ -617,13 +631,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 +1100,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 +1121,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 +1136,13 @@ 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 # endregion -- cgit v1.2.3 From 6dd7d7d641403d468418eb8b8d1d60d35e5d8e0d Mon Sep 17 00:00:00 2001 From: scragly <29337040+scragly@users.noreply.github.com> Date: Thu, 27 Dec 2018 04:53:10 +1000 Subject: Add content kwarg to modlog messages. --- bot/cogs/modlog.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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) -- cgit v1.2.3 From 7a6e289636c131bf724f82c8f00a008b275eb79c Mon Sep 17 00:00:00 2001 From: scragly <29337040+scragly@users.noreply.github.com> Date: Thu, 27 Dec 2018 04:53:47 +1000 Subject: Ping mod on infr notify failure in modlog. --- bot/cogs/moderation.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/bot/cogs/moderation.py b/bot/cogs/moderation.py index 0fc47c9df..24b60332f 100644 --- a/bot/cogs/moderation.py +++ b/bot/cogs/moderation.py @@ -100,6 +100,9 @@ class Moderation(Scheduler): else: await ctx.send(f"{action} ({reason}).") + if not notified: + await self.log_notify_failure(user, ctx.author, "warning") + @with_role(*MODERATION_ROLES) @command(name="kick") async def kick(self, ctx: Context, user: Member, *, reason: str = None): @@ -130,6 +133,9 @@ class Moderation(Scheduler): else: await ctx.send(f"{action} ({reason}).") + 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( icon_url=Icons.sign_out, @@ -175,6 +181,9 @@ class Moderation(Scheduler): else: await ctx.send(f"{action} ({reason}).") + 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( icon_url=Icons.user_ban, @@ -220,6 +229,9 @@ class Moderation(Scheduler): else: await ctx.send(f"{action} ({reason}).") + 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( icon_url=Icons.user_mute, @@ -274,6 +286,9 @@ class Moderation(Scheduler): else: await ctx.send(f"{action} ({reason}).") + 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( icon_url=Icons.user_mute, @@ -329,6 +344,9 @@ class Moderation(Scheduler): else: await ctx.send(f"{action} ({reason}).") + 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( icon_url=Icons.user_ban, @@ -619,6 +637,9 @@ class Moderation(Scheduler): 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( icon_url=Icons.user_unmute, @@ -1144,6 +1165,15 @@ class Moderation(Scheduler): ) 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 async def __error(self, ctx, error): -- cgit v1.2.3 From c419a2516d63aba2ada59694e345f27eaa5a0e1a Mon Sep 17 00:00:00 2001 From: sco1 Date: Sat, 29 Dec 2018 14:27:44 -0500 Subject: Add mod log event for member warn & shadowwarn --- bot/cogs/moderation.py | 26 ++++++++++++++++++++++++++ bot/constants.py | 2 ++ config-default.yml | 2 ++ 3 files changed, 30 insertions(+) diff --git a/bot/cogs/moderation.py b/bot/cogs/moderation.py index 6e958b912..8add6fdde 100644 --- a/bot/cogs/moderation.py +++ b/bot/cogs/moderation.py @@ -99,6 +99,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 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") async def kick(self, ctx: Context, user: Member, *, reason: str = None): @@ -361,6 +374,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): 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" -- cgit v1.2.3