コード例 #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()
コード例 #2
0
ファイル: tell.py プロジェクト: karipe/irctk
def tell(context):
    ".tell <nick> <message>"

    db = get_db_connection()
    db_init(db)

    query = context.args.split(" ", 1)
    nick = context.line["user"]
    chan = context.line["sender"]

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

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

    if chan.lower() == user_from.lower():
        chan = "a pm"

    if user_to == user_from.lower():
        return "No."

    if db.execute("select count() from tell where user_to=?", (user_to,)).fetchone()[0] >= 5:
        return "That person has too many things queued."

    try:
        db.execute(
            "insert into tell(user_to, user_from, message, chan, " "time) values(?,?,?,?,?)",
            (user_to, user_from, message, chan, time.time()),
        )
        db.commit()
    except db.IntegrityError:
        return "Message has already been queued."
    return "I'll pass that along."
コード例 #3
0
ファイル: remember.py プロジェクト: edk0/irctk
def recall(context):
    db = get_db_connection()
    db_init(db)

    chan = context.line['sender']
    token = context.line['regex_search'].groups()[1]

    return get_remember_token(db, chan, token)
コード例 #4
0
ファイル: remember.py プロジェクト: karipe/irctk
def recall(context):
    db = get_db_connection()
    db_init(db)

    chan = context.line['sender']
    token = context.line['regex_search'].groups()[1]

    return get_remember_token(db, chan, token)
コード例 #5
0
ファイル: remember.py プロジェクト: edk0/irctk
def remember(context):
    '.remember <token> <string>, .remember <token> +<string> (append)'
    chan = context.line['sender']

    db = get_db_connection()
    db_init(db)

    args = context.args.split(' ', 1)

    if not len(args) == 2:
        return 'not enough args given'

    token = args[0]
    text = args[1][:1024]

    return add_remember_token(db, chan, token, text)
コード例 #6
0
ファイル: remember.py プロジェクト: karipe/irctk
def remember(context):
    '.remember <token> <string>, .remember <token> +<string> (append)'
    chan = context.line['sender']

    db = get_db_connection()
    db_init(db)

    args = context.args.split(' ', 1)

    if not len(args) == 2:
        return 'not enough args given'

    token = args[0]
    text = args[1][:1024]

    return add_remember_token(db, chan, token, text)
コード例 #7
0
ファイル: tell.py プロジェクト: karipe/irctk
def tellinput(context):
    if "showtells" in context.line["message"].lower():
        return

    nick = context.line["user"]

    db = get_db_connection()
    db_init(db)

    tells = get_tells(db, nick)

    if tells:
        user_from, message, time, chan = tells[0]
        past = timesince(time)
        reply = "{0} said {1} ago in {2}: {3}".format(user_from, past, chan, message)
        if len(tells) > 1:
            reply += " (+{0} more, .showtells to view)".format((len(tells) - 1))

        db.execute("delete from tell where user_to=lower(?) and message=?", (nick, message))
        db.commit()
        return reply
コード例 #8
0
def urlinput(context):
    match = context.line['regex_search']
    chan = context.line['sender']
    nick = context.line['sender']

    db = get_db_connection()

    db_init(db)

    url = match.group().encode('utf-8', 'ignore')
    url = url.decode('utf-8')
    history = get_history(db, chan, url)
    insert_history(db, chan, url, nick)

    inp = match.string.lower()

    for name in dict(history):
        if name.lower() in inp:  # person was probably quoting a line
            return  # that had a link. don't remind them.

    if nick not in dict(history):
        return format_reply(history)
コード例 #9
0
ファイル: repost.py プロジェクト: edk0/irctk
def urlinput(context):
    match = context.line['regex_search']
    chan = context.line['sender']
    nick = context.line['sender']

    db = get_db_connection()

    db_init(db)

    url = match.group().encode('utf-8', 'ignore')
    url = url.decode('utf-8')
    history = get_history(db, chan, url)
    insert_history(db, chan, url, nick)

    inp = match.string.lower()

    for name in dict(history):
        if name.lower() in inp:  # person was probably quoting a line
            return               # that had a link. don't remind them.

    if nick not in dict(history):
        return format_reply(history)
コード例 #10
0
ファイル: tell.py プロジェクト: karipe/irctk
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()
コード例 #11
0
def weather(context):
    '.weather <location>'

    db = get_db_connection()

    location = context.args
    hostmask = context.line['prefix'].split('!', 1)[-1]

    db.cursor().execute('create table if not exists ' \
                        'weather(host primary key, loc)')

    if not location:
        location = \
            db.cursor().execute('select loc from weather where host=lower(?)',
                                (hostmask,)).fetchone()[0]
        if not location:
            return weather.__doc__

    url = 'http://www.google.com/ig/api?weather=' + quote(location)
    r = etree.fromstring(requests.get(url).content)
    r = r.find('weather')

    if r.find('problem_cause') is not None:
        return ('Couldn\'t retrieve weather for {0}.'.format(location))

    info = dict((e.tag, e.get('data')) for e in r.find('current_conditions'))
    info['city'] = r.find('forecast_information/city').get('data')
    info['high'] = r.find('forecast_conditions/high').get('data')
    info['low'] = r.find('forecast_conditions/low').get('data')

    if location:
        db.execute('insert or replace into weather(host, loc) values (?,?)',
                   (hostmask, location))
        db.commit()

    return ('{city}: {condition}, {temp_f}F/{temp_c}C (H:{high}F, L:{low}), '
            '{humidity}, {wind_condition}.'.format(**info))
コード例 #12
0
def tell(context):
    '.tell <nick> <message>'

    db = get_db_connection()
    db_init(db)

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

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

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

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

    if user_to == user_from.lower():
        return 'No.'

    if db.execute('select count() from tell where user_to=?',
                  (user_to, )).fetchone()[0] >= 5:
        return 'That person has too many things queued.'

    try:
        db.execute(
            'insert into tell(user_to, user_from, message, chan, '
            'time) values(?,?,?,?,?)',
            (user_to, user_from, message, chan, time.time()))
        db.commit()
    except db.IntegrityError:
        return 'Message has already been queued.'
    return 'I\'ll pass that along.'
コード例 #13
0
def tellinput(context):
    if 'showtells' in context.line['message'].lower():
        return

    nick = context.line['user']

    db = get_db_connection()
    db_init(db)

    tells = get_tells(db, nick)

    if tells:
        user_from, message, time, chan = tells[0]
        past = timesince(time)
        reply = '{0} said {1} ago in {2}: {3}'.format(user_from, past, chan,
                                                      message)
        if len(tells) > 1:
            reply += \
                    ' (+{0} more, .showtells to view)'.format((len(tells) - 1))

        db.execute('delete from tell where user_to=lower(?) and message=?',
                   (nick, message))
        db.commit()
        return reply