53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
from discord.ext import commands
|
|
import discord
|
|
from . import config
|
|
|
|
|
|
def isOwner(ctx):
|
|
return ctx.message.author.id == config.ownerID
|
|
|
|
|
|
def customPermsOrRole(perm):
|
|
def predicate(ctx):
|
|
if ctx.message.channel.is_private:
|
|
return False
|
|
custom_permissions = config.getContent('custom_permissions')
|
|
_perm = None
|
|
try:
|
|
_perm = custom_permissions[ctx.message.server.id][str(ctx.command)]
|
|
except KeyError:
|
|
pass
|
|
|
|
if _perm is None:
|
|
return getattr(ctx.message.author.permissions_in(ctx.message.channel), perm)
|
|
else:
|
|
return getattr(ctx.message.author.permissions_in(ctx.message.channel), _perm)
|
|
|
|
return commands.check(predicate)
|
|
|
|
def customPermsOrRole(**perms):
|
|
def predicate(ctx):
|
|
if ctx.message.channel.is_private:
|
|
return False
|
|
|
|
member_perms = ctx.message.author.permissions_in(ctx.message.channel)
|
|
default_perms = discord.Permissions.none()
|
|
for perm,setting in perms.items():
|
|
setattr(default_perms,perm,setting)
|
|
|
|
try:
|
|
required_perm = config.getContent('custom_permissions')[ctx.message.server.id][ctx.command.qualified_name]
|
|
except KeyError:
|
|
required_perm = default_perms
|
|
return member_perms >= required_perm
|
|
|
|
|
|
return commands.check(predicate)
|
|
|
|
|
|
def isPM():
|
|
def predicate(ctx):
|
|
return ctx.message.channel.is_private
|
|
|
|
return commands.check(predicate)
|