[Core V3] Fix checks (#924)

* Fix global checks

* Fix bank's checks

Predicates for decorators return true or false, they don't return other decorators

* Async getters in core checks
This commit is contained in:
Tobotimus
2017-08-16 08:09:57 +10:00
committed by palmtree5
parent 2a19f151fc
commit 115418d323
3 changed files with 41 additions and 17 deletions

View File

@@ -5,20 +5,36 @@ from core.bot import Red # Only used for type hints
def check_global_setting_guildowner():
"""
Command decorator. If the bank is not global, it checks if the author is
either the guildowner or has the administrator permission.
"""
async def pred(ctx: commands.Context):
if await bank.is_global():
return checks.is_owner()
else:
return checks.guildowner_or_permissions(administrator=True)
author = ctx.author
if await ctx.bot.is_owner(author):
return True
if not await bank.is_global():
permissions = ctx.channel.permissions_for(author)
return author == ctx.guild.owner or permissions.administrator
return commands.check(pred)
def check_global_setting_admin():
"""
Command decorator. If the bank is not global, it checks if the author is
either a bot admin or has the manage_guild permission.
"""
async def pred(ctx: commands.Context):
if await bank.is_global():
return checks.is_owner()
else:
return checks.admin_or_permissions(manage_guild=True)
author = ctx.author
if await ctx.bot.is_owner(author):
return True
if not await bank.is_global():
permissions = ctx.channel.permissions_for(author)
is_guild_owner = author == ctx.guild.owner
admin_role = await ctx.bot.db.guild(ctx.guild).admin_role()
return admin_role in author.roles or is_guild_owner or permissions.manage_guild
return commands.check(pred)