2017-06-11 20:04:03 +02:00
|
|
|
from discord.ext import commands
|
|
|
|
|
|
|
|
|
2018-12-03 01:26:23 +01:00
|
|
|
def is_owner_check(message):
|
2019-06-27 23:40:25 +02:00
|
|
|
return str(message.author.id) in ['171685542553976832',
|
|
|
|
'269156684155453451']
|
|
|
|
|
2017-06-11 20:04:03 +02:00
|
|
|
|
|
|
|
def is_owner(warn=True):
|
2019-06-27 23:40:25 +02:00
|
|
|
def check(ctx, log):
|
|
|
|
owner = is_owner_check(ctx.message)
|
|
|
|
if not owner and log:
|
|
|
|
print(ctx.message.author.name + " à essayer d'executer " + ctx.message.content + " sur le serveur " + ctx.message.guild.name)
|
|
|
|
return owner
|
|
|
|
|
|
|
|
owner = commands.check(lambda ctx: check(ctx, warn))
|
|
|
|
return owner
|
|
|
|
|
2017-06-11 20:04:03 +02:00
|
|
|
|
2019-06-27 23:40:25 +02:00
|
|
|
"""-------------------------------------------------------------------------"""
|
2017-06-11 20:04:03 +02:00
|
|
|
|
|
|
|
|
2018-12-03 01:26:23 +01:00
|
|
|
async def check_permissions(ctx, perms, *, check=all):
|
2019-06-27 23:40:25 +02:00
|
|
|
is_owner = await ctx.bot.is_owner(ctx.author)
|
|
|
|
if is_owner or is_owner_check(ctx.message) is True:
|
|
|
|
return True
|
|
|
|
|
|
|
|
resolved = ctx.channel.permissions_for(ctx.author)
|
|
|
|
return check(getattr(resolved, name, None) == value for name, value in
|
|
|
|
perms.items())
|
2017-06-11 20:04:03 +02:00
|
|
|
|
|
|
|
|
2018-12-03 01:26:23 +01:00
|
|
|
def has_permissions(*, check=all, **perms):
|
2019-06-27 23:40:25 +02:00
|
|
|
async def pred(ctx):
|
|
|
|
return await check_permissions(ctx, perms, check=check)
|
|
|
|
|
|
|
|
return commands.check(pred)
|
|
|
|
|
2017-06-11 20:04:03 +02:00
|
|
|
|
2018-12-03 01:26:23 +01:00
|
|
|
async def check_guild_permissions(ctx, perms, *, check=all):
|
2019-06-27 23:40:25 +02:00
|
|
|
is_owner = await ctx.bot.is_owner(ctx.author)
|
|
|
|
if is_owner:
|
|
|
|
return True
|
2017-06-11 20:04:03 +02:00
|
|
|
|
2019-06-27 23:40:25 +02:00
|
|
|
if ctx.guild is None:
|
|
|
|
return False
|
|
|
|
|
|
|
|
resolved = ctx.author.guild_permissions
|
|
|
|
return check(getattr(resolved, name, None) == value for name, value in
|
|
|
|
perms.items())
|
2017-06-11 20:04:03 +02:00
|
|
|
|
|
|
|
|
2018-12-03 01:26:23 +01:00
|
|
|
def has_guild_permissions(*, check=all, **perms):
|
2019-06-27 23:40:25 +02:00
|
|
|
async def pred(ctx):
|
|
|
|
return await check_guild_permissions(ctx, perms, check=check)
|
|
|
|
|
|
|
|
return commands.check(pred)
|
|
|
|
|
2017-06-11 20:04:03 +02:00
|
|
|
|
2018-12-03 01:26:23 +01:00
|
|
|
# These do not take channel overrides into account
|
2017-06-11 20:04:03 +02:00
|
|
|
|
2019-06-27 23:40:25 +02:00
|
|
|
|
2018-12-03 01:26:23 +01:00
|
|
|
def is_mod():
|
2019-06-27 23:40:25 +02:00
|
|
|
async def pred(ctx):
|
|
|
|
return await check_guild_permissions(ctx, {'manage_guild': True})
|
|
|
|
|
|
|
|
return commands.check(pred)
|
|
|
|
|
2017-09-30 18:09:02 +02:00
|
|
|
|
2018-12-03 01:26:23 +01:00
|
|
|
def is_admin():
|
2019-06-27 23:40:25 +02:00
|
|
|
async def pred(ctx):
|
|
|
|
return await check_guild_permissions(ctx, {'administrator': True})
|
|
|
|
|
|
|
|
return commands.check(pred)
|
|
|
|
|
2017-09-30 18:09:02 +02:00
|
|
|
|
2018-12-03 01:26:23 +01:00
|
|
|
def mod_or_permissions(**perms):
|
2019-06-27 23:40:25 +02:00
|
|
|
perms['manage_guild'] = True
|
|
|
|
|
|
|
|
async def predicate(ctx):
|
|
|
|
return await check_guild_permissions(ctx, perms, check=any)
|
|
|
|
|
|
|
|
return commands.check(predicate)
|
|
|
|
|
2017-09-30 18:09:02 +02:00
|
|
|
|
2018-12-03 01:26:23 +01:00
|
|
|
def admin_or_permissions(**perms):
|
2019-06-27 23:40:25 +02:00
|
|
|
perms['administrator'] = True
|
|
|
|
|
|
|
|
async def predicate(ctx):
|
|
|
|
return await check_guild_permissions(ctx, perms, check=any)
|
|
|
|
|
|
|
|
return commands.check(predicate)
|
|
|
|
|
2018-12-03 01:26:23 +01:00
|
|
|
|
|
|
|
def is_in_guilds(*guild_ids):
|
2019-06-27 23:40:25 +02:00
|
|
|
def predicate(ctx):
|
|
|
|
guild = ctx.guild
|
|
|
|
if guild is None:
|
|
|
|
return False
|
|
|
|
return guild.id in guild_ids
|
|
|
|
|
|
|
|
return commands.check(predicate)
|
2018-12-03 01:26:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
def get_user(message, user):
|
2019-06-27 23:40:25 +02:00
|
|
|
try:
|
|
|
|
member = message.mentions[0]
|
|
|
|
except:
|
|
|
|
member = message.guild.get_member_named(user)
|
|
|
|
if not member:
|
|
|
|
try:
|
|
|
|
member = message.guild.get_member(int(user))
|
|
|
|
except ValueError:
|
|
|
|
pass
|
|
|
|
if not member:
|
|
|
|
return None
|
|
|
|
return member
|
|
|
|
|
2018-12-03 01:26:23 +01:00
|
|
|
|
|
|
|
def check_date(date: str):
|
2019-06-27 23:40:25 +02:00
|
|
|
if len(date) == 1:
|
|
|
|
return f"0{date}"
|
|
|
|
else:
|
2019-09-08 23:05:43 +02:00
|
|
|
return date
|