Esempio n. 1
0
def wa_api(context):
    '''Usage: .wa <query>'''
    if not bot.config['WOLFRAMALPHA_KEY']:
        return 'WolframAlpha support not configured.'
    url = 'http://api.wolframalpha.com/v2/query'
    params = {'format': 'plaintext', 'appid': bot.config['WOLFRAMALPHA_KEY'], 'input': context.args}
    result = utils.make_request(url, params=params, timeout=10)
    if type(result) is str:
        return result
    xml = ET.fromstring(result.text.encode('utf8'))
    success = xml.get('success') == 'true'
    if success:
        pods = xml.findall('.//pod[@primary=\'true\']/subpod/plaintext')

        if len(pods) < 1:
            return 'No primary node returned, you {0}'.format(generate_insult())

        results = pods[-1].text.split('\n')

        def format_result_nicely(result):
            if letters_re.match(result):
                return result.replace(' | ', '')
            return result

        results = [format_result_nicely(r) for r in results]
        return ', '.join(results)
    else:
        return 'Failed, you %s.' % utils.generate_insult()
Esempio n. 2
0
def new_tell(context):
    '''.tell <nick> <message>'''

    query = context.args.split(' ', 1)
    user_from = context.line['user']
    channel = context.line['sender']

    if len(query) != 2:
        return new_tell.__doc__

    user_to = query[0].lower()
    message = query[1].strip()

    if user_to == user_from.lower():
        return 'You can tell yourself that, you {0}.'.format(generate_insult())
    elif user_to == bot.irc.nick.lower():
        return 'No, you {0}.'.format(generate_insult())

    if channel.lower() == user_from.lower():
        channel = 'a pm'

    session = Session()

    t = tells(user_to, user_from, message, channel)
    session.add(t)
    session.commit()
    Session.remove()
    get_users()

    return u'{0}: I\'ll tell {1} that when I see them.'.format(
             user_from, query[0])
Esempio n. 3
0
def insult(context):
    '''.insult <user>'''
    name = context.args
    return u'{0} is a {1}'.format(context.args, generate_insult())