Esempio n. 1
0
    def parse(self, line):
        '''
        Parse a line from the buffer, and decide what type
        of action it represents. 
        '''

        out.verbose("%s" % line)
        #print ":::: parse->",line
        privmatch = re.match(regex.MSG, line)

        if privmatch != None:
            text = privmatch.group(5)
            if text is not unicode:
                try:
                    text = text.encode('utf-8', 'ignore')
                except:
                    pass

            if (privmatch.group(5)[0] == self.cfg.get('module','prefix') \
                    and len(privmatch.group(5)) > 2):
                self.parsecmd(privmatch.group(1), \
                        privmatch.group(2), \
                        privmatch.group(3), \
                        privmatch.group(4), \
                        text[1:])
            else:
                self.parsepriv(privmatch.group(1), \
                        privmatch.group(2), \
                        privmatch.group(3), \
                        privmatch.group(4), \
                        text)
Esempio n. 2
0
    def parse(self, line):
        '''
        Parse a line from the buffer, and decide what type
        of action it represents. 
        '''
        
        out.verbose("%s" % line)
        #print ":::: parse->",line
        privmatch = re.match(regex.MSG, line)

        if privmatch != None:
            text = privmatch.group(5)
            if text is not unicode:
                try:
                    text = text.encode('utf-8', 'ignore')
                except:
                    pass

            if (privmatch.group(5)[0] == self.cfg.get('module','prefix') \
                    and len(privmatch.group(5)) > 2):
                self.parsecmd(privmatch.group(1), \
                        privmatch.group(2), \
                        privmatch.group(3), \
                        privmatch.group(4), \
                        text[1:])
            else:
                self.parsepriv(privmatch.group(1), \
                        privmatch.group(2), \
                        privmatch.group(3), \
                        privmatch.group(4), \
                        text)
Esempio n. 3
0
    def load_cmds(self):
        ''' 
        Method for loading core commands from
        the module/core/cmd/ directory.
        '''
        cmdlist = []
        for m in os.listdir('module/core/cmd'):
            if m[-3:] == '.py' and not m == '__init__.py':
                cmdlist.append(m[:-3])

        for module in self.cmd.keys():
            try:
                del sys.modules["module.core.cmd." + module]
            except:
                ''' Nothing serious '''

        self.cmd = {}
        for mod in cmdlist:
            if not mod == '__init__':
                try:
                    module = __import__("module.core.cmd." + mod)
                    module = sys.modules["module.core.cmd." + mod]
                    reload(module)
                    for cmd_listen in module.cmd:
                        self.cmd[cmd_listen] = module
                except Exception as error:
                    #print '-'*60
                    #traceback.print_exc(file=sys.stdout)
                    #print '-'*60
                    out.error("Module %s failed to run." % mod)
                    out.verbose(error)
Esempio n. 4
0
def main(modules, data):
    argv          = data['argv']
    channel       = data['channel']
    communication = modules.mcore['communication']

    nick  = data['nick']
    ident = data['ident']
    host  = data['host']

    if modules.mcore['auth'].isAdmin(nick,ident,host):
        if argv:
            name = data['argv'][0]
            verbose = False

            if len(argv) == 2:
                if argv[1] == '-v' or argv[1] == 'verbose' or argv[1] == 'report':
                    verbose = True
   
            communication.say(channel,'Running tests on module (might take some time)...')
   
            out.verbose(argv)
            module, result = modules.moduleLoader.download(argv[0],verbose)

            valid          = result['valid']
            successful     = result['successful']
            tests          = result['tests']
            errors         = result['errors']
            failures       = result['failures']
            url            = result['url']

            if inspect.ismodule(module) and valid:
                communication.say(channel,'%d/%d tests passed. Module %s downloaded, with name "%s"' % (successful, tests, name, module.name))
            else:
                if url:
                    communication.say(channel,'Failed. Module %s not loaded. Error report: %s' % (successful, tests, name, url))
                else:
                    error_msg = ''
                    errorC = 0
                    failureC = 0
                    if errors and len(errors) > 0:
                        error_msg = " : ".join(errors[0])
                        errorC = len(errors)
                    if failures and len(failures) > 0:
                        error_msg = " : ".join(failures[0])
                        failureC = len(failures)

                    communication.say(channel,'Failed. Errors: %d  Failures: %d. (%s)' % (errorC, failureC, error_msg))
    else:
        communication.say(channel,'You aren\'t allowed to do that. (requires admin)')
Esempio n. 5
0
    def parsecmd(self, nick, ident, host, channel, cmd):
        '''
        Parse a command sent to the bot and decide what to do
        
        Keyword arguments:
        nick    -- nick of sender
        ident   -- ident of sender
        host    -- host of sender
        channel -- channel the message was sent to
        cmd     -- command that was sent
        '''

        command = cmd.split()
        data = {
            'type': 'cmd',
            'nick': nick,
            'ident': ident,
            'host': host,
            'channel': channel,
            'cmd': command[0]
        }
        try:
            data['argv'] = command[1:]
        except:
            data['argv'] = None

        coreCmd = self.modules.mcore['corecmd'].parse_cmd(data)

        if not coreCmd:
            cmdModules = self.modules.listening('cmd')
            try:
                module = self.modules.cmdlist[data['cmd']]
                out.info("running: %s" % module)
                if module:
                    try:
                        self.threadmanager.runModule(module, data)
                        #thread.start_new_thread(module.main, (data, ) )
                    except Exception as error:
                        out.verbose(error)
                        out.error("Module '%s %s' failed to run." %
                                  (module.name, module.version))

                    if self.modules.requires(module, 'presist'):
                        module.presist.save()

            except:
                out.warn("could not find module that listens to %s." %
                         data['cmd'])
Esempio n. 6
0
    def parse_cmd(self,data):
        '''
        Parsing the command to check if it is a part
        of the core commands. Returns true if, false
        otherwise.
        '''
        cmd = data['cmd']
        if cmd == 'cmd' and data['argv']:
            try:
                info_cmd = self.cmd[data['argv'][0]]
                used     = ", ".join(info_cmd.cmd) 
                info     = "[%s]    usage: %s" % (used, info_cmd.usage)
                descr    = "%sdescription: %s" % (" "*len(used), info_cmd.description)

                self.communication.say(data['channel'],"%s" % info)
                self.communication.say(data['channel'],"%s" % descr)
            except:
                self.communication.say(data['channel'],"Could not find info for %s" % data['argv'][0])

            return True
        elif cmd == 'reloadcmd':
            self.load_cmds()
            self.communication.say(data['channel'], '%d core commands modules reloaded.' % len(self.cmd))
            self.cfg.load()
            out.info("Reloaded core commands and config file.")
            return True

        elif cmd == 'listcmd':
            listofcmd = ", ".join(self.cmd.keys())
            self.communication.say(data['channel'],
                    'Found %d core commands: %s. (+ reloadcmd, cmd, listcmd)' % (len(self.cmd), listofcmd))

        elif cmd in self.cmd:
            try:
                self.cmd[cmd].main(self.modules, data)
            except Exception as error:
                out.error('Module [%s] in corecmd failed.' % cmd)
                out.verbose(error)
                #print '-'*60
                #traceback.print_exc(file=sys.stdout)
                #print '-'*60
            return True

        return False
Esempio n. 7
0
    def parsecmd(self, nick, ident, host, channel, cmd):
        '''
        Parse a command sent to the bot and decide what to do
        
        Keyword arguments:
        nick    -- nick of sender
        ident   -- ident of sender
        host    -- host of sender
        channel -- channel the message was sent to
        cmd     -- command that was sent
        '''

        command = cmd.split()
        data = {'type'    :'cmd',
                'nick'    :nick,
                'ident'   :ident,
                'host'    :host,
                'channel' :channel,
                'cmd'     :command[0]}
        try: data['argv'] = command[1:]
        except: data['argv'] = None

        coreCmd = self.modules.mcore['corecmd'].parse_cmd(data)

        if not coreCmd:
            cmdModules = self.modules.listening('cmd')
            try:
                module = self.modules.cmdlist[data['cmd']]
                out.info("running: %s" % module)
                if module:
                    try: 
                        self.threadmanager.runModule(module, data)
                        #thread.start_new_thread(module.main, (data, ) )
                    except Exception as error:
                        out.verbose(error)
                        out.error("Module '%s %s' failed to run." % (module.name, module.version))

                    if self.modules.requires(module,'presist'):
                        module.presist.save()

            except:
                out.warn("could not find module that listens to %s." % data['cmd'])