aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Mark <[email protected]>2020-06-17 12:17:07 -0700
committerGravatar GitHub <[email protected]>2020-06-17 12:17:07 -0700
commit632b80746e0081d790cdb63eb8b90bfbed1b0813 (patch)
tree2c8bd548c8f7187fb1aebf0781080467c4288394
parentAdd LMGTFY to domain blacklist (diff)
parentFormat parameters with a more consistent style (diff)
Merge pull request #1001 from python-discord/bug/mod/bot-68/ban-strips-none
Check infraction reason isn't None before shortening it
-rw-r--r--bot/cogs/moderation/infractions.py53
-rw-r--r--bot/cogs/moderation/scheduler.py7
2 files changed, 38 insertions, 22 deletions
diff --git a/bot/cogs/moderation/infractions.py b/bot/cogs/moderation/infractions.py
index 5bfaad796..3b28526b2 100644
--- a/bot/cogs/moderation/infractions.py
+++ b/bot/cogs/moderation/infractions.py
@@ -53,7 +53,7 @@ class Infractions(InfractionScheduler, commands.Cog):
# region: Permanent infractions
@command()
- async def warn(self, ctx: Context, user: Member, *, reason: str = None) -> None:
+ async def warn(self, ctx: Context, user: Member, *, reason: t.Optional[str] = None) -> None:
"""Warn a user for the given reason."""
infraction = await utils.post_infraction(ctx, user, "warning", reason, active=False)
if infraction is None:
@@ -62,12 +62,12 @@ class Infractions(InfractionScheduler, commands.Cog):
await self.apply_infraction(ctx, infraction, user)
@command()
- async def kick(self, ctx: Context, user: Member, *, reason: str = None) -> None:
+ async def kick(self, ctx: Context, user: Member, *, reason: t.Optional[str] = None) -> None:
"""Kick a user for the given reason."""
await self.apply_kick(ctx, user, reason, active=False)
@command()
- async def ban(self, ctx: Context, user: FetchedMember, *, reason: str = None) -> None:
+ async def ban(self, ctx: Context, user: FetchedMember, *, reason: t.Optional[str] = None) -> None:
"""Permanently ban a user for the given reason and stop watching them with Big Brother."""
await self.apply_ban(ctx, user, reason)
@@ -75,7 +75,7 @@ class Infractions(InfractionScheduler, commands.Cog):
# region: Temporary infractions
@command(aliases=["mute"])
- async def tempmute(self, ctx: Context, user: Member, duration: Expiry, *, reason: str = None) -> None:
+ async def tempmute(self, ctx: Context, user: Member, duration: Expiry, *, reason: t.Optional[str] = None) -> None:
"""
Temporarily mute a user for the given reason and duration.
@@ -94,7 +94,14 @@ class Infractions(InfractionScheduler, commands.Cog):
await self.apply_mute(ctx, user, reason, expires_at=duration)
@command()
- async def tempban(self, ctx: Context, user: FetchedMember, duration: Expiry, *, reason: str = None) -> None:
+ async def tempban(
+ self,
+ ctx: Context,
+ user: FetchedMember,
+ duration: Expiry,
+ *,
+ reason: t.Optional[str] = None
+ ) -> None:
"""
Temporarily ban a user for the given reason and duration.
@@ -116,7 +123,7 @@ class Infractions(InfractionScheduler, commands.Cog):
# region: Permanent shadow infractions
@command(hidden=True)
- async def note(self, ctx: Context, user: FetchedMember, *, reason: str = None) -> None:
+ async def note(self, ctx: Context, user: FetchedMember, *, reason: t.Optional[str] = None) -> None:
"""Create a private note for a user with the given reason without notifying the user."""
infraction = await utils.post_infraction(ctx, user, "note", reason, hidden=True, active=False)
if infraction is None:
@@ -125,12 +132,12 @@ class Infractions(InfractionScheduler, commands.Cog):
await self.apply_infraction(ctx, infraction, user)
@command(hidden=True, aliases=['shadowkick', 'skick'])
- async def shadow_kick(self, ctx: Context, user: Member, *, reason: str = None) -> None:
+ async def shadow_kick(self, ctx: Context, user: Member, *, reason: t.Optional[str] = None) -> None:
"""Kick a user for the given reason without notifying the user."""
await self.apply_kick(ctx, user, reason, hidden=True, active=False)
@command(hidden=True, aliases=['shadowban', 'sban'])
- async def shadow_ban(self, ctx: Context, user: FetchedMember, *, reason: str = None) -> None:
+ async def shadow_ban(self, ctx: Context, user: FetchedMember, *, reason: t.Optional[str] = None) -> None:
"""Permanently ban a user for the given reason without notifying the user."""
await self.apply_ban(ctx, user, reason, hidden=True)
@@ -138,7 +145,13 @@ class Infractions(InfractionScheduler, commands.Cog):
# region: Temporary shadow infractions
@command(hidden=True, aliases=["shadowtempmute, stempmute", "shadowmute", "smute"])
- async def shadow_tempmute(self, ctx: Context, user: Member, duration: Expiry, *, reason: str = None) -> None:
+ async def shadow_tempmute(
+ self, ctx: Context,
+ user: Member,
+ duration: Expiry,
+ *,
+ reason: t.Optional[str] = None
+ ) -> None:
"""
Temporarily mute a user for the given reason and duration without notifying the user.
@@ -163,7 +176,7 @@ class Infractions(InfractionScheduler, commands.Cog):
user: FetchedMember,
duration: Expiry,
*,
- reason: str = None
+ reason: t.Optional[str] = None
) -> None:
"""
Temporarily ban a user for the given reason and duration without notifying the user.
@@ -198,7 +211,7 @@ class Infractions(InfractionScheduler, commands.Cog):
# endregion
# region: Base apply functions
- async def apply_mute(self, ctx: Context, user: Member, reason: str, **kwargs) -> None:
+ async def apply_mute(self, ctx: Context, user: Member, reason: t.Optional[str], **kwargs) -> None:
"""Apply a mute infraction with kwargs passed to `post_infraction`."""
if await utils.get_active_infraction(ctx, user, "mute"):
return
@@ -218,7 +231,7 @@ class Infractions(InfractionScheduler, commands.Cog):
await self.apply_infraction(ctx, infraction, user, action())
@respect_role_hierarchy()
- async def apply_kick(self, ctx: Context, user: Member, reason: str, **kwargs) -> None:
+ async def apply_kick(self, ctx: Context, user: Member, reason: t.Optional[str], **kwargs) -> None:
"""Apply a kick infraction with kwargs passed to `post_infraction`."""
infraction = await utils.post_infraction(ctx, user, "kick", reason, active=False, **kwargs)
if infraction is None:
@@ -226,11 +239,14 @@ class Infractions(InfractionScheduler, commands.Cog):
self.mod_log.ignore(Event.member_remove, user.id)
- action = user.kick(reason=textwrap.shorten(reason, width=512, placeholder="..."))
+ if reason:
+ reason = textwrap.shorten(reason, width=512, placeholder="...")
+
+ action = user.kick(reason=reason)
await self.apply_infraction(ctx, infraction, user, action)
@respect_role_hierarchy()
- async def apply_ban(self, ctx: Context, user: UserSnowflake, reason: str, **kwargs) -> None:
+ async def apply_ban(self, ctx: Context, user: UserSnowflake, reason: t.Optional[str], **kwargs) -> None:
"""
Apply a ban infraction with kwargs passed to `post_infraction`.
@@ -259,9 +275,10 @@ class Infractions(InfractionScheduler, commands.Cog):
self.mod_log.ignore(Event.member_remove, user.id)
- truncated_reason = textwrap.shorten(reason, width=512, placeholder="...")
+ if reason:
+ reason = textwrap.shorten(reason, width=512, placeholder="...")
- action = ctx.guild.ban(user, reason=truncated_reason, delete_message_days=0)
+ action = ctx.guild.ban(user, reason=reason, delete_message_days=0)
await self.apply_infraction(ctx, infraction, user, action)
if infraction.get('expires_at') is not None:
@@ -281,7 +298,7 @@ class Infractions(InfractionScheduler, commands.Cog):
# endregion
# region: Base pardon functions
- async def pardon_mute(self, user_id: int, guild: discord.Guild, reason: str) -> t.Dict[str, str]:
+ async def pardon_mute(self, user_id: int, guild: discord.Guild, reason: t.Optional[str]) -> t.Dict[str, str]:
"""Remove a user's muted role, DM them a notification, and return a log dict."""
user = guild.get_member(user_id)
log_text = {}
@@ -307,7 +324,7 @@ class Infractions(InfractionScheduler, commands.Cog):
return log_text
- async def pardon_ban(self, user_id: int, guild: discord.Guild, reason: str) -> t.Dict[str, str]:
+ async def pardon_ban(self, user_id: int, guild: discord.Guild, reason: t.Optional[str]) -> t.Dict[str, str]:
"""Remove a user's ban on the Discord guild and return a log dict."""
user = discord.Object(user_id)
log_text = {}
diff --git a/bot/cogs/moderation/scheduler.py b/bot/cogs/moderation/scheduler.py
index b03d89537..d75a72ddb 100644
--- a/bot/cogs/moderation/scheduler.py
+++ b/bot/cogs/moderation/scheduler.py
@@ -127,18 +127,17 @@ class InfractionScheduler(Scheduler):
dm_result = ":incoming_envelope: "
dm_log_text = "\nDM: Sent"
+ end_msg = ""
if infraction["actor"] == self.bot.user.id:
log.trace(
f"Infraction #{id_} actor is bot; including the reason in the confirmation message."
)
-
- end_msg = f" (reason: {textwrap.shorten(reason, width=1500, placeholder='...')})"
+ if reason:
+ end_msg = f" (reason: {textwrap.shorten(reason, width=1500, placeholder='...')})"
elif ctx.channel.id not in STAFF_CHANNELS:
log.trace(
f"Infraction #{id_} context is not in a staff channel; omitting infraction count."
)
-
- end_msg = ""
else:
log.trace(f"Fetching total infraction count for {user}.")