util.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:Python-IRC-Bot 作者: wolfy1339 项目源码 文件源码
def call_command(bot, event, irc, arguments):
    command = ' '.join(arguments).split(' ')
    if not command[0].startswith("?"):
        del command[0]
        name = command[0]
    else:
        name = command[0][1:]
    if not name == '' and not name.find("?") != -1:
        privmsg = event.target == bot.config['nickname']
        args = command[1:] if len(command) > 1 else ''

        host = event.source.host
        chan = event.target if not privmsg else False

        try:
            perms = commands[name]['perms']
            min_args = commands[name]['minArgs']

            if check_perms(host, chan, owner=perms[2], admin=perms[1],
                           trusted=perms[0]):
                if len(args) < min_args:
                    irc.reply(event, config.argsMissing)
                else:
                    target = "a private message" if privmsg else event.target
                    source = event.source
                    log.info("%s called %s in %s", source, name, target)
                    commands[name]['func'](bot, event, irc, args)
            else:
                if not event.source.host.find("/bot/"):
                    irc.reply(event, config.noPerms)
        except KeyError:
            irc.notice(event.source.nick, config.invalidCmd.format(name))
        except Exception:
            irc.reply(event, 'Oops, an error occured!')
            print_error(irc, event)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号