Exemple #1
0
def showtells(context):
    '.showtells -- view all pending tell messages (sent in PM).'

    nick = context.line['user']

    db = get_db_connection()
    db_init(db)

    tells = get_tells(db, nick)

    if not tells:
        bot.reply('You have no pending tells.',
                  context,
                  recipient=nick,
                  notice=True)
        return

    for tell in tells:
        user_from, message, time, chan = tell
        past = timesince(time)
        bot.reply('{0} said {1} ago in {2}: {3}'.format(
            user_from, past, chan, message),
                  context,
                  recipient=nick,
                  notice=True)

    db.execute('delete from tell where user_to=lower(?)', (nick, ))
    db.commit()
Exemple #2
0
def showtells(context):
    ".showtells -- view all pending tell messages (sent in PM)."

    nick = context.line["user"]

    db = get_db_connection()
    db_init(db)

    tells = get_tells(db, nick)

    if not tells:
        bot.reply("You have no pending tells.", context, recipient=nick, notice=True)
        return

    for tell in tells:
        user_from, message, time, chan = tell
        past = timesince(time)
        bot.reply(
            "{0} said {1} ago in {2}: {3}".format(user_from, past, chan, message), context, recipient=nick, notice=True
        )

    db.execute("delete from tell where user_to=lower(?)", (nick,))
    db.commit()
Exemple #3
0
def shorten(context):
    message = context.line['message']
    schemes = ('http://', 'https://', 'www.')
    contains_url = True in map(lambda scheme: scheme in message, schemes)

    if not contains_url:
        return

    wiki = re.search(wiki_re, context.line['message'])
    if wiki:
        return

    youtube = re.search(youtube_re, context.line['message'])
    if youtube:
        return

    urls = find_urls(message)

    titles_and_urls = []
    for url in urls:
        try:
            r = requests.get(url)
        except Exception:
            return 'unable to open url: ' + url

        parsed_page = html.parse(StringIO(r.content))
        title = parsed_page.find('.//title')
        url = shortener(url)

        if title is not None:
            title = title.text
            titles_and_urls.append(title + ' - ' + url)
        else:
            titles_and_urls.append(url)

    for result in titles_and_urls:
        bot.reply(result, context.line)
Exemple #4
0
def shorten(context):
    message = context.line['message']
    schemes = ('http://', 'https://', 'www.')
    contains_url = True in map(lambda scheme: scheme in message, schemes)

    if not contains_url:
        return

    wiki = re.search(wiki_re, context.line['message'])
    if wiki:
        return

    youtube = re.search(youtube_re, context.line['message'])
    if youtube:
        return

    urls = find_urls(message)

    titles_and_urls = []
    for url in urls:
        try:
            r = requests.get(url)
        except Exception:
            return 'unable to open url: ' + url

        parsed_page = html.parse(StringIO(r.content))
        title = parsed_page.find('.//title')
        url = shortener(url)

        if title is not None:
            title = title.text
            titles_and_urls.append(title + ' - ' + url)
        else:
            titles_and_urls.append(url)

    for result in titles_and_urls:
        bot.reply(result, context.line)