Exemplo n.º 1
0
    def parsepriv(self, nick, ident, host, channel, message):
        '''
        Parse a message 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
        message -- message that was sent
        '''


        privModules = self.modules.listening('privmsg')
        data = {'type'    :'privmsg',
                'nick'    :nick,
                'ident'   :ident,
                'host'    :host, 
                'channel' :channel, 
                'msg'     :message}

        for module in privModules:
            try: 
                self.threadmanager.runModule(module, data)
                #thread.start_new_thread(module.main, (data, ) )
            except: 
                out.error("Module '%s %s' failed to run correctly." % (module.name,module.version))
        
            if self.modules.requires(module,'presist'):
                module.presist.save()

        self.recentdata.store(nick,ident,host,channel,message)
Exemplo n.º 2
0
    def parsepriv(self, nick, ident, host, channel, message):
        '''
        Parse a message 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
        message -- message that was sent
        '''

        privModules = self.modules.listening('privmsg')
        data = {
            'type': 'privmsg',
            'nick': nick,
            'ident': ident,
            'host': host,
            'channel': channel,
            'msg': message
        }

        for module in privModules:
            try:
                self.threadmanager.runModule(module, data)
                #thread.start_new_thread(module.main, (data, ) )
            except:
                out.error("Module '%s %s' failed to run correctly." %
                          (module.name, module.version))

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

        self.recentdata.store(nick, ident, host, channel, message)
Exemplo 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)
Exemplo n.º 4
0
 def load(self):
     try:
         datafile = open('presistence/%s_%s.dat' % (self.module.name, self.module.version),'r')
         self.data = pickle.load(datafile)
         datafile.close()
        
         for var in self.variables:
             try:
                 vars(self.module)[var] = self.data[var]
             except:
                 out.error('Failed to load presistence: %s [%s]' % (self.module.name, var))
     except:
         out.error('Could not load presistence data file')
Exemplo n.º 5
0
    def __init__(self, owners, admins):
        self.users = []
        try:
            for owner in owners:
                user, ident, host = owner.replace(' ','').split(',')
                self.addUser(user,ident,host,1)
        except:
            out.error('No owner(s) of the bot defined.')

        try:
            for admin in admins:
                user, ident, host = admin.replace(' ','').split(',')
                self.addUser(user,ident,host,2)
        except:
            out.warn('No owners found.')
Exemplo n.º 6
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'])
Exemplo n.º 7
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
Exemplo n.º 8
0
    def runModule(self, module, data):
        '''
        runModule()

        Creating a new process representation of a brunobot extra module.
        Passing the information needed for the process, then running the
        process.

        Keyword arguments:
        module   -- brunobot extra module with a module.main(data) method
        data     -- brunobot data dictionary object
        '''
        try:
            t = ThreadModule()
            t.setModule(module, data)
            self.proccesses.append(t)
            t.start()
        except:
            out.error('Running of extra module "%s" failed.' % module.name)
Exemplo n.º 9
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'])