mirror of
https://gitlab.com/ddorn/tfjm-discord-bot.git
synced 2025-12-14 20:45:15 +01:00
✨ send_and_bin utility
This commit is contained in:
26
src/utils.py
26
src/utils.py
@@ -1,12 +1,7 @@
|
||||
import asyncio
|
||||
from typing import Sequence
|
||||
from functools import wraps
|
||||
|
||||
import psutil
|
||||
from discord import Message, Member, User, Reaction
|
||||
from discord.ext.commands import Context, Bot
|
||||
from discord.utils import get
|
||||
|
||||
from src.constants import Emoji
|
||||
from discord.ext.commands import Bot
|
||||
|
||||
|
||||
def has_role(member, role: str):
|
||||
@@ -15,6 +10,23 @@ def has_role(member, role: str):
|
||||
return any(r.name == role for r in member.roles)
|
||||
|
||||
|
||||
def send_and_bin(f):
|
||||
"""
|
||||
Decorator that allows a command in a cog to just return
|
||||
the messages that needs to be sent, and allow the author that
|
||||
trigger the message de delete it.
|
||||
"""
|
||||
|
||||
@wraps(f)
|
||||
async def wrapped(cog, ctx, *args, **kwargs):
|
||||
msg = await f(cog, ctx, *args, **kwargs)
|
||||
if msg:
|
||||
msg = await ctx.send(msg)
|
||||
await cog.bot.wait_for_bin(ctx.author, msg)
|
||||
|
||||
return wrapped
|
||||
|
||||
|
||||
def start_time(self):
|
||||
return psutil.Process().create_time()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user