diff options
| author | 2021-09-05 19:46:37 +0100 | |
|---|---|---|
| committer | 2021-09-05 19:46:37 +0100 | |
| commit | 8a410f3abd39a1b48c514d32651a50d4bdced492 (patch) | |
| tree | 17fbb917adec0a1283d3d2456d8b09eee0334371 /bot/exts/evergreen/timed.py | |
| parent | Merge pull request #845 from python-discord/Pin-platform-in-Dockerfile (diff) | |
| parent | Merge branch 'main' into lance-restructure (diff) | |
Merge pull request #851 from python-discord/lance-restructure
Restructure Sir Lancebot
Diffstat (limited to 'bot/exts/evergreen/timed.py')
| -rw-r--r-- | bot/exts/evergreen/timed.py | 48 |
1 files changed, 0 insertions, 48 deletions
diff --git a/bot/exts/evergreen/timed.py b/bot/exts/evergreen/timed.py deleted file mode 100644 index 2ea6b419..00000000 --- a/bot/exts/evergreen/timed.py +++ /dev/null @@ -1,48 +0,0 @@ -from copy import copy -from time import perf_counter - -from discord import Message -from discord.ext import commands - -from bot.bot import Bot - - -class TimedCommands(commands.Cog): - """Time the command execution of a command.""" - - @staticmethod - async def create_execution_context(ctx: commands.Context, command: str) -> commands.Context: - """Get a new execution context for a command.""" - msg: Message = copy(ctx.message) - msg.content = f"{ctx.prefix}{command}" - - return await ctx.bot.get_context(msg) - - @commands.command(name="timed", aliases=("time", "t")) - async def timed(self, ctx: commands.Context, *, command: str) -> None: - """Time the command execution of a command.""" - new_ctx = await self.create_execution_context(ctx, command) - - ctx.subcontext = new_ctx - - if not ctx.subcontext.command: - help_command = f"{ctx.prefix}help" - error = f"The command you are trying to time doesn't exist. Use `{help_command}` for a list of commands." - - await ctx.send(error) - return - - if new_ctx.command.qualified_name == "timed": - await ctx.send("You are not allowed to time the execution of the `timed` command.") - return - - t_start = perf_counter() - await new_ctx.command.invoke(new_ctx) - t_end = perf_counter() - - await ctx.send(f"Command execution for `{new_ctx.command}` finished in {(t_end - t_start):.4f} seconds.") - - -def setup(bot: Bot) -> None: - """Load the Timed cog.""" - bot.add_cog(TimedCommands()) |