diff options
| -rw-r--r-- | bot/cogs/moderation.py | 89 |
1 files 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 |