def admin_or_permissions(**perms): async def predicate(ctx): override = await check_overrides(ctx, level="admin") return (override if override is not None else await check_permissions( ctx, perms) or await is_admin_or_superior(ctx)) return commands.check(predicate)
def is_owner(**kwargs): async def check(ctx): override = await check_overrides(ctx, level="owner") return override if override is not None else await ctx.bot.is_owner( ctx.author, **kwargs) return commands.check(check)
def mod_or_voice_permissions(**perms): async def pred(ctx: commands.Context): author = ctx.author guild = ctx.guild if await ctx.bot.is_owner(author) or guild.owner == author: # Author is bot owner or guild owner return True admin_role = discord.utils.get(guild.roles, id=await ctx.bot.db.guild(guild).admin_role()) mod_role = discord.utils.get(guild.roles, id=await ctx.bot.db.guild(guild).mod_role()) if admin_role in author.roles or mod_role in author.roles: return True for vc in guild.voice_channels: resolved = vc.permissions_for(author) good = resolved.administrator or all( getattr(resolved, name, None) == value for name, value in perms.items()) if not good: return False else: return True return commands.check(pred)
def guild_only_check(): async def pred(ctx: commands.Context): if await bank.is_global(): return True elif not await bank.is_global() and ctx.guild is not None: return True else: return False return commands.check(pred)
def guildowner_or_permissions(**perms): async def predicate(ctx): has_perms_or_is_owner = await check_permissions(ctx, perms) if ctx.guild is None: return has_perms_or_is_owner is_guild_owner = ctx.author == ctx.guild.owner override = await check_overrides(ctx, level="guildowner") return override if override is not None else is_guild_owner or has_perms_or_is_owner return commands.check(predicate)
def bot_has_voice_permissions(**perms): async def pred(ctx: commands.Context): guild = ctx.guild for vc in guild.voice_channels: resolved = vc.permissions_for(guild.me) good = resolved.administrator or all( getattr(resolved, name, None) == value for name, value in perms.items()) if not good: return False else: return True return commands.check(pred)
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): author = ctx.author if not await bank.is_global(): if not isinstance(ctx.channel, discord.abc.GuildChannel): return False if await ctx.bot.is_owner(author): return True permissions = ctx.channel.permissions_for(author) return author == ctx.guild.owner or permissions.administrator else: return await ctx.bot.is_owner(author) 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): author = ctx.author if not await bank.is_global(): if not isinstance(ctx.channel, discord.abc.GuildChannel): return False if await ctx.bot.is_owner(author): return True 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 else: return await ctx.bot.is_owner(author) return commands.check(pred)
def bot_in_a_guild(**kwargs): async def predicate(ctx): return len(ctx.bot.guilds) > 0 return commands.check(predicate)