python类check()的实例源码

checks.py 文件源码 项目:lagbot 作者: mikevb1 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def dm_only():
    return commands.check(lambda ctx: ctx.guild is None)
check.py 文件源码 项目:Socrates 作者: Curlybear 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def is_owner():
    return commands.check(lambda ctx: is_owner_check(ctx.message))
check.py 文件源码 项目:Socrates 作者: Curlybear 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def is_authorized_staff():
    return commands.check(lambda ctx: is_authorized_staff_check(ctx.message))
checks.py 文件源码 项目:Luna 作者: Moonlington 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def is_owner():
    return commands.check(lambda ctx: is_owner_check(ctx.message))
checks.py 文件源码 项目:Luna 作者: Moonlington 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def role_or_permissions(ctx, check, **perms):
    if check_permissions(ctx, perms):
        return True

    ch = ctx.message.channel
    author = ctx.message.author
    if ch.is_private:
        return False  # can't have roles in PMs

    role = discord.utils.find(check, author.roles)
    return role is not None
checks.py 文件源码 项目:Luna 作者: Moonlington 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def mod_or_permissions(**perms):
    def predicate(ctx):
        return role_or_permissions(ctx, lambda r: r.name in ('Luna Mod', 'Luna Admin', 'Bot Commander', 'Master Assassin'), **perms)

    return commands.check(predicate)
checks.py 文件源码 项目:Luna 作者: Moonlington 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def admin_or_permissions(**perms):
    def predicate(ctx):
        return role_or_permissions(ctx, lambda r: r.name in ('Luna Admin', 'Master Assassin'), **perms)
    return commands.check(predicate)

# These two roles are for a specific server, just use 'Luna mod' and 'Luna
# admin'
__main__.py 文件源码 项目:AutomaBot 作者: 73VW 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def bot_main(token, queue, channel, prefix, desc):
    """Run bot."""
    bot = AutomaBot(get=queue, update_channel=channel,
                    command_prefix=prefix,
                    description=desc, self_bot=False)

    @bot.command(pass_context=True)
    @commands.check(is_owner)
    async def sleep(ctx):
        await bot.change_presence(status=discord.Status.dnd, afk=True)
        msg = 'Going to sleep. See you :wave:'
        for comm in bot.commands:
            if comm is not "wakeup":
                bot.commands[comm].enabled = False
        await bot.say(msg)

    @bot.command(pass_context=True, hidden=True)
    @commands.check(is_owner)
    async def wakeup(ctx):
        for comm in bot.commands:
            if comm is not "wakeup":
                bot.commands[comm].enabled = True
        await bot.change_presence(status=discord.Status.online, afk=False)
        msg = 'Goooooooooood morniiing vietnammmmmm :bomb:'
        await bot.say(msg)

    await bot.start(token)
checks.py 文件源码 项目:Inkxbot 作者: InkxtheSquid 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def is_owner():
    return commands.check(lambda ctx: is_owner_check(ctx.message))

# The permission system of the bot is based on a "just works" basis
# You have permissions and the bot has permissions. If you meet the permissions
# required to execute the command (and the bot does as well) then it goes through
# and you can execute the command.
# If these checks fail, then there are two fallbacks.
# A role with the name of Bot Mod and a role with the name of Bot Admin.
# Having these roles provides you access to certain commands without actually having
# the permissions required for them.
# Of course, the owner will always be able to execute commands.
checks.py 文件源码 项目:Inkxbot 作者: InkxtheSquid 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def role_or_permissions(ctx, check, **perms):
    if check_permissions(ctx, perms):
        return True

    ch = ctx.message.channel
    author = ctx.message.author
    if ch.is_private:
        return False # can't have roles in PMs

    role = discord.utils.find(check, author.roles)
    return role is not None
checks.py 文件源码 项目:Inkxbot 作者: InkxtheSquid 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def mod_or_permissions(**perms):
    def predicate(ctx):
        return role_or_permissions(ctx, lambda r: r.name == 'Bot Commander', **perms)
    return commands.check(predicate)
checks.py 文件源码 项目:Inkxbot 作者: InkxtheSquid 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def admin_or_permissions(**perms):
    def predicate(ctx):
        return role_or_permissions(ctx, lambda r: r.name == 'Bot Commander', **perms)
    return commands.check(predicate)
checks.py 文件源码 项目:Inkxbot 作者: InkxtheSquid 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def TO_or_permissions(**perms):
    def predicate(ctx):
        return role_or_permissions(ctx, lambda r: r.name in ('TO_Crew', 'Head TO', 'Staff'), **perms) #these roles are needed if you're a TO
    return commands.check(predicate)
bot.py 文件源码 项目:storcord 作者: memework 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def gay_only():
    return commands.check(lambda m: m.author.id in \
        (162819866682851329, 97104885337575424, 150745989836308480))
checks.py 文件源码 项目:discordbot.py 作者: rauenzi 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def is_owner():
    return commands.check(lambda ctx: is_owner_check(ctx.message))

# The permission system of the bot is based on a "just works" basis
# You have permissions and the bot has permissions. If you meet the permissions
# required to execute the command (and the bot does as well) then it goes through
# and you can execute the command.
# If these checks fail, then there are two fallbacks.
# A role with the name of Bot Mod and a role with the name of Bot Admin.
# Having these roles provides you access to certain commands without actually having
# the permissions required for them.
# Of course, the owner will always be able to execute commands.
checks.py 文件源码 项目:discordbot.py 作者: rauenzi 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def role_or_permissions(ctx, check, **perms):
    if check_permissions(ctx, perms):
        return True

    ch = ctx.message.channel
    author = ctx.message.author
    if ch.is_private:
        return False # can't have roles in PMs

    role = discord.utils.find(check, author.roles)
    return role is not None
checks.py 文件源码 项目:discordbot.py 作者: rauenzi 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def mod_or_permissions(**perms):
    def predicate(ctx):
        return role_or_permissions(ctx, lambda r: r.name in ('Bot Mod', 'Bot Admin'), **perms)

    return commands.check(predicate)
checks.py 文件源码 项目:discordbot.py 作者: rauenzi 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def admin_or_permissions(**perms):
    def predicate(ctx):
        return role_or_permissions(ctx, lambda r: r.name == 'Bot Admin', **perms)

    return commands.check(predicate)
checks.py 文件源码 项目:discordbot.py 作者: rauenzi 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def is_in_servers(*server_ids):
    def predicate(ctx):
        server = ctx.message.server
        if server is None:
            return False
        return server.id in server_ids
    return commands.check(predicate)
checks.py 文件源码 项目:SESTREN 作者: SirThane 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def bot_owner(ctx):
    def check():
        return ctx.author.id == 125435062127820800
    return check()


问题


面经


文章

微信
公众号

扫码关注公众号