def factoid(inp, message=None, db=None, bot=None, action=None, conn=None, input=None): """?<word> -- Shows what data is associated with <word>.""" try: prefix_on = bot.config["plugins"]["factoids"].get("prefix", False) except KeyError: prefix_on = False db_init(db, conn) # split up the input split = inp.group(1).strip().split(" ") factoid_id = split[0] if len(split) >= 1: arguments = u" ".join(split[1:]) else: arguments = "" data = get_memory(db, factoid_id) if data: # factoid preprocessors if data.startswith("<py>"): code = data[4:].strip() variables = u'input="""{}"""; nick="{}"; chan="{}"; bot_nick="{}"; '.format(arguments.replace('"', '\\"'), input.nick, input.chan, input.conn.nick) if code.startswith("<force>"): code = code[8:].strip() result = unicode(pyexec.eval_py(variables + code, paste_multiline=False)) else: result = unicode(pyexec.eval_py(variables + code)) else: result = unicode(data) # factoid postprocessors result = text.multiword_replace(result, shortcodes) if result.startswith("<act>"): result = result[5:].strip() action(result) elif result.startswith("<url>"): url = result[5:].strip() try: message(http.get(url)) except http.HttpError: message("Could not fetch URL.") else: if "\n" in result: result = result.strip("\r").split("\n") for output in result: if prefix_on: message(u"\x02[{}]:\x02 {}".format(factoid_id, output)) else: message(output) else: if prefix_on: message(u"\x02[{}]:\x02 {}".format(factoid_id, result)) else: message(result)
def factoid(inp, input, db, message, action): """?<word> -- Shows what data is associated with <word>.""" # split up the input split = inp.group(1).strip().split(" ") factoid_id = split[0] if len(split) >= 1: arguments = " ".join(split[1:]) else: arguments = "" if factoid_id in factoid_cache: data = factoid_cache[factoid_id] # factoid preprocessors if data.startswith("<py>"): code = data[4:].strip() variables = 'input="""{}"""; nick="{}"; chan="{}"; bot_nick="{}";'.format(arguments.replace('"', '\\"'), input.nick, input.chan, input.conn.nick) result = pyexec.eval_py(variables + code) else: result = data # factoid postprocessors result = formatting.multiword_replace(result, shortcodes) if result.startswith("<act>"): result = result[5:].strip() action(result) elif result.startswith("<url>"): url = result[5:].strip() try: message(http.get(url)) except http.HTTPError: message("Could not fetch URL.") else: message(result)
def factoid(inp, input, db, message, action): """?<word> -- Shows what data is associated with <word>.""" # split up the input split = inp.group(1).strip().split(" ") factoid_id = split[0] if len(split) >= 1: arguments = " ".join(split[1:]) else: arguments = "" if factoid_id in factoid_cache: data = factoid_cache[factoid_id] # factoid preprocessors if data.startswith("<py>"): code = data[4:].strip() variables = 'input="""{}"""; nick="{}"; chan="{}"; bot_nick="{}";'.format( arguments.replace('"', '\\"'), input.nick, input.chan, input.conn.nick) result = pyexec.eval_py(variables + code) else: result = data # factoid postprocessors result = formatting.multiword_replace(result, shortcodes) if result.startswith("<act>"): result = result[5:].strip() action(result) elif result.startswith("<url>"): url = result[5:].strip() try: message(http.get(url)) except http.HTTPError: message("Could not fetch URL.") else: message(result)
def python(inp): """python <prog> -- Executes <prog> as Python code.""" return eval_py(inp)