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
2 changes: 1 addition & 1 deletion bot/exts/moderation/infraction/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"note": (Icons.user_warn, None),
"superstar": (Icons.superstarify, Icons.unsuperstarify),
"warning": (Icons.user_warn, None),
"voice_ban": (Icons.voice_state_red, Icons.voice_state_green),
"voice_mute": (Icons.voice_state_red, Icons.voice_state_green),
}
RULES_URL = "https://pythondiscord.com/pages/rules"

Expand Down
87 changes: 58 additions & 29 deletions bot/exts/moderation/infraction/infractions.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Infractions(InfractionScheduler, commands.Cog):
category_description = "Server moderation tools."

def __init__(self, bot: Bot):
super().__init__(bot, supported_infractions={"ban", "kick", "mute", "note", "warning", "voice_ban"})
super().__init__(bot, supported_infractions={"ban", "kick", "mute", "note", "warning", "voice_mute"})

self.category = "Moderation"
self._muted_role = discord.Object(constants.Roles.muted)
Expand Down Expand Up @@ -107,8 +107,19 @@ async def purgeban(
"""
await self.apply_ban(ctx, user, reason, 1, expires_at=duration)

@command(aliases=('vban',))
async def voiceban(
@command(aliases=("vban",))
async def voiceban(self, ctx: Context) -> None:
"""
NOT IMPLEMENTED.

Permanently ban a user from joining voice channels.

If duration is specified, it temporarily voice bans that user for the given duration.
"""
await ctx.send(":x: This command is not yet implemented. Maybe you meant to use `voicemute`?")

@command(aliases=("vmute",))
async def voicemute(
self,
ctx: Context,
user: UnambiguousMemberOrUser,
Expand All @@ -117,11 +128,11 @@ async def voiceban(
reason: t.Optional[str]
) -> None:
"""
Permanently ban user from using voice channels.
Permanently mute user in voice channels.

If duration is specified, it temporarily voice bans that user for the given duration.
If duration is specified, it temporarily voice mutes that user for the given duration.
"""
await self.apply_voice_ban(ctx, user, reason, expires_at=duration)
await self.apply_voice_mute(ctx, user, reason, expires_at=duration)

# endregion
# region: Temporary infractions
Expand Down Expand Up @@ -186,16 +197,25 @@ async def tempban(
await self.apply_ban(ctx, user, reason, expires_at=duration)

@command(aliases=("tempvban", "tvban"))
async def tempvoiceban(
self,
ctx: Context,
user: UnambiguousMemberOrUser,
duration: Expiry,
*,
reason: t.Optional[str]
async def tempvoiceban(self, ctx: Context) -> None:
"""
NOT IMPLEMENTED.

Temporarily voice bans that user for the given duration.
"""
await ctx.send(":x: This command is not yet implemented. Maybe you meant to use `tempvoicemute`?")

@command(aliases=("tempvmute", "tvmute"))
async def tempvoicemute(
self,
ctx: Context,
user: UnambiguousMemberOrUser,
duration: Expiry,
*,
reason: t.Optional[str]
) -> None:
"""
Temporarily voice ban a user for the given reason and duration.
Temporarily voice mute a user for the given reason and duration.

A unit of time should be appended to the duration.
Units (∗case-sensitive):
Expand All @@ -209,7 +229,7 @@ async def tempvoiceban(

Alternatively, an ISO 8601 timestamp can be provided for the duration.
"""
await self.apply_voice_ban(ctx, user, reason, expires_at=duration)
await self.apply_voice_mute(ctx, user, reason, expires_at=duration)

# endregion
# region: Permanent shadow infractions
Expand Down Expand Up @@ -271,9 +291,18 @@ async def unban(self, ctx: Context, user: UnambiguousMemberOrUser) -> None:
await self.pardon_infraction(ctx, "ban", user)

@command(aliases=("uvban",))
async def unvoiceban(self, ctx: Context, user: UnambiguousMemberOrUser) -> None:
"""Prematurely end the active voice ban infraction for the user."""
await self.pardon_infraction(ctx, "voice_ban", user)
async def unvoiceban(self, ctx: Context) -> None:
"""
NOT IMPLEMENTED.

Temporarily voice bans that user for the given duration.
"""
await ctx.send(":x: This command is not yet implemented. Maybe you meant to use `unvoicemute`?")

@command(aliases=("uvmute",))
async def unvoicemute(self, ctx: Context, user: UnambiguousMemberOrUser) -> None:
"""Prematurely end the active voice mute infraction for the user."""
await self.pardon_infraction(ctx, "voice_mute", user)

# endregion
# region: Base apply functions
Expand Down Expand Up @@ -395,12 +424,12 @@ async def apply_ban(
await bb_cog.apply_unwatch(ctx, user, bb_reason, send_message=False)

@respect_role_hierarchy(member_arg=2)
async def apply_voice_ban(self, ctx: Context, user: MemberOrUser, reason: t.Optional[str], **kwargs) -> None:
"""Apply a voice ban infraction with kwargs passed to `post_infraction`."""
if await _utils.get_active_infraction(ctx, user, "voice_ban"):
async def apply_voice_mute(self, ctx: Context, user: MemberOrUser, reason: t.Optional[str], **kwargs) -> None:
"""Apply a voice mute infraction with kwargs passed to `post_infraction`."""
if await _utils.get_active_infraction(ctx, user, "voice_mute"):
return

infraction = await _utils.post_infraction(ctx, user, "voice_ban", reason, active=True, **kwargs)
infraction = await _utils.post_infraction(ctx, user, "voice_mute", reason, active=True, **kwargs)
if infraction is None:
return

Expand All @@ -414,7 +443,7 @@ async def action() -> None:
if not isinstance(user, Member):
return

await user.move_to(None, reason="Disconnected from voice to apply voiceban.")
await user.move_to(None, reason="Disconnected from voice to apply voice mute.")
await user.remove_roles(self._voice_verified_role, reason=reason)

await self.apply_infraction(ctx, infraction, user, action())
Expand Down Expand Up @@ -471,7 +500,7 @@ async def pardon_ban(self, user_id: int, guild: discord.Guild, reason: t.Optiona

return log_text

async def pardon_voice_ban(
async def pardon_voice_mute(
self,
user_id: int,
guild: discord.Guild,
Expand All @@ -487,9 +516,9 @@ async def pardon_voice_ban(
# DM user about infraction expiration
notified = await _utils.notify_pardon(
user=user,
title="Voice ban ended",
content="You have been unbanned and can verify yourself again in the server.",
icon_url=_utils.INFRACTION_ICONS["voice_ban"][1]
title="Voice mute ended",
content="You have been unmuted and can verify yourself again in the server.",
icon_url=_utils.INFRACTION_ICONS["voice_mute"][1]
)
log_text["DM"] = "Sent" if notified else "**Failed**"

Expand All @@ -514,8 +543,8 @@ async def _pardon_action(self, infraction: _utils.Infraction, notify: bool) -> t
return await self.pardon_mute(user_id, guild, reason, notify=notify)
elif infraction["type"] == "ban":
return await self.pardon_ban(user_id, guild, reason)
elif infraction["type"] == "voice_ban":
return await self.pardon_voice_ban(user_id, guild, notify=notify)
elif infraction["type"] == "voice_mute":
return await self.pardon_voice_mute(user_id, guild, notify=notify)

# endregion

Expand Down
4 changes: 2 additions & 2 deletions bot/exts/moderation/voice_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

MESSAGE_FIELD_MAP = {
"joined_at": f"have been on the server for less than {GateConf.minimum_days_member} days",
"voice_banned": "have an active voice ban infraction",
"voice_muted": "have an active voice mute infraction",
"total_messages": f"have sent less than {GateConf.minimum_messages} messages",
"activity_blocks": f"have been active for fewer than {GateConf.minimum_activity_blocks} ten-minute blocks",
}
Expand Down Expand Up @@ -170,7 +170,7 @@ async def voice_verify(self, ctx: Context, *_) -> None:
ctx.author.joined_at > arrow.utcnow() - timedelta(days=GateConf.minimum_days_member)
),
"total_messages": data["total_messages"] < GateConf.minimum_messages,
"voice_banned": data["voice_banned"],
"voice_muted": data["voice_muted"],
"activity_blocks": data["activity_blocks"] < GateConf.minimum_activity_blocks,
}

Expand Down
Loading