1
0
Fork 0
mirror of synced 2024-06-26 18:21:15 +12:00
Bonfire/cogs/utils/checks.py

49 lines
1.6 KiB
Python
Raw Normal View History

import asyncio
2016-07-09 13:27:19 +12:00
from discord.ext import commands
import discord
2016-07-09 13:27:19 +12:00
from . import config
loop = asyncio.get_event_loop()
2016-07-09 13:27:19 +12:00
def is_owner(ctx):
return ctx.message.author.id in config.owner_ids
2016-07-09 13:27:19 +12:00
def custom_perms(**perms):
def predicate(ctx):
# Return true if this is a private channel, we'll handle that in the registering of the command
if ctx.message.channel.is_private:
return True
2016-07-31 12:20:55 +12:00
2016-10-06 07:43:49 +13:00
# Get the member permissions so that we can compare
member_perms = ctx.message.author.permissions_in(ctx.message.channel)
2016-10-06 07:43:49 +13:00
# Next, set the default permissions if one is not used, based on what was passed
# This will be overriden later, if we have custom permissions
required_perm = discord.Permissions.none()
2016-07-31 12:20:55 +12:00
for perm, setting in perms.items():
2016-10-06 07:43:49 +13:00
setattr(required_perm, perm, setting)
perm_values = config.cache.get('custom_permissions').values
# Loop through and find this server's entry for custom permissions
# Find the command we're using, if it exists, then overwrite
# The required permissions, based on the value saved
for x in perm_values:
if x['server_id'] == ctx.message.server.id and x.get(ctx.command.qualified_name):
required_perm = discord.Permissions(x[ctx.command.qualified_name])
# Now just check if the person running the command has these permissions
return member_perms >= required_perm
predicate.perms = perms
return commands.check(predicate)
def is_pm():
2016-07-09 13:27:19 +12:00
def predicate(ctx):
return ctx.message.channel.is_private
return commands.check(predicate)