From 5b670c074f797ab45212d2c8aa4d37e936bec9ec Mon Sep 17 00:00:00 2001 From: Andy <76832778+Andeeeee@users.noreply.github.com> Date: Mon, 15 Feb 2021 13:25:03 -0800 Subject: [PATCH] Update `[p]economyset slottime&paydaytime` to use `TimedeltaConverter` and not accept negative integers (#4807) * add a time converter, as well as not allowing negative integers * timedeltaconverter * styling and unused imports * update docstrings * update param name to "duration" instead of seconds * make timedelta default_unit seconds * better descriptions & docstrings * docs for updated paydaytime & slottime * Fix style * Few minor fixes * Cast `total_seconds()` return type to `int` * Fix one of my own issues * Make the duration argument catch-rest for convenience * One more fix for the docs Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> --- docs/cog_guides/economy.rst | 16 ++++++++++------ redbot/cogs/economy/economy.py | 23 +++++++++++++++++------ 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/docs/cog_guides/economy.rst b/docs/cog_guides/economy.rst index fd20f7398..0a173ffb1 100644 --- a/docs/cog_guides/economy.rst +++ b/docs/cog_guides/economy.rst @@ -302,18 +302,20 @@ economyset paydaytime .. code-block:: none - [p]economyset paydaytime + [p]economyset paydaytime **Description** Set the cooldown for the payday command. -Example: +Examples: - ``[p]economyset paydaytime 86400`` + - ``[p]economyset paydaytime 1d`` **Arguments** -- ```` The new number of seconds to wait in between uses of payday. Default is 300. +- | ```` The new duration to wait in between uses of payday. Default is 5 minutes. + | Accepts: seconds, minutes, hours, days, weeks (if no unit is specified, the duration is assumed to be given in seconds) .. _economy-command-economyset-registeramount: @@ -436,18 +438,20 @@ economyset slottime .. code-block:: none - [p]economyset slottime + [p]economyset slottime **Description** Set the cooldown for the slot machine. -Example: +Examples: - ``[p]economyset slottime 10`` + - ``[p]economyset slottime 10m`` **Arguments** -- ```` The new number of seconds to wait in between uses of the slot machine. Default is 5. +- | ```` The new duration to wait in between uses of the slot machine. Default is 5 seconds. + | Accepts: seconds, minutes, hours, days, weeks (if no unit is specified, the duration is assumed to be given in seconds) .. _economy-command-leaderboard: diff --git a/redbot/cogs/economy/economy.py b/redbot/cogs/economy/economy.py index fcb4d53e5..81d8a36e3 100644 --- a/redbot/cogs/economy/economy.py +++ b/redbot/cogs/economy/economy.py @@ -11,6 +11,7 @@ import discord from redbot.cogs.bank import is_owner_if_bank_global from redbot.cogs.mod.converters import RawUserIds from redbot.core import Config, bank, commands, errors, checks +from redbot.core.commands.converter import TimedeltaConverter from redbot.core.bot import Red from redbot.core.i18n import Translator, cog_i18n from redbot.core.utils import AsyncIter @@ -904,16 +905,21 @@ class Economy(commands.Cog): ) @economyset.command() - async def slottime(self, ctx: commands.Context, seconds: int): + async def slottime( + self, ctx: commands.Context, *, duration: TimedeltaConverter(default_unit="seconds") + ): """Set the cooldown for the slot machine. - Example: + Examples: - `[p]economyset slottime 10` + - `[p]economyset slottime 10m` **Arguments** - - `` The new number of seconds to wait in between uses of the slot machine. Default is 5. + - `` The new duration to wait in between uses of the slot machine. Default is 5 seconds. + Accepts: seconds, minutes, hours, days, weeks (if no unit is specified, the duration is assumed to be given in seconds) """ + seconds = int(duration.total_seconds()) guild = ctx.guild if await bank.is_global(): await self.config.SLOT_TIME.set(seconds) @@ -922,16 +928,21 @@ class Economy(commands.Cog): await ctx.send(_("Cooldown is now {num} seconds.").format(num=seconds)) @economyset.command() - async def paydaytime(self, ctx: commands.Context, seconds: int): + async def paydaytime( + self, ctx: commands.Context, *, duration: TimedeltaConverter(default_unit="seconds") + ): """Set the cooldown for the payday command. - Example: + Examples: - `[p]economyset paydaytime 86400` + - `[p]economyset paydaytime 1d` **Arguments** - - `` The new number of seconds to wait in between uses of payday. Default is 300. + - `` The new duration to wait in between uses of payday. Default is 5 minutes. + Accepts: seconds, minutes, hours, days, weeks (if no unit is specified, the duration is assumed to be given in seconds) """ + seconds = int(duration.total_seconds()) guild = ctx.guild if await bank.is_global(): await self.config.PAYDAY_TIME.set(seconds)