From d01bca23141073489d43f6945af55db5aaa37608 Mon Sep 17 00:00:00 2001 From: Jamie <31554168+flaree@users.noreply.github.com> Date: Wed, 23 Dec 2020 19:25:32 +0000 Subject: [PATCH] Owners can bypass cooldowns with non persistent toggle (#4440) * dev bypas cooldowns * Toggleable within dev, new attrib * Reuqested changes * Remake content * Looks like `reset_cooldown()` is under Command object :) * Remove `await` Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com> --- redbot/core/bot.py | 1 + redbot/core/dev_commands.py | 15 +++++++++++++++ redbot/core/events.py | 5 +++++ 3 files changed, 21 insertions(+) diff --git a/redbot/core/bot.py b/redbot/core/bot.py index 866d5c30e..67f6e2d57 100644 --- a/redbot/core/bot.py +++ b/redbot/core/bot.py @@ -162,6 +162,7 @@ class RedBase( self._ignored_cache = IgnoreManager(self._config) self._whiteblacklist_cache = WhitelistBlacklistManager(self._config) self._i18n_cache = I18nManager(self._config) + self._bypass_cooldowns = False async def prefix_manager(bot, message) -> List[str]: prefixes = await self._prefix_cache.get_prefixes(message.guild) diff --git a/redbot/core/dev_commands.py b/redbot/core/dev_commands.py index a6647a0e9..06ae6ceba 100644 --- a/redbot/core/dev_commands.py +++ b/redbot/core/dev_commands.py @@ -369,3 +369,18 @@ class Dev(commands.Cog): await asyncio.sleep(2) ctx.message.author = old_author ctx.message.content = old_content + + @commands.command() + @checks.is_owner() + async def bypasscooldowns(self, ctx, toggle: Optional[bool] = None): + """Give bot owners the ability to bypass cooldowns. + + Does not persist through restarts.""" + if toggle is None: + toggle = not ctx.bot._bypass_cooldowns + ctx.bot._bypass_cooldowns = toggle + + if toggle: + await ctx.send(_("Bot owners will now bypass all commands with cooldowns.")) + else: + await ctx.send(_("Bot owners will no longer bypass all commands with cooldowns.")) diff --git a/redbot/core/events.py b/redbot/core/events.py index 8838b43dc..a465f48c4 100644 --- a/redbot/core/events.py +++ b/redbot/core/events.py @@ -292,6 +292,11 @@ def init_events(bot, cli_flags): elif isinstance(error, commands.CheckFailure): pass elif isinstance(error, commands.CommandOnCooldown): + if bot._bypass_cooldowns and ctx.author.id in bot.owner_ids: + ctx.command.reset_cooldown(ctx) + new_ctx = await bot.get_context(ctx.message) + await bot.invoke(new_ctx) + return if delay := humanize_timedelta(seconds=error.retry_after): msg = _("This command is on cooldown. Try again in {delay}.").format(delay=delay) else: