aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar SebastiaanZ <[email protected]>2019-01-18 22:28:55 +0100
committerGravatar SebastiaanZ <[email protected]>2019-01-18 22:28:55 +0100
commitb7bbf20171b19fa1dead4ad4ff235bcab27d6127 (patch)
tree4f186bddf89e633a825f6d8a34b5f80d9f431cb9
parentMerge pull request #283 from python-discord/rmq_fix (diff)
Adding 'redirect_output' decorator to bot/decorators.py
-rw-r--r--bot/decorators.py31
1 files changed, 30 insertions, 1 deletions
diff --git a/bot/decorators.py b/bot/decorators.py
index 710045c10..6654aa664 100644
--- a/bot/decorators.py
+++ b/bot/decorators.py
@@ -1,7 +1,7 @@
import logging
import random
import typing
-from asyncio import Lock
+from asyncio import Lock, sleep
from functools import wraps
from weakref import WeakValueDictionary
@@ -100,3 +100,32 @@ def locked():
return await func(self, ctx, *args, **kwargs)
return inner
return wrap
+
+
+def redirect_output(channel: int, bypass_roles: typing.Container[int] = None):
+ def wrap(func):
+ @wraps(func)
+ async def inner(self, ctx, *args, **kwargs):
+ if ctx.channel.id == channel:
+ return await func(self, ctx, *args, **kwargs)
+
+ if bypass_roles and any(role.id in bypass_roles for role in ctx.author.roles):
+ return await func(self, ctx, *args, **kwargs)
+
+ redirect_channel = ctx.guild.get_channel(channel)
+ old_channel = ctx.channel
+
+ 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)
+
+ message = await old_channel.send(
+ f"Hey, {ctx.author.mention}, you can find the output of your command here: "
+ f"{redirect_channel.mention}"
+ )
+
+ await sleep(15)
+ await message.delete()
+ await ctx.message.delete()
+ return inner
+ return wrap