def get_steam(id): response, content = browser.request("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0001/?key=" + eyercbot.config['plugin_config']['steam']['apikey'] + "&steamids=" + id) try: database = json.loads(content.decode())['response']['players']['player'][0] except: log.warning('There has been an error processing this steam account:' + id) log.warning(content.decode()) return database
def loadPlugin(plugin_name): try: # Loading system plugins filepath, pathname, description = imp.find_module(plugin_name, eyercbot.plugins.__path__) moduleSource = pathname +'/plugin.py' moduleSource = moduleSource.replace ( '\\', '/' ) handle = open ( moduleSource ) module = imp.load_module ( plugin_name, handle, ( moduleSource ), ( '.py', 'r', imp.PY_SOURCE ) ) # This batch of code will be good for loading plugins in the user directory (which will happen after main ones) #moduleSource = 'plugins/'+plugin_name+'/plugin.py' #name = moduleSource.replace ( '.py', '' ).replace ( '\\', '/' ).split ( '/' ) [ 1 ] #handle = open ( moduleSource ) #module = imp.load_module ( name, handle, ( moduleSource ), ( '.py', 'r', imp.PY_SOURCE ) ) # Populate the main database plugins[plugin_name.lower()] = module if hasattr(module, 'alias_map'): for alias, function in module.alias_map.items(): # Sometimes function may be a dict with function and threaded # We must check for this if type(function) is not dict: eyercbot.messenger.add(alias, function) else: eyercbot.messenger.add(alias, function['function'], threaded=function['threaded']) if hasattr(module, 'event_map'): for alias, function in module.event_map.items(): # Sometimes function may be a dict with function and threaded if type(function) is not dict: eyercbot.messenger.add(alias, function) else: eyercbot.messenger.add(alias, function['function'], threaded=function['threaded']) reboot = None # Will now check and update configs as needed if module.HAS_CONFIG: reboot = managePluginConfig(plugin_name, module.config, module.CONFIG_VERSION) if reboot: eyercbot.saveConfig() log.info("Plugin",plugin_name,"loaded.") return reboot except: log.warning("I couldn't load",plugin_name + '. I placed a report in errlog.txt for you.') import traceback traceback.print_exc(file=open("errlog.txt","a")) return None
def process_message(server, line): '''Process incomming string and assignes it an IRC() function for further processing''' if not line: # If a douche sends us an empty line, screw them lets try again! return # Break message into prefix, command code, and arguments prefix = '' command = '' trailing = [] if line[0] == ':': prefix, line = line[1:].split(' ', 1) if line.find(' :') != -1: line, trailing = line.split(' :', 1) arguments = line.split() arguments.append(trailing) else: arguments = line.split() command = arguments.pop(0) if command in numeric_to_symbolic: command = numeric_to_symbolic[command] # irc_ is added to prevent malicious servers method = getattr(irc, "irc_{0}".format(command), None) if method: method(server, prefix, arguments) else: log.warning('Command not yet implimented: ' + command) log.warning("Prefix: " + prefix) log.warning("Arguments: " + str(arguments))
def managePluginConfig(plugin_name, config, config_version): '''This function has the very complicated task on managing and updating the main config with the plugin config. The goal is to preserve user config in the event of a plugin config update. Plugin config version requires a bot config version of equal or greater value. Less than means the config must be updated. Returns if bot needs reboot or not TODO: Does not update nexted config expansions. Find a better way? ''' # Step 1: Check for config in db and add if not if plugin_name.lower() not in list(eyercbot.config['plugin_config'].keys()): eyercbot.config['plugin_config'][plugin_name] = config eyercbot.config['plugin_config'][plugin_name]["version"] = config_version return True # Step 2: Check for version mismatch, if not then we do not need to update if config_version > eyercbot.config['plugin_config'][plugin_name]["version"]: log.critical(plugin_name + ": !!!!ATTENTION!!!! Plugin version less than config version. Fix version mismatch before restarting bot!") #self.stop('!!!!ATTENTION!!!! Plugin version less than config version. Fix version mismatch before restarting bot!') if config_version == eyercbot.config['plugin_config'][plugin_name]["version"]: return False # Step 3: Iterate though config and see if we added anything plugin_keys = list(config.keys()) plugin_keys2 = plugin_keys for key in plugin_keys: if key in eyercbot.config['plugin_config'][plugin_name]: plugin_keys2.pop(plugin_keys2.index(key)) else: eyercbot.config['plugin_config'][plugin_name][key] = config[key] if plugin_keys2: log.warning(plugin_name + ": The following plugin config were not updated. Please compare between bot config file and plugin documentation to verify syntax did not change.") log.warning(plugin_name + str(plugin_keys2)) # Step 4: Find depriciated keys difference = set(list(config.keys())) - set(plugin_keys) if difference: log.warning(plugin_name + ": The following plugin config keys are now depriciated. Please manually remove them from the bot config file.") log.warning(plugin_name + str(difference)) eyercbot.config['plugin_config'][plugin_name]["version"] = config_version return True
def irc_ERR_UNKNOWNCOMMAND(self, prefix, params): log.warning('Unknown command: ' + str(prefix) + ', ' + str(params))