diff options
-rw-r--r-- | bot/exts/moderation/infraction/infractions.py | 43 | ||||
-rw-r--r-- | tests/bot/exts/moderation/infraction/test_infractions.py | 4 |
2 files changed, 34 insertions, 13 deletions
diff --git a/bot/exts/moderation/infraction/infractions.py b/bot/exts/moderation/infraction/infractions.py index 38d1ffc0e..f19323c7c 100644 --- a/bot/exts/moderation/infraction/infractions.py +++ b/bot/exts/moderation/infraction/infractions.py @@ -76,31 +76,52 @@ class Infractions(InfractionScheduler, commands.Cog): await self.apply_kick(ctx, user, reason) @command() - 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) + async def ban( + self, + ctx: Context, + user: FetchedMember, + duration: t.Optional[Expiry] = None, + *, + reason: t.Optional[str] = None + ) -> None: + """ + Permanently ban a user for the given reason and stop watching them with Big Brother. + + If duration is specified, it temporarily bans that user for the given duration. + """ + await self.apply_ban(ctx, user, reason, expires_at=duration) @command(aliases=('pban',)) async def purgeban( self, ctx: Context, user: FetchedMember, - purge_days: t.Optional[int] = 1, + duration: t.Optional[Expiry] = None, *, reason: t.Optional[str] = None ) -> None: """ - Same as ban but removes all their messages for the given number of days, default being 1. + Same as ban but removes all their messages of the last 24 hours. - `purge_days` can only be values between 0 and 7. - Anything outside these bounds are automatically adjusted to their respective limits. + If duration is specified, it temporarily bans that user for the given duration. """ - await self.apply_ban(ctx, user, reason, max(min(purge_days, 7), 0)) + await self.apply_ban(ctx, user, reason, 1, expires_at=duration) @command(aliases=('vban',)) - async def voiceban(self, ctx: Context, user: FetchedMember, *, reason: t.Optional[str]) -> None: - """Permanently ban user from using voice channels.""" - await self.apply_voice_ban(ctx, user, reason) + async def voiceban( + self, + ctx: Context, + user: FetchedMember, + duration: t.Optional[Expiry] = None, + *, + reason: t.Optional[str] + ) -> None: + """ + Permanently ban user from using voice channels. + + If duration is specified, it temporarily voice bans that user for the given duration. + """ + await self.apply_voice_ban(ctx, user, reason, expires_at=duration) # endregion # region: Temporary infractions diff --git a/tests/bot/exts/moderation/infraction/test_infractions.py b/tests/bot/exts/moderation/infraction/test_infractions.py index 08f39cd50..b9d527770 100644 --- a/tests/bot/exts/moderation/infraction/test_infractions.py +++ b/tests/bot/exts/moderation/infraction/test_infractions.py @@ -74,7 +74,7 @@ class VoiceBanTests(unittest.IsolatedAsyncioTestCase): """Should call voice ban applying function without expiry.""" self.cog.apply_voice_ban = AsyncMock() self.assertIsNone(await self.cog.voiceban(self.cog, self.ctx, self.user, reason="foobar")) - self.cog.apply_voice_ban.assert_awaited_once_with(self.ctx, self.user, "foobar") + self.cog.apply_voice_ban.assert_awaited_once_with(self.ctx, self.user, "foobar", expires_at=None) async def test_temporary_voice_ban(self): """Should call voice ban applying function with expiry.""" @@ -184,7 +184,7 @@ class VoiceBanTests(unittest.IsolatedAsyncioTestCase): user = MockUser() await self.cog.voiceban(self.cog, self.ctx, user, reason=None) - post_infraction_mock.assert_called_once_with(self.ctx, user, "voice_ban", None, active=True) + post_infraction_mock.assert_called_once_with(self.ctx, user, "voice_ban", None, active=True, expires_at=None) apply_infraction_mock.assert_called_once_with(self.cog, self.ctx, infraction, user, ANY) # Test action |