Exemplo n.º 1
0
        except:
            phrase = False
        if not phrase:
            phrase = backup
            break

        try:
            phrase = translate(phrase[0], lang, 'en')
        except:
            phrase = backup
            continue

        if not phrase:
            phrase = backup
            break
    bot.reply(phrase[0])


@rule('(.*)')
@priority('low')
def collect_mangle_lines(bot, trigger):
    global mangle_lines
    mangle_lines[
        trigger.sender.lower()] = "%s said '%s'" % (trigger.nick,
                                                    (trigger.group(0).strip()))


if __name__ == "__main__":
    from sopel.test_tools import run_example_tests
    run_example_tests(__file__)
Exemplo n.º 2
0
    if answer:
        answer = answer.decode('unicode_escape')
        answer = HTMLParser.HTMLParser().unescape(answer)
        # This might not work if there are more than one instance of escaped
        # unicode chars But so far I haven't seen any examples of such output
        # examples from Wolfram Alpha
        match = re.search('\\\:([0-9A-Fa-f]{4})', answer)
        if match is not None:
            char_code = match.group(1)
            char = unichr(int(char_code, 16))
            answer = answer.replace('\:' + char_code, char)
        waOutputArray = answer.split(";")
        if(len(waOutputArray) < 2):
            if(answer.strip() == "Couldn't grab results from json stringified precioussss."):
                # Answer isn't given in an IRC-able format, just link to it.
                bot.say('[WOLFRAM]Couldn\'t display answer, try http://www.wolframalpha.com/input/?i=' + query.replace(' ', '+'))
            else:
                bot.say('[WOLFRAM ERROR]' + answer)
        else:

            bot.say('[WOLFRAM] ' + waOutputArray[0] + " = "
                    + waOutputArray[1])
        waOutputArray = []
    else:
        bot.reply('Sorry, no result.')


if __name__ == "__main__":
    from sopel.test_tools import run_example_tests
    run_example_tests(__file__)
Exemplo n.º 3
0
def initPlayer(bot, trigger):
    globals['bot'] = bot

    # new player instance
    p = Player(trigger.nick)

    # set player record
    bot.memory['players'][trigger.nick] = p

    return p


# returns the player instance for this user
def getPlayer(bot, trigger):
    globals['bot'] = bot

    # init memory if needed
    if (not bot.memory.contains('players')):
        return None

    # player exists, return it
    if (bot.memory['players'].contains(trigger.nick)):
        return bot.memory['players'][trigger.nick]

    return None


if __name__ == "__main__":
    from sopel.test_tools import run_example_tests
    run_example_tests(__file__, verbose=False)