tfjm-discord-bot/src/utils.py

41 lines
858 B
Python
Raw Normal View History

2020-04-30 18:11:07 +00:00
from functools import wraps
2020-04-30 15:26:33 +00:00
import psutil
2020-04-30 18:11:07 +00:00
from discord.ext.commands import Bot
2020-04-29 16:43:07 +00:00
def french_join(l):
start = ", ".join(l[:-1])
return f"{start} et {l[-1]}"
2020-04-29 14:27:40 +00:00
def has_role(member, role: str):
"""Return whether the member has a role with this name."""
return any(r.name == role for r in member.roles)
2020-04-29 16:43:07 +00:00
2020-04-30 18:11:07 +00:00
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
2020-05-01 15:08:05 +00:00
def start_time():
return psutil.Process().create_time()
2020-04-30 15:26:33 +00:00
def setup(bot: Bot):
pass