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>
This commit is contained in:
Andy 2021-02-15 13:25:03 -08:00 committed by GitHub
parent 1a9ce2040a
commit 5b670c074f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 12 deletions

View File

@ -302,18 +302,20 @@ economyset paydaytime
.. code-block:: none .. code-block:: none
[p]economyset paydaytime <seconds> [p]economyset paydaytime <duration>
**Description** **Description**
Set the cooldown for the payday command. Set the cooldown for the payday command.
Example: Examples:
- ``[p]economyset paydaytime 86400`` - ``[p]economyset paydaytime 86400``
- ``[p]economyset paydaytime 1d``
**Arguments** **Arguments**
- ``<seconds>`` The new number of seconds to wait in between uses of payday. Default is 300. - | ``<duration>`` 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: .. _economy-command-economyset-registeramount:
@ -436,18 +438,20 @@ economyset slottime
.. code-block:: none .. code-block:: none
[p]economyset slottime <seconds> [p]economyset slottime <duration>
**Description** **Description**
Set the cooldown for the slot machine. Set the cooldown for the slot machine.
Example: Examples:
- ``[p]economyset slottime 10`` - ``[p]economyset slottime 10``
- ``[p]economyset slottime 10m``
**Arguments** **Arguments**
- ``<seconds>`` The new number of seconds to wait in between uses of the slot machine. Default is 5. - | ``<duration>`` 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: .. _economy-command-leaderboard:

View File

@ -11,6 +11,7 @@ import discord
from redbot.cogs.bank import is_owner_if_bank_global from redbot.cogs.bank import is_owner_if_bank_global
from redbot.cogs.mod.converters import RawUserIds from redbot.cogs.mod.converters import RawUserIds
from redbot.core import Config, bank, commands, errors, checks 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.bot import Red
from redbot.core.i18n import Translator, cog_i18n from redbot.core.i18n import Translator, cog_i18n
from redbot.core.utils import AsyncIter from redbot.core.utils import AsyncIter
@ -904,16 +905,21 @@ class Economy(commands.Cog):
) )
@economyset.command() @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. """Set the cooldown for the slot machine.
Example: Examples:
- `[p]economyset slottime 10` - `[p]economyset slottime 10`
- `[p]economyset slottime 10m`
**Arguments** **Arguments**
- `<seconds>` The new number of seconds to wait in between uses of the slot machine. Default is 5. - `<duration>` 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 guild = ctx.guild
if await bank.is_global(): if await bank.is_global():
await self.config.SLOT_TIME.set(seconds) 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)) await ctx.send(_("Cooldown is now {num} seconds.").format(num=seconds))
@economyset.command() @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. """Set the cooldown for the payday command.
Example: Examples:
- `[p]economyset paydaytime 86400` - `[p]economyset paydaytime 86400`
- `[p]economyset paydaytime 1d`
**Arguments** **Arguments**
- `<seconds>` The new number of seconds to wait in between uses of payday. Default is 300. - `<duration>` 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 guild = ctx.guild
if await bank.is_global(): if await bank.is_global():
await self.config.PAYDAY_TIME.set(seconds) await self.config.PAYDAY_TIME.set(seconds)