예제 #1
0
 def doit(self, bot, event, target, direct=False):
     """ do the dispatching. """
     if not target.enable: return
     if target.modname in event.chan.data.denyplug:
          logging.warn("%s is denied in channel %s - %s" % (target.plugname, event.channel, event.userhost))
          return
     id = event.auth or event.userhost
     event.iscommand = True
     event.how = event.how or target.how or "overwrite"
     aliascheck(event)
     display = "%s/%s/%s" % (target.plugname, bot.cfg.name, event.nick or event.channel)
     logging.warning('dispatching %s (%s)' % (event.usercmnd, display))
     try:
         if direct or event.direct: target.func(bot, event)
         elif (target.threaded or event.threaded) and not event.nothreads:
             logging.warning("DIRECT COMMAND THREAD %s (%s)" % (event.usercmnd, display))
             t = start_bot_command(target.func, (bot, event))
             event.threaded = True
             event.thread = t
         else:
             event.dontclose = False
             cmndrunner.put(target.speed or event.speed, display, target.func, bot, event)
     except Exception, ex:
         logging.error('%s - error executing %s' % (whichmodule(), str(target.func)))
         raise
예제 #2
0
파일: commands.py 프로젝트: Petraea/jsonbot
 def doit(self, bot, event, target, direct=False):
     """ do the dispatching. """
     if not target.enable: return
     if target.modname in event.chan.data.denyplug:
         logging.warn("%s is denied in channel %s - %s" %
                      (target.plugname, event.channel, event.userhost))
         return
     id = event.auth or event.userhost
     event.iscommand = True
     event.how = event.how or target.how or "overwrite"
     aliascheck(event)
     display = "%s/%s/%s" % (target.plugname, bot.cfg.name, event.nick
                             or event.channel)
     logging.warning('dispatching %s (%s)' % (event.usercmnd, display))
     try:
         if direct or event.direct: target.func(bot, event)
         elif (target.threaded or event.threaded) and not event.nothreads:
             logging.warning("DIRECT COMMAND THREAD %s (%s)" %
                             (event.usercmnd, display))
             t = start_bot_command(target.func, (bot, event))
             event.threaded = True
             event.thread = t
         else:
             event.dontclose = False
             cmndrunner.put(target.speed or event.speed, display,
                            target.func, bot, event)
     except Exception, ex:
         logging.error('%s - error executing %s' %
                       (whichmodule(), str(target.func)))
         raise
예제 #3
0
 def doit(self, bot, event, target, direct=False):
     """ do the dispatching. """
     if not target.enable: return
     if target.modname in event.chan.data.denyplug:
          logging.warn("%s is denied in channel %s - %s" % (target.plugname, event.channel, event.userhost))
          return
     id = event.auth or event.userhost
     event.iscommand = True
     event.how = event.how or target.how or "overwrite"
     aliascheck(event)
     logging.warning('dispatching %s (%s)' % (event.usercmnd, bot.cfg.name))
     try:
         if bot.isgae:
             if not event.notask and (target.threaded or event.threaded) and not event.nothreads:
                 logging.warn("LAUNCHING AS TASK")
                 from jsb.drivers.gae.tasks import start_botevent
                 if target.threaded == "backend": start_botevent(bot, event, "backend")
                 else: start_botevent(bot, event, target.speed or event.speed)
                 event.reply("task started for %s" % event.auth)
             else: target.func(bot, event)
         else:
             if direct or event.direct: target.func(bot, event)
             elif target.threaded and not event.nothreads:
                 logging.warning("launching thread for %s (%s)" % (event.usercmnd, bot.cfg.name))
                 t = start_bot_command(target.func, (bot, event))
                 event.thread = t
             else: event.dontclose = False; cmndrunner.put(target.speed or event.speed, target.modname, target.func, bot, event)
     except Exception, ex:
         logging.error('%s - error executing %s' % (whichmodule(), str(target.func)))
         raise
예제 #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)
예제 #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)