From 002e9aa4fb2770635cc6a22b2f681a66d481ca39 Mon Sep 17 00:00:00 2001 From: NovialRiptide <35881688+NovialRiptide@users.noreply.github.com> Date: Mon, 18 Apr 2022 19:26:59 -0400 Subject: Added an option to use 0s as an argument --- bot/exts/moderation/slowmode.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bot/exts/moderation/slowmode.py b/bot/exts/moderation/slowmode.py index b6a771441..595026837 100644 --- a/bot/exts/moderation/slowmode.py +++ b/bot/exts/moderation/slowmode.py @@ -2,7 +2,7 @@ from typing import Optional from dateutil.relativedelta import relativedelta from discord import TextChannel -from discord.ext.commands import Cog, Context, group, has_any_role +from discord.ext.commands import Cog, Context, group, has_any_role, BadArgument from bot.bot import Bot from bot.constants import Channels, Emojis, MODERATION_ROLES @@ -44,7 +44,7 @@ class Slowmode(Cog): await ctx.send(f'The slowmode delay for {channel.mention} is {humanized_delay}.') @slowmode_group.command(name='set', aliases=['s']) - async def set_slowmode(self, ctx: Context, channel: Optional[TextChannel], delay: DurationDelta) -> None: + async def set_slowmode(self, ctx: Context, channel: Optional[TextChannel], delay: str) -> None: """Set the slowmode delay for a text channel.""" # Use the channel this command was invoked in if one was not given if channel is None: @@ -52,8 +52,13 @@ class Slowmode(Cog): # Convert `dateutil.relativedelta.relativedelta` to `datetime.timedelta` # Must do this to get the delta in a particular unit of time - slowmode_delay = time.relativedelta_to_timedelta(delay).total_seconds() + try: + delay = await DurationDelta().convert(ctx, delay) + + except BadArgument: + delay = relativedelta(seconds=0) + slowmode_delay = time.relativedelta_to_timedelta(delay).total_seconds() humanized_delay = time.humanize_delta(delay) # Ensure the delay is within discord's limits -- cgit v1.2.3 From 67479c56d10806714b39720561aa0ad4a1afd62f Mon Sep 17 00:00:00 2001 From: NovialRiptide <35881688+NovialRiptide@users.noreply.github.com> Date: Mon, 18 Apr 2022 20:16:03 -0400 Subject: Rewrote set_slowmode() changes --- bot/exts/moderation/slowmode.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/bot/exts/moderation/slowmode.py b/bot/exts/moderation/slowmode.py index 595026837..5ac806c4a 100644 --- a/bot/exts/moderation/slowmode.py +++ b/bot/exts/moderation/slowmode.py @@ -1,4 +1,4 @@ -from typing import Optional +from typing import Literal, Optional, Union from dateutil.relativedelta import relativedelta from discord import TextChannel @@ -6,7 +6,7 @@ from discord.ext.commands import Cog, Context, group, has_any_role, BadArgument from bot.bot import Bot from bot.constants import Channels, Emojis, MODERATION_ROLES -from bot.converters import DurationDelta +from bot.converters import Duration, DurationDelta from bot.log import get_logger from bot.utils import time @@ -44,7 +44,7 @@ class Slowmode(Cog): await ctx.send(f'The slowmode delay for {channel.mention} is {humanized_delay}.') @slowmode_group.command(name='set', aliases=['s']) - async def set_slowmode(self, ctx: Context, channel: Optional[TextChannel], delay: str) -> None: + async def set_slowmode(self, ctx: Context, channel: Optional[TextChannel], delay: Union[DurationDelta, Literal["0s"], Literal["0seconds"]]) -> None: """Set the slowmode delay for a text channel.""" # Use the channel this command was invoked in if one was not given if channel is None: @@ -52,10 +52,8 @@ class Slowmode(Cog): # Convert `dateutil.relativedelta.relativedelta` to `datetime.timedelta` # Must do this to get the delta in a particular unit of time - try: - delay = await DurationDelta().convert(ctx, delay) - - except BadArgument: + log.info(delay) + if isinstance(delay, str): delay = relativedelta(seconds=0) slowmode_delay = time.relativedelta_to_timedelta(delay).total_seconds() -- cgit v1.2.3 From abc767485c42efe79df78985444546c49755be44 Mon Sep 17 00:00:00 2001 From: NovialRiptide <35881688+NovialRiptide@users.noreply.github.com> Date: Mon, 18 Apr 2022 20:25:34 -0400 Subject: Linting Co-Authored-By: ChrisJL --- bot/exts/moderation/slowmode.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bot/exts/moderation/slowmode.py b/bot/exts/moderation/slowmode.py index 5ac806c4a..9b4903318 100644 --- a/bot/exts/moderation/slowmode.py +++ b/bot/exts/moderation/slowmode.py @@ -2,11 +2,11 @@ from typing import Literal, Optional, Union from dateutil.relativedelta import relativedelta from discord import TextChannel -from discord.ext.commands import Cog, Context, group, has_any_role, BadArgument +from discord.ext.commands import Cog, Context, group, has_any_role from bot.bot import Bot from bot.constants import Channels, Emojis, MODERATION_ROLES -from bot.converters import Duration, DurationDelta +from bot.converters import DurationDelta from bot.log import get_logger from bot.utils import time @@ -44,7 +44,12 @@ class Slowmode(Cog): await ctx.send(f'The slowmode delay for {channel.mention} is {humanized_delay}.') @slowmode_group.command(name='set', aliases=['s']) - async def set_slowmode(self, ctx: Context, channel: Optional[TextChannel], delay: Union[DurationDelta, Literal["0s"], Literal["0seconds"]]) -> None: + async def set_slowmode( + self, + ctx: Context, + channel: Optional[TextChannel], + delay: Union[DurationDelta, Literal["0s", "0seconds"]], + ) -> None: """Set the slowmode delay for a text channel.""" # Use the channel this command was invoked in if one was not given if channel is None: @@ -52,7 +57,6 @@ class Slowmode(Cog): # Convert `dateutil.relativedelta.relativedelta` to `datetime.timedelta` # Must do this to get the delta in a particular unit of time - log.info(delay) if isinstance(delay, str): delay = relativedelta(seconds=0) -- cgit v1.2.3