1
0
Fork 0
mirror of synced 2024-06-26 10:10:44 +12:00

Corrected custom_permissions checking

This commit is contained in:
phxntxm 2016-10-05 13:43:49 -05:00
parent 1012fa7e72
commit 307bc575c4

View file

@ -16,17 +16,24 @@ def custom_perms(**perms):
if ctx.message.channel.is_private:
return False
# Get the member permissions so that we can compare
member_perms = ctx.message.author.permissions_in(ctx.message.channel)
default_perms = discord.Permissions.none()
# 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()
for perm, setting in perms.items():
setattr(default_perms, perm, setting)
setattr(required_perm, perm, setting)
try:
perm_values = config.cache.get('custom_permissions').values
required_perm_value = perm_values[ctx.message.server.id][ctx.command.qualified_name]
required_perm = discord.Permissions(required_perm_value)
except (KeyError, TypeError):
required_perm = default_perms
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