def trydispatch(self, bot, ievent, direct=False):
        """ try to dispatch ievent. """

        # test for ignore
        if shouldignore(ievent.userhost):
            return 0

        # set printto
        if ievent.msg:
            ievent.printto = ievent.nick
        else:
            ievent.printto = ievent.channel

        # see if ievent would dispatch
        # what is rebefore, cmnds of reafter, com is the command object
        # check if redispatcher or commands object needs to be used
        (what, com) = self.dispatchtest(bot, ievent, direct)
        if what:
            if com.allowqueue:
                ievent.txt = ievent.txt.replace(' || ', ' | ')
                if ievent.txt.find(' | ') != -1:
                    if ievent.txt[0] == '!':
                        ievent.txt = ievent.txt[1:]
                    else:
                        self.splitpipe(bot, ievent)
                        return
                elif ievent.txt.find(' && ') != -1:
                    self.multiple(bot, ievent)
                    return
            return self.dispatch(what, com, bot, ievent)
Exemple #2
0
    def trydispatch(self, bot, ievent, direct=False):

        """ try to dispatch ievent. """

        # test for ignore
        if shouldignore(ievent.userhost):
            return 0

        # set printto
        if ievent.msg:
            ievent.printto = ievent.nick
        else:
            ievent.printto = ievent.channel

        # see if ievent would dispatch
        # what is rebefore, cmnds of reafter, com is the command object
        # check if redispatcher or commands object needs to be used
        (what, com) = self.dispatchtest(bot, ievent, direct)
        if what:
            if com.allowqueue:
                ievent.txt = ievent.txt.replace(' || ', ' | ')
                if ievent.txt.find(' | ') != -1:
                    if ievent.txt[0] == '!':
                        ievent.txt = ievent.txt[1:]
                    else:
                        self.splitpipe(bot, ievent)
                        return
                elif ievent.txt.find(' && ') != -1:
                    self.multiple(bot, ievent)
                    return
            return self.dispatch(what, com, bot, ievent)
    def dispatchtest(self, bot, ievent, direct=False):
        """ see if ievent would dispatch. """

        # check for ignore
        if shouldignore(ievent.userhost):
            return (None, None)

        # check for throttle
        if ievent.userhost in bot.throttle:
            return (None, None)

        # set target properly
        if ievent.txt.find(' | ') != -1:
            target = ievent.txt.split(' | ')[0]
        elif ievent.txt.find(' && ') != -1:
            target = ievent.txt.split(' && ')[0]
        else:
            target = ievent.txt
        result = []

        # first check for RE before commands dispatcher
        com = rebefore.getcallback(target)

        if com and not target.startswith('!'):
            com.re = True
            result = [rebefore, com]
        else:

            # try commands
            if ievent.txt.startswith('!'):
                ievent.txt = ievent.txt[1:]

            aliascheck(ievent)
            com = cmnds.getcommand(ievent.txt)

            if com:
                com.re = False
                result = [cmnds, com]
                ievent.txt = ievent.txt.strip()
            else:

                # try RE after commands
                com = reafter.getcallback(target)
                if com:
                    com.re = True
                    result = [reafter, com]
        if result:

            # check for auto registration
            if config['auto_register'] and not users.getname(ievent.userhost):
                users.add("%s!%s" % (ievent.nick, ievent.userhost) , \
[ievent.userhost, ], ['USER', ])

            # check for anon access
            if config['anon_enable'] and not 'OPER' in result[1].perms:
                return result

            # check if command is allowed (all-add command)
            if com.name in bot.state['allowed'] or getname(
                    com.func) in bot.state['allowed']:
                return result

            # check for channel permissions
            try:
                chanperms = bot.channels[ievent.channel.lower()]['perms']
                for i in result[1].perms:
                    if i in chanperms and not ievent.msg:
                        ievent.speed = 1
                        return result
            except (KeyError, TypeError):
                pass

            # if direct is set dont check the user database
            if direct:
                return result

            # use event.stripped in case of jabber
            if bot.jabber and ievent.jabber:
                if not ievent.groupchat or ievent.jidchange:
                    if users.allowed(ievent.stripped, result[1].perms):
                        return result

            # irc users check
            if users.allowed(ievent.userhost, result[1].perms):
                return result

        return (None, None)
Exemple #4
0
    def dispatchtest(self, bot, ievent, direct=False):

        """ see if ievent would dispatch. """

        # check for ignore
        if shouldignore(ievent.userhost):
            return (None, None)

        # check for throttle
        if ievent.userhost in bot.throttle:
            return (None, None)

        # set target properly
        if ievent.txt.find(' | ') != -1:
            target = ievent.txt.split(' | ')[0]
        elif ievent.txt.find(' && ') != -1:
            target = ievent.txt.split(' && ')[0]
        else:
            target = ievent.txt
        result = []

        # first check for RE before commands dispatcher
        com = rebefore.getcallback(target)

        if com and not target.startswith('!'):
            com.re = True
            result = [rebefore, com]
        else:

            # try commands 
            if ievent.txt.startswith('!'):
                ievent.txt = ievent.txt[1:]

            aliascheck(ievent)
            com = cmnds.getcommand(ievent.txt)

            if com:
                com.re = False
                result = [cmnds, com]
                ievent.txt = ievent.txt.strip()
            else:

                # try RE after commands
                com = reafter.getcallback(target)
                if com:
                    com.re = True
                    result = [reafter, com]
        if result:

            # check for auto registration
            if config['auto_register'] and not users.getname(ievent.userhost):
                users.add("%s!%s" % (ievent.nick, ievent.userhost) , \
[ievent.userhost, ], ['USER', ])

            # check for anon access
            if config['anon_enable'] and not 'OPER' in result[1].perms:
                return result

            # check if command is allowed (all-add command)
            if com.name in bot.state['allowed'] or getname(com.func) in bot.state['allowed']:
                return result

            # check for channel permissions
            try:
                chanperms = bot.channels[ievent.channel.lower()]['perms']
                for i in result[1].perms:
                    if i in chanperms and not ievent.msg:
                        ievent.speed = 1
                        return result
            except (KeyError, TypeError):
                pass

            # if direct is set dont check the user database
            if direct:
                return result

            # use event.stripped in case of jabber 
            if bot.jabber and ievent.jabber:
                if not ievent.groupchat or ievent.jidchange:
                    if users.allowed(ievent.stripped, result[1].perms):
                        return result

            # irc users check
            if users.allowed(ievent.userhost, result[1].perms):
                return result

        return (None, None)