def reload_config(self, event): if event.module == "core" or event.module == "all": self.read_config() if event.module == "modules": self.modules = [] reload(moduleloader) self.modules = moduleloader.reload_modules(self.modules, self.ed)
def main(self, msg, MODULES, CFG): """ Need to have some basic variables set for each message """ message = msg['body'] results = {} # fill in keys in the results dict for mod_name in CFG['mods']: results['%s_msgs' %(mod_name)] = [] # send message to history module if loaded if MODULES.has_key('history'): if (msg['mucnick'] != self.nick): MODULES['history'].main(self, msg, CFG) """ Make sure the message comes from a public channel. Otherwise, someone could game the karma system. In a future version, there will be a key to check that determines what to do with a message before this point is reached. """ if (msg['type'] == 'groupchat'): if (message.__contains__('karma') or \ message.__contains__('--') or \ message.__contains__('++')): try: # add the result from the karma module to results dict results['karma_msgs'] = MODULES['karma'].main(self, msg, CFG) except: print "Couldn't set karma for some reason" #look for URIs, excluding deenproject URIs, exclusion in uri.py #right now only http/https/ftp are being parsed uris = [] uris_wiki = [] for uri_match in uri_re.findall(message): # uri_match is a tuple, so check second element if uri_match not in uris_wiki and 'wiki.deen' in uri_match[1]: uris_wiki.append(uri_match) elif uri_match not in uris: uris.append(uri_match) if uris: try: results['uri_msgs'] = MODULES['uri'].main(self, msg, uris, CFG) except: print "Couldn't parse uri title for some reason" if uris_wiki: print uris_wiki try: results['uri_msgs'] = MODULES['mediawiki'].main(self, msg, uris_wiki, CFG) except: print "Couldn't parse wiki uri title for some reason" if (msg['body'].startswith('seen ')): try: results['seen_msgs'] = MODULES['seen'].main(self, msg, MODULES, CFG) except: print "Couldn't run seen for some reason" # look for chiliproject issue #s # duplicates are removed issues = [] for issue in issue_re.findall(msg['body']): # strip spaces first, then #, order matters issue = issue.strip() issue = issue.strip('#') issue = issue.strip('?') if issue not in issues: issues.append(issue) if issues: try: results['chili_msgs'] = MODULES['chili'].main(self, msg, issues, CFG) except: print "Couldn't get issue title for some reason" votes = [] if ('vote' in msg['body'] and msg['mucnick'] != self.nick): results['vote_msgs'] = MODULES['vote'].main(self, msg, CFG) actions = [] if 'earlbot' in msg['body']: for action in slap_re.findall(msg['body']): actions.append(action) if actions: results['actions_msgs'] = MODULES['actions'].main(self, msg, issues, CFG) return results if (msg['type'] == 'chat' and msg['mucnick'] != self.nick): # this lets the bot reload modules in /modules - handy for development # careful though, reloading with a config that has different modules # might lead to an unexpected result - untested if (msg['body'] == 'reload'): try: MODULES = moduleloader.reload_modules(MODULES, CFG) except: print "Couldn't reload modules" return results