Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 13 additions & 143 deletions bot/cogs/moderation.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,7 @@ async def warn(self, ctx: Context, user: UserTypes, *, reason: str = None) -> No

dm_result = ":incoming_envelope: " if notified else ""
action = f"{dm_result}:ok_hand: warned {user.mention}"

if reason is None:
await ctx.send(f"{action}.")
else:
await ctx.send(f"{action} ({reason}).")
await ctx.send(f"{action}.")

if notified:
dm_status = "Sent"
Expand Down Expand Up @@ -138,11 +134,7 @@ async def kick(self, ctx: Context, user: Member, *, reason: str = None) -> None:

dm_result = ":incoming_envelope: " if notified else ""
action = f"{dm_result}:ok_hand: kicked {user.mention}"

if reason is None:
await ctx.send(f"{action}.")
else:
await ctx.send(f"{action} ({reason}).")
await ctx.send(f"{action}.")

dm_status = "Sent" if notified else "**Failed**"
title = "Member kicked" if action_result else "Member kicked (Failed)"
Expand Down Expand Up @@ -196,11 +188,7 @@ async def ban(self, ctx: Context, user: UserTypes, *, reason: str = None) -> Non

dm_result = ":incoming_envelope: " if notified else ""
action = f"{dm_result}:ok_hand: permanently banned {user.mention}"

if reason is None:
await ctx.send(f"{action}.")
else:
await ctx.send(f"{action} ({reason}).")
await ctx.send(f"{action}.")

dm_status = "Sent" if notified else "**Failed**"
log_content = None if all((notified, action_result)) else ctx.author.mention
Expand All @@ -223,62 +211,11 @@ async def ban(self, ctx: Context, user: UserTypes, *, reason: str = None) -> Non
footer=f"ID {infraction['id']}"
)

@with_role(*MODERATION_ROLES)
@command()
async def mute(self, ctx: Context, user: Member, *, reason: str = None) -> None:
"""Create a permanent mute infraction for a user with the provided reason."""
if await already_has_active_infraction(ctx=ctx, user=user, type="mute"):
return

infraction = await post_infraction(ctx, user, type="mute", reason=reason)
if infraction is None:
return

self.mod_log.ignore(Event.member_update, user.id)
await user.add_roles(self._muted_role, reason=reason)

notified = await self.notify_infraction(
user=user,
infr_type="Mute",
expires_at="Permanent",
reason=reason
)

dm_result = ":incoming_envelope: " if notified else ""
action = f"{dm_result}:ok_hand: permanently muted {user.mention}"

if reason is None:
await ctx.send(f"{action}.")
else:
await ctx.send(f"{action} ({reason}).")

if notified:
dm_status = "Sent"
log_content = None
else:
dm_status = "**Failed**"
log_content = ctx.author.mention

await self.mod_log.send_log_message(
icon_url=Icons.user_mute,
colour=Colour(Colours.soft_red),
title="Member permanently muted",
thumbnail=user.avatar_url_as(static_format="png"),
text=textwrap.dedent(f"""
Member: {user.mention} (`{user.id}`)
Actor: {ctx.message.author}
DM: {dm_status}
Reason: {reason}
"""),
content=log_content,
footer=f"ID {infraction['id']}"
)

# endregion
# region: Temporary infractions

@with_role(*MODERATION_ROLES)
@command()
@command(aliases=('mute',))
async def tempmute(self, ctx: Context, user: Member, duration: Duration, *, reason: str = None) -> None:
"""
Create a temporary mute infraction for a user with the provided expiration and reason.
Expand Down Expand Up @@ -314,11 +251,7 @@ async def tempmute(self, ctx: Context, user: Member, duration: Duration, *, reas

dm_result = ":incoming_envelope: " if notified else ""
action = f"{dm_result}:ok_hand: muted {user.mention} until {infraction_expiration}"

if reason is None:
await ctx.send(f"{action}.")
else:
await ctx.send(f"{action} ({reason}).")
await ctx.send(f"{action}.")

if notified:
dm_status = "Sent"
Expand Down Expand Up @@ -391,11 +324,7 @@ async def tempban(self, ctx: Context, user: UserTypes, duration: Duration, *, re

dm_result = ":incoming_envelope: " if notified else ""
action = f"{dm_result}:ok_hand: banned {user.mention} until {infraction_expiration}"

if reason is None:
await ctx.send(f"{action}.")
else:
await ctx.send(f"{action} ({reason}).")
await ctx.send(f"{action}.")

dm_status = "Sent" if notified else "**Failed**"
log_content = None if all((notified, action_result)) else ctx.author.mention
Expand Down Expand Up @@ -423,7 +352,7 @@ async def tempban(self, ctx: Context, user: UserTypes, duration: Duration, *, re
# region: Permanent shadow infractions

@with_role(*MODERATION_ROLES)
@command(hidden=True, aliases=['shadowwarn', 'swarn', 'shadow_warn'])
@command(hidden=True)
async def note(self, ctx: Context, user: UserTypes, *, reason: str = None) -> None:
"""
Create a private infraction note in the database for a user with the provided reason.
Expand All @@ -434,10 +363,7 @@ async def note(self, ctx: Context, user: UserTypes, *, reason: str = None) -> No
if infraction is None:
return

if reason is None:
await ctx.send(f":ok_hand: note added for {user.mention}.")
else:
await ctx.send(f":ok_hand: note added for {user.mention} ({reason}).")
await ctx.send(f":ok_hand: note added for {user.mention}.")

await self.mod_log.send_log_message(
icon_url=Icons.user_warn,
Expand Down Expand Up @@ -477,10 +403,7 @@ async def shadow_kick(self, ctx: Context, user: Member, *, reason: str = None) -
except Forbidden:
action_result = False

if reason is None:
await ctx.send(f":ok_hand: kicked {user.mention}.")
else:
await ctx.send(f":ok_hand: kicked {user.mention} ({reason}).")
await ctx.send(f":ok_hand: kicked {user.mention}.")

title = "Member shadow kicked"
if action_result:
Expand Down Expand Up @@ -532,10 +455,7 @@ async def shadow_ban(self, ctx: Context, user: UserTypes, *, reason: str = None)
except Forbidden:
action_result = False

if reason is None:
await ctx.send(f":ok_hand: permanently banned {user.mention}.")
else:
await ctx.send(f":ok_hand: permanently banned {user.mention} ({reason}).")
await ctx.send(f":ok_hand: permanently banned {user.mention}.")

title = "Member permanently banned"
if action_result:
Expand All @@ -558,47 +478,11 @@ async def shadow_ban(self, ctx: Context, user: UserTypes, *, reason: str = None)
footer=f"ID {infraction['id']}"
)

@with_role(*MODERATION_ROLES)
@command(hidden=True, aliases=['shadowmute', 'smute'])
async def shadow_mute(self, ctx: Context, user: Member, *, reason: str = None) -> None:
"""
Create a permanent mute infraction for a user with the provided reason.

This does not send the user a notification.
"""
if await already_has_active_infraction(ctx=ctx, user=user, type="mute"):
return

infraction = await post_infraction(ctx, user, type="mute", reason=reason, hidden=True)
if infraction is None:
return

self.mod_log.ignore(Event.member_update, user.id)
await user.add_roles(self._muted_role, reason=reason)

if reason is None:
await ctx.send(f":ok_hand: permanently muted {user.mention}.")
else:
await ctx.send(f":ok_hand: permanently muted {user.mention} ({reason}).")

await self.mod_log.send_log_message(
icon_url=Icons.user_mute,
colour=Colour(Colours.soft_red),
title="Member permanently muted",
thumbnail=user.avatar_url_as(static_format="png"),
text=textwrap.dedent(f"""
Member: {user.mention} (`{user.id}`)
Actor: {ctx.message.author}
Reason: {reason}
"""),
footer=f"ID {infraction['id']}"
)

# endregion
# region: Temporary shadow infractions

@with_role(*MODERATION_ROLES)
@command(hidden=True, aliases=["shadowtempmute, stempmute"])
@command(hidden=True, aliases=["shadowtempmute, stempmute", "shadowmute", "smute"])
async def shadow_tempmute(
self, ctx: Context, user: Member, duration: Duration, *, reason: str = None
) -> None:
Expand Down Expand Up @@ -626,15 +510,8 @@ async def shadow_tempmute(
.fromisoformat(infraction["expires_at"][:-1])
.strftime('%c')
)

self.schedule_task(ctx.bot.loop, infraction["id"], infraction)

if reason is None:
await ctx.send(f":ok_hand: muted {user.mention} until {infraction_expiration}.")
else:
await ctx.send(
f":ok_hand: muted {user.mention} until {infraction_expiration} ({reason})."
)
await ctx.send(f":ok_hand: muted {user.mention} until {infraction_expiration}.")

await self.mod_log.send_log_message(
icon_url=Icons.user_mute,
Expand Down Expand Up @@ -690,15 +567,8 @@ async def shadow_tempban(
.fromisoformat(infraction["expires_at"][:-1])
.strftime('%c')
)

self.schedule_task(ctx.bot.loop, infraction["id"], infraction)

if reason is None:
await ctx.send(f":ok_hand: banned {user.mention} until {infraction_expiration}.")
else:
await ctx.send(
f":ok_hand: banned {user.mention} until {infraction_expiration} ({reason})."
)
await ctx.send(f":ok_hand: banned {user.mention} until {infraction_expiration}.")

title = "Member temporarily banned"
if action_result:
Expand Down
2 changes: 1 addition & 1 deletion bot/cogs/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self, bot: Bot):
self.bot = bot
self.tag_cooldowns = {}

@group(name='tags', aliases=('tag', 't'), hidden=True, invoke_without_command=True)
@group(name='tags', aliases=('tag', 't'), invoke_without_command=True)
async def tags_group(self, ctx: Context, *, tag_name: TagNameConverter = None) -> None:
"""Show all known tags, a single tag, or run a subcommand."""
await ctx.invoke(self.get_command, tag_name=tag_name)
Expand Down