Esempio n. 1
0
    def handle(self, *args, **kwargs):
        """ fire monitor callbacks. """

        for i in self.outs:

            # check if precondition is met
            try:
                if i[2]:
                    stats.up('monitors', thr.getname(str(i[2])))
                    rlog(-10, 'jabbermonitor',
                         'checking inloop %s' % str(i[2]))
                    doit = i[2](*args, **kwargs)
                else:
                    doit = 1
            except Exception, ex:
                handle_exception()
                doit = 0

            if doit:
                # run monitor callback in its own thread
                rlog(0, 'jabbermonitor', 'excecuting jabbermonitor callback \
%s' % i[0])
                stats.up('monitors', thr.getname(str(i[1])))
                if not i[3]:
                    cbrunners[5].put("monitor-%s" % i[0], i[1], *args)
                else:
                    thr.start_new_thread(i[1], args, kwargs)
Esempio n. 2
0
    def handle(self, *args, **kwargs):

        """ fire monitor callbacks. """

        for i in self.outs:

            # check if precondition is met
            try:
                if i[2]:
                    stats.up('monitors', thr.getname(str(i[2])))
                    rlog(-10, 'jabbermonitor', 'checking inloop %s' % str(i[2]))
                    doit = i[2](*args, **kwargs)
                else:
                    doit = 1
            except Exception, ex:
                handle_exception()
                doit = 0

            if doit:
                # run monitor callback in its own thread
                rlog(0, 'jabbermonitor', 'excecuting jabbermonitor callback \
%s' % i[0])
                stats.up('monitors', thr.getname(str(i[1])))
                if not i[3]:
                    cbrunners[5].put("monitor-%s" % i[0], i[1], *args)
                else:
                    thr.start_new_thread(i[1], args, kwargs)
    def __init__(self, index, regex, func, perm, plugname, speed=5, \
threaded=True, allowqueue=True, options={}):
        self.name = thr.getname(func) # name of the callback
        self.index = index # index into the list
        self.regex = regex # the RE to match
        self.compiled = re.compile(regex) # compiled RE
        self.func = func # the function to call if RE matches
        # make sure perms is a list
        if type(perm) == types.ListType:
            self.perms = list(perm)
        else:
            self.perms = [perm, ]
        # plug name
        self.plugname = plugname # plugname where RE callbacks is registered
        self.speed = copy.deepcopy(speed) # speed at which the function runs
        self.threaded = copy.deepcopy(threaded) # set when run threaade
        self.allowqueue = copy.deepcopy(allowqueue) # set when pipeline is allowed
        self.options = dict(options) # options set on the callback
Esempio n. 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)
Esempio n. 5
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)