diff options
| author | 2019-01-18 23:01:53 +0100 | |
|---|---|---|
| committer | 2019-01-18 23:01:53 +0100 | |
| commit | 42a5892d622cc178b488b3f66573667584e766ce (patch) | |
| tree | bf5e7757493d1ea777e2d41ede4595a7523aefe4 | |
| parent | Adding redirection constants to contants.py and config-default.yml (diff) | |
Adding log.trace messages to decorator
| -rw-r--r-- | bot/decorators.py | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/bot/decorators.py b/bot/decorators.py index 6654aa664..ce54f28cd 100644 --- a/bot/decorators.py +++ b/bot/decorators.py @@ -9,7 +9,7 @@ from discord import Colour, Embed from discord.ext import commands from discord.ext.commands import CheckFailure, Context -from bot.constants import ERROR_REPLIES +from bot.constants import ERROR_REPLIES, RedirectOutput from bot.utils.checks import with_role_check, without_role_check log = logging.getLogger(__name__) @@ -102,19 +102,27 @@ def locked(): return wrap -def redirect_output(channel: int, bypass_roles: typing.Container[int] = None): +def redirect_output(destination_channel: int, bypass_roles: typing.Container[int] = None): + """ + Changes the channel in the context of the command to redirect the output + to a certain channel, unless the author has a role to bypass redirection + """ + def wrap(func): @wraps(func) async def inner(self, ctx, *args, **kwargs): - if ctx.channel.id == channel: + if ctx.channel.id == destination_channel: + log.trace(f"Command {ctx.command.name} was invoked in destination_channel, not redirecting") return await func(self, ctx, *args, **kwargs) if bypass_roles and any(role.id in bypass_roles for role in ctx.author.roles): + log.trace(f"{ctx.author} has role to bypass output redirection") return await func(self, ctx, *args, **kwargs) - redirect_channel = ctx.guild.get_channel(channel) + redirect_channel = ctx.guild.get_channel(destination_channel) old_channel = ctx.channel + log.trace(f"Redirecting output of {ctx.author}'s command '{ctx.command.name}'' to {redirect_channel.name}") ctx.channel = redirect_channel await ctx.channel.send(f"Here's the output of your command, {ctx.author.mention}") await func(self, ctx, *args, **kwargs) @@ -124,8 +132,9 @@ def redirect_output(channel: int, bypass_roles: typing.Container[int] = None): f"{redirect_channel.mention}" ) - await sleep(15) - await message.delete() - await ctx.message.delete() + if RedirectOutput.delete_invocation: + await sleep(RedirectOutput.delete_delay) + await message.delete() + await ctx.message.delete() return inner return wrap |