aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bot/cogs/moderation.py107
-rw-r--r--bot/cogs/modlog.py12
2 files changed, 80 insertions, 39 deletions
diff --git a/bot/cogs/moderation.py b/bot/cogs/moderation.py
index 6e958b912..24b60332f 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")
@with_role(*MODERATION_ROLES)
@command(name="kick")
@@ -108,7 +112,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 +125,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 +158,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 +173,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 +206,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 +221,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 +258,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 +278,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 +314,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 +336,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(
@@ -603,7 +627,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 +652,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 +1121,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 +1142,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 +1157,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)