mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-21 10:17:59 -05:00
Improve Cooldown UX (#2412)
This improves the feedback given on `command_on_cool_down`, as well as automatically handling cooldowns under 1 second for the user.
This commit is contained in:
committed by
Toby Harradine
parent
7e2e37ab3f
commit
722aaa225b
@@ -4,6 +4,7 @@ import codecs
|
||||
import datetime
|
||||
import logging
|
||||
import traceback
|
||||
import asyncio
|
||||
from datetime import timedelta
|
||||
|
||||
import aiohttp
|
||||
@@ -15,7 +16,7 @@ from pkg_resources import DistributionNotFound
|
||||
from .. import __version__ as red_version, version_info as red_version_info, VersionInfo
|
||||
from . import commands
|
||||
from .data_manager import storage_type
|
||||
from .utils.chat_formatting import inline, bordered, format_perms_list
|
||||
from .utils.chat_formatting import inline, bordered, format_perms_list, humanize_timedelta
|
||||
from .utils import fuzzy_command_search, format_fuzzy_results
|
||||
|
||||
log = logging.getLogger("red")
|
||||
@@ -213,8 +214,22 @@ def init_events(bot, cli_flags):
|
||||
elif isinstance(error, commands.NoPrivateMessage):
|
||||
await ctx.send("That command is not available in DMs.")
|
||||
elif isinstance(error, commands.CommandOnCooldown):
|
||||
if error.retry_after < 1:
|
||||
async with ctx.typing():
|
||||
# the sleep here is so that commands using this for ratelimit purposes
|
||||
# are not made more lenient than intended, while still being
|
||||
# more convienient for the user than redoing it less than a second later.
|
||||
await asyncio.sleep(error.retry_after)
|
||||
await ctx.bot.invoke(ctx)
|
||||
# done this way so checks still occur if there are other
|
||||
# failures possible than just cooldown.
|
||||
# do not change to ctx.reinvoke()
|
||||
return
|
||||
|
||||
await ctx.send(
|
||||
"This command is on cooldown. Try again in {:.2f}s".format(error.retry_after)
|
||||
"This command is on cooldown. Try again in {}.".format(
|
||||
humanize_timedelta(seconds=error.retry_after)
|
||||
)
|
||||
)
|
||||
else:
|
||||
log.exception(type(error).__name__, exc_info=error)
|
||||
|
||||
Reference in New Issue
Block a user