Exemple #1
0
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)
Exemple #2
0
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)
Exemple #3
0
def eightball(action):
    """8ball <question> -- The all knowing magic eight ball, in electronic form. Ask and it shall be answered!"""

    magic = formatting.multiword_replace(random.choice(responses), color_codes)
    action("shakes the magic 8 ball... {}".format(magic))