Example #1
0
def seen(bot, trigger):
    """Reports when and where the user was last seen."""
    if not trigger.group(2):
        bot.say(".seen <nick> - Reports when <nick> was last seen.")
        return
    nick = Identifier(trigger.group(2).strip())
    if nick in seen_dict:
        timestamp = seen_dict[nick]['timestamp']
        channel = seen_dict[nick]['channel']
        message = seen_dict[nick]['message']

        tz = get_timezone(bot.db, bot.config, None, trigger.nick,
                          trigger.sender)
        saw = datetime.datetime.utcfromtimestamp(timestamp)
        timestamp = format_time(bot.db, bot.config, tz, trigger.nick,
                                trigger.sender, saw)

        msg = "I last saw {} at {}".format(nick, timestamp)
        if Identifier(channel) == trigger.sender:
            msg = msg + " in here, saying " + message
        else:
            msg += " in another channel."
        bot.say(str(trigger.nick) + ': ' + msg)
    else:
        bot.say("Sorry, I haven't seen %s around." % nick)
Example #2
0
def update_user_format(bot, trigger):
    """
    Sets your preferred format for time. Uses the standard strftime format. You
    can use http://strftime.net or your favorite search engine to learn more.
    """
    if bot.db:
        tformat = trigger.group(2)
        if not tformat:
            bot.reply("What format do you want me to use? Try using"
                         " http://strftime.net to make one.")

        tz = get_timezone(bot.db, bot.config, None, None,
                                       trigger.sender)
        try:
            timef = format_time(zone=tz)
        except:
            bot.reply("That format doesn't work. Try using"
                         " http://strftime.net to make one.")
            return
        bot.db.preferences.update(trigger.nick, {'time_format': tformat})
        bot.reply("Got it. Your time will now appear as %s. (If the "
                     "timezone is wrong, you might try the settz command)"
                     % timef)
    else:
        bot.reply("I can't remember that; I don't have a database.")
Example #3
0
def update_user_format(bot, trigger):
    """
    Sets your preferred format for time. Uses the standard strftime format. You
    can use http://strftime.net or your favorite search engine to learn more.
    """
    tformat = trigger.group(2)
    if not tformat:
        bot.reply("What format do you want me to use? Try using"
                  " http://strftime.net to make one.")
        return

    tz = get_timezone(bot.db, bot.config, None, trigger.nick, trigger.sender)

    # Get old format as back-up
    old_format = bot.db.get_nick_value(trigger.nick, 'time_format')

    # Save the new format in the database so we can test it.
    bot.db.set_nick_value(trigger.nick, 'time_format', tformat)

    try:
        timef = format_time(db=bot.db, zone=tz, nick=trigger.nick)
    except:
        bot.reply("That format doesn't work. Try using"
                  " http://strftime.net to make one.")
        # New format doesn't work. Revert save in database.
        bot.db.set_nick_value(trigger.nick, 'time_format', old_format)
        return
    bot.reply("Got it. Your time will now appear as %s. (If the "
              "timezone is wrong, you might try the settz command)"
              % timef)
Example #4
0
def seen(bot, trigger):
    """Reports when and where the user was last seen."""
    if not trigger.group(2):
        bot.say(".seen <nick> - Reports when <nick> was last seen.")
        return
    nick = trigger.group(2).strip()
    timestamp = bot.db.get_nick_value(nick, 'seen_timestamp')
    if timestamp:
        channel = bot.db.get_nick_value(nick, 'seen_channel')
        message = bot.db.get_nick_value(nick, 'seen_message')

        tz = get_timezone(bot.db, bot.config, None, trigger.nick,
                          trigger.sender)
        saw = datetime.datetime.utcfromtimestamp(timestamp)
        timestamp = format_time(bot.db, bot.config, tz, trigger.nick,
                                trigger.sender, saw)

        msg = "I last saw {} at {}".format(nick, timestamp)
        if Identifier(channel) == trigger.sender:
            msg = msg + " in here, saying " + message
        else:
            msg += " in another channel."
        bot.say(str(trigger.nick) + ': ' + msg)
    else:
        bot.say("Sorry, I haven't seen {} around.".format(nick))
Example #5
0
File: clock.py Project: dkg/willie
def update_user_format(bot, trigger):
    """
    Sets your preferred format for time. Uses the standard strftime format. You
    can use http://strftime.net or your favorite search engine to learn more.
    """
    tformat = trigger.group(2)
    if not tformat:
        bot.reply("What format do you want me to use? Try using"
                  " http://strftime.net to make one.")

    tz = get_timezone(bot.db, bot.config, None, None, trigger.sender)

    # Get old format as back-up
    old_format = bot.db.get_nick_value(trigger.nick, 'time_format')

    # Save the new format in the database so we can test it.
    bot.db.set_nick_value(trigger.nick, 'time_format', tformat)

    try:
        timef = format_time(db=bot.db, zone=tz, nick=trigger.nick)
    except:
        bot.reply("That format doesn't work. Try using"
                  " http://strftime.net to make one.")
        # New format doesn't work. Revert save in database.
        bot.db.set_nick_value(trigger.nick, 'time_format', old_format)
        return
    bot.reply("Got it. Your time will now appear as %s. (If the "
              "timezone is wrong, you might try the settz command)"
              % timef)
Example #6
0
File: clock.py Project: dkg/willie
def update_channel_format(bot, trigger):
    """
    Sets your preferred format for time. Uses the standard strftime format. You
    can use http://strftime.net or your favorite search engine to learn more.
    """
    if bot.privileges[trigger.sender][trigger.nick] < OP:
        return

    tformat = trigger.group(2)
    if not tformat:
        bot.reply("What format do you want me to use? Try using"
                  " http://strftime.net to make one.")

    tz = get_timezone(bot.db, bot.config, None, None, trigger.sender)
    try:
        timef = format_time(zone=tz)
    except:
        bot.reply("That format doesn't work. Try using"
                  " http://strftime.net to make one.")
        return
    bot.db.set_channel_value(trigger.sender, 'time_format', tformat)
    bot.reply("Got it. Times in this channel  will now appear as %s "
              "unless a user has their own format set. (If the timezone"
              " is wrong, you might try the settz and channeltz "
              "commands)" % timef)
Example #7
0
def seen(bot, trigger):
    if not trigger.group(2):
        if bot.config.lang == 'ca':
            bot.say(u"He vist per última vegada a \x02%s\x02 ara mateix a \x02%s\x02, dient \x1D%s\x0F" % (trigger.nick, trigger.sender, trigger.group(0)))
        elif bot.config.lang == 'es':
            bot.say(u"He visto por última vez a \x02%s\x02 ahora mismo en \x02%s\x02, diciendo \x1D%s\x0F" % (trigger.nick, trigger.sender, trigger.group(0)))
        else:
            bot.say(u"I last saw \x02%s\x02 right now on \x02%s\x02, saying \x1D%s\x0F" % (trigger.nick, trigger.sender, trigger.group(0)))
        return
    nick = Nick(trigger.group(2).strip())
    if nick in seen_dict:
        timestamp = seen_dict[nick]['timestamp']
        channel = seen_dict[nick]['channel']
        message = seen_dict[nick]['message']

        tz = get_timezone(bot.db, bot.config, None, trigger.nick,
                          trigger.sender)
        saw = datetime.datetime.utcfromtimestamp(timestamp)
        timestamp = format_time(bot.db, bot.config, tz, trigger.nick,
                                trigger.sender, saw)
        if bot.config.lang == 'ca':
            msg = u"He vist \x02%s\x02 per última vegada el dia \x02%s\x02 al canal \x02%s\x02, dient: \x1D%s\x0F" % (nick, timestamp, channel, message)
        elif bot.config.lang == 'es':
            msg = u"He visto a \x02%s\x02 por última vez el día \x02%s\x02 en el canal \x02%s\x02, diciendo: \x1D%s\x0F" % (nick, timestamp, channel, message)
        else:                                
            msg = u"I last saw \x02%s\x02 at \x02%s\x02 on \x02%s\x02, saying \x1D%s\x0F" % (nick, timestamp, channel, message)
        bot.say(str(trigger.nick) + ': ' + msg)
    else:
        if bot.config.lang == 'ca':
            bot.say(u"No recordo haver vist a \x02%s\x02." % nick)
        elif bot.config.lang == 'es':
            bot.say(u"No recuerdo haber visto a \x02%s\x02." % nick)
        else:
            bot.say("Sorry, I haven't seen \x02%s\x02 around." % nick)
Example #8
0
def update_user_format(bot, trigger):
    """
    Sets your preferred format for time. Uses the standard strftime format. You
    can use http://strftime.net or your favorite search engine to learn more.
    """
    if bot.db:
        tformat = trigger.group(2)
        if not tformat:
            bot.reply("What format do you want me to use? Try using"
                      " http://strftime.net to make one.")

        tz = get_timezone(bot.db, bot.config, None, None, trigger.sender)

        # Get old format as back-up
        old_format = bot.db.preferences.get(trigger.nick, 'time_format')

        # Save the new format in the database so we can test it.
        bot.db.preferences.update(trigger.nick, {'time_format': tformat})

        try:
            timef = format_time(db=bot.db, zone=tz, nick=trigger.nick)
        except:
            bot.reply("That format doesn't work. Try using"
                      " http://strftime.net to make one.")
            # New format doesn't work. Revert save in database.
            bot.db.preferences.update(trigger.nick, {'time_format': old_format})
            return
        bot.reply("Got it. Your time will now appear as {}. (If the timezone "
                  "is wrong, you might try the settz command)".format(timef))
    else:
        bot.reply("I can't remember that; I don't have a database.")
Example #9
0
def update_channel_format(bot, trigger):
    """
    Sets your preferred format for time. Uses the standard strftime format. You
    can use http://strftime.net or your favorite search engine to learn more.
    """
    if bot.privileges[trigger.sender][trigger.nick] < OP:
        return
    elif not bot.db:
        bot.reply("I can't remember that; I don't have a database.")
    else:
        tformat = trigger.group(2)
        if not tformat:
            bot.reply("What format do you want me to use? Try using"
                         " http://strftime.net to make one.")

        tz = get_timezone(bot.db, bot.config, None, None,
                                       trigger.sender)
        try:
            timef = format_time(zone=tz)
        except:
            bot.reply("That format doesn't work. Try using"
                         " http://strftime.net to make one.")
            return
        bot.db.preferences.update(trigger.sender, {'time_format': tformat})
        bot.reply("Got it. Times in this channel  will now appear as %s "
                     "unless a user has their own format set. (If the timezone"
                     " is wrong, you might try the settz and channeltz "
                     "commands)" % timef)
Example #10
0
def update_user_format(bot, trigger):
    """
    Establece el formato de fecha y hora de un usuario. Puedes buscar uno de tu preferencia en http://strftime.net o en
    cualquier motor de búsqueda.
    """
    if bot.db:
        tformat = trigger.group(2)
        if not tformat:
            bot.reply("Que formato de zona horaria deseas utilizar?"
                         " Entra a http://strftime.net para crear uno.")

        tz = get_timezone(bot.db, bot.config, None, None,
                                       trigger.sender)

        # Get old format as back-up
        old_format = bot.db.preferences.get(trigger.nick, 'time_format')

        # Save the new format in the database so we can test it.
        bot.db.preferences.update(trigger.nick, {'time_format': tformat})

        try:
            timef = format_time(db = bot.db, zone=tz, nick=trigger.nick)
        except:
            bot.reply("Ese formato no es válido. Entra a"
                         " http://strftime.net para crear uno.")
            # New format doesn't work. Revert save in database.
            bot.db.preferences.update(trigger.nick, {'time_format': old_format})
            return
        bot.reply("Fantástico!. Tu hora ahora se mostrará como %s. (Si tu "
                     "zona horaria es incorrecta, puedes cambiarla con el comando timez)"
                     % timef)
    else:
        bot.reply("No puedo recordar eso! no tengo base de datos :/")
Example #11
0
def update_user_format(bot, trigger):
    """
    Sets your preferred format for time. Uses the standard strftime format. You
    can use http://strftime.net or your favorite search engine to learn more.
    """
    if bot.db:
        tformat = trigger.group(2)
        if not tformat:
            bot.reply("What format do you want me to use? Try using"
                         " http://strftime.net to make one.")

        tz = get_timezone(bot.db, bot.config, None, None,
                                       trigger.sender)
        try:
            timef = format_time(zone=tz)
        except:
            bot.reply("That format doesn't work. Try using"
                         " http://strftime.net to make one.")
            return
        bot.db.preferences.update(trigger.nick, {'time_format': tformat})
        bot.reply("Got it. Your time will now appear as %s. (If the "
                     "timezone is wrong, you might try the settz command)"
                     % timef)
    else:
        bot.reply("I can't remember that; I don't have a database.")
Example #12
0
def f_time(bot, trigger):
    """Returns the current time."""
    if trigger.group(2):
        zone = get_timezone(bot.db, bot.config, trigger.group(2), None, None)
        if not zone:
            bot.say('oops')
            return
    else:
        zone = get_timezone(bot.db, bot.config, None, trigger.nick,
                            trigger.sender)
    time = format_time(bot.db, bot.config, zone, trigger.nick, trigger.sender)
    bot.say(time)
Example #13
0
def f_time(bot, trigger):
    """Da la hora actual en alguna zona horaria."""
    if trigger.group(2):
        zone = get_timezone(bot.db, bot.config, trigger.group(2).strip(), None, None)
        if not zone:
            bot.say('No se ha encontrado la zona horaria %s.' % trigger.group(2).strip())
            return
    else:
        zone = get_timezone(bot.db, bot.config, None, trigger.nick,
                            trigger.sender)
    time = format_time(bot.db, bot.config, zone, trigger.nick, trigger.sender)
    bot.say(time)
Example #14
0
def f_time(bot, trigger):
    """Returns the current time."""
    if trigger.group(2):
        zone = get_timezone(bot.db, bot.config, trigger.group(2).strip(), None, None)
        if not zone:
            bot.say('Could not find timezone %s.' % trigger.group(2).strip())
            return
    else:
        zone = get_timezone(bot.db, bot.config, None, trigger.nick,
                            trigger.sender)
    time = format_time(bot.db, bot.config, zone, trigger.nick, trigger.sender)
    bot.say("Oh, you cheaped out and got a computer without a clock? It's %s" % time)
Example #15
0
File: clock.py Project: dkg/willie
def f_time(bot, trigger):
    """Returns the current time."""
    if trigger.group(2):
        zone = get_timezone(bot.db, bot.config, trigger.group(2).strip(), None, None)
        if not zone:
            bot.say('Could not find timezone %s.' % trigger.group(2).strip())
            return
    else:
        zone = get_timezone(bot.db, bot.config, None, trigger.nick,
                            trigger.sender)
    time = format_time(bot.db, bot.config, zone, trigger.nick, trigger.sender)
    bot.say(time)
Example #16
0
def f_time(bot, trigger):
    """Returns the current time."""
    if trigger.group(2):
        zone = get_timezone(bot.db, bot.config, trigger.group(2).strip(), None, None)
        if not zone:
            bot.say('Could not find timezone %s.' % trigger.group(2).strip())
            return
    else:
        zone = get_timezone(bot.db, bot.config, None, trigger.nick,
                            trigger.sender)
    time = format_time(bot.db, bot.config, zone, trigger.nick, trigger.sender)
    bot.say(time)
Example #17
0
def seen(bot, trigger):
    nick = trigger.group(2).strip()
    if nick in bot.db.seen_db:
        sn = bot.db.seen_db.get(nick, ['timestamp', 'channel', 'message'])
        tz = get_timezone(bot.db, bot.config, None, trigger.nick,
                          trigger.sender)
        saw = datetime.datetime.utcfromtimestamp(time.mktime(time.strptime(sn[0],
                        "%a %b %d %H:%M:%S %Y")))
        timestamp = format_time(bot.db, bot.config, tz, trigger.nick,
                               trigger.sender, saw)
        msg = "I last saw %s at %s on %s saying %s" % (nick, timestamp, sn[1], sn[2])
        bot.say(str(trigger.nick) + ': ' + msg)
    else:
        bot.say("Sorry, I haven't seen %s around." % nick)
Example #18
0
def seen(bot, trigger):
    if not trigger.group(2):
        if bot.config.lang == 'ca':
            bot.say(
                u"He vist per última vegada a \x02%s\x02 ara mateix a \x02%s\x02, dient \x1D%s\x0F"
                % (trigger.nick, trigger.sender, trigger.group(0)))
        elif bot.config.lang == 'es':
            bot.say(
                u"He visto por última vez a \x02%s\x02 ahora mismo en \x02%s\x02, diciendo \x1D%s\x0F"
                % (trigger.nick, trigger.sender, trigger.group(0)))
        else:
            bot.say(
                u"I last saw \x02%s\x02 right now on \x02%s\x02, saying \x1D%s\x0F"
                % (trigger.nick, trigger.sender, trigger.group(0)))
        return
    name = str(trigger.group(2))
    if ' ' in name:
        name = name.split()[0]
    with open(seen_dict, "r") as f:
        data = json.load(f)
    if name in data:
        timestamp = data[name]['timestamp']
        channel = data[name]['channel']
        message = data[name]['message']

        tz = get_timezone(bot.db, bot.config, None, trigger.nick,
                          trigger.sender)
        saw = datetime.datetime.utcfromtimestamp(timestamp)
        timestamp = format_time(bot.db, bot.config, tz, trigger.nick,
                                trigger.sender, saw)
        if bot.config.lang == 'ca':
            msg = u"He vist \x02%s\x02 per última vegada el dia \x02%s\x02 al canal \x02%s\x02, dient: \x1D%s\x0F" % (
                name, timestamp, channel, message)
        elif bot.config.lang == 'es':
            msg = u"He visto a \x02%s\x02 por última vez el día \x02%s\x02 en el canal \x02%s\x02, diciendo: \x1D%s\x0F" % (
                name, timestamp, channel, message)
        else:
            msg = u"I last saw \x02%s\x02 at \x02%s\x02 on \x02%s\x02, saying \x1D%s\x0F" % (
                name, timestamp, channel, message)
        bot.say(str(trigger.nick) + ': ' + msg)
    else:
        if bot.config.lang == 'ca':
            bot.say(u"No recordo haver vist a \x02%s\x02." % name)
        elif bot.config.lang == 'es':
            bot.say(u"No recuerdo haber visto a \x02%s\x02." % name)
        else:
            bot.say("Sorry, I haven't seen \x02%s\x02 around." % name)
Example #19
0
def process_urls(bot, trigger, urls):
    for pre, url, post in urls:
        if not url.startswith(exclusion_char):
            # Magic stuff to account for international domain names
            try:
                url = web.iri_to_uri(url)
            except:
                pass
            bot.memory['last_seen_url'][trigger.sender] = url
            # post the bookmark to the Bookie API
            (title, domain, resp, headers) = api_bmark(bot, trigger, url,
                                                       pre + post)
            if headers['_http_status'] != 200:
                status = 'error from bookie API: %s' % text(
                    resp.decode('utf-8', 'ignore'))
            else:
                # try to show the user when the bookmark was posted,
                # so they can tell if it's new
                try:
                    # assumes that bookie's times are UTC
                    timestamp = datetime.strptime(
                        json.loads(resp)['bmark']['stored'],
                        '%Y-%m-%d %H:%M:%S')
                    if pytz:
                        tz = tools.get_timezone(bot.db, bot.config,
                                                trigger.nick, trigger.sender)
                        timestamp = tools.format_time(bot.db, bot.config, tz,
                                                      trigger.nick,
                                                      trigger.sender,
                                                      timestamp)
                    else:
                        timestamp += 'Z'
                    status = 'posted on ' + timestamp
                except KeyError:
                    # the 'stored' field is not in the response?
                    status = 'no timestamp in %s' % json.loads(resp)
                except ValueError as e:
                    if 'JSON' in str(e):
                        status = u'cannot parse JSON response: %s' % resp.decode(
                            'utf-8', 'ignore')
                    else:
                        raise
            message = '[ %s ] - %s (%s)' % (title, domain, status)
            # Guard against responding to other instances of this bot.
            if message != trigger:
                bot.say(message)
Example #20
0
def seen(bot, trigger):
    """Scrive quando e dove l'utente è stato visto per l'ultima volta"""
    if not trigger.group(2):
        bot.say(".seen <nick> - Scrive quando <nick> è stato visto l'ultima volta")
        return
    nick = Nick(trigger.group(2).strip())
    if nick in seen_dict:
        timestamp = seen_dict[nick]['timestamp']
        channel = seen_dict[nick]['channel']
        message = seen_dict[nick]['message']

        tz = get_timezone(bot.db, bot.config, None, trigger.nick,
                          trigger.sender)
        saw = datetime.datetime.utcfromtimestamp(timestamp)
        timestamp = format_time(bot.db, bot.config, tz, trigger.nick,
                                trigger.sender, saw)

        msg = "Ho visto %s per l'ultima volta %s su %s, e ha detto %s" % (nick, timestamp, channel, message)
        bot.say(str(trigger.nick) + ': ' + msg)
    else:
        bot.say("Mi spiace, non ho visto %s in giro." % nick)
Example #21
0
def seen(bot, trigger):
    """Reports when and where the user was last seen."""
    if not trigger.group(2):
        bot.say(".seen <nick> - Reports when <nick> was last seen.")
        return
    nick = Identifier(trigger.group(2).strip())
    if nick in seen_dict:
        timestamp = seen_dict[nick]['timestamp']
        channel = seen_dict[nick]['channel']
        message = seen_dict[nick]['message']

        tz = get_timezone(bot.db, bot.config, None, trigger.nick,
                          trigger.sender)
        saw = datetime.datetime.utcfromtimestamp(timestamp)
        timestamp = format_time(bot.db, bot.config, tz, trigger.nick,
                                trigger.sender, saw)

        msg = "I last saw %s at %s on %s, saying %s" % (nick, timestamp, channel, message)
        bot.say(str(trigger.nick) + ': ' + msg)
    else:
        bot.say("Sorry, I haven't seen %s around." % nick)
Example #22
0
def process_urls(bot, trigger, urls):
    for pre, url, post in urls:
        if not url.startswith(exclusion_char):
            # Magic stuff to account for international domain names
            try:
                url = willie.web.iri_to_uri(url)
            except:
                pass
            bot.memory['last_seen_url'][trigger.sender] = url
            # post the bookmark to the Bookie API
            (title, domain, resp, headers) = api_bmark(bot, trigger, url, pre+post)
            if headers['_http_status'] != 200:
                status = 'error from bookie API: %s' % text(resp.decode('utf-8', 'ignore'))
            else:
                # try to show the user when the bookmark was posted,
                # so they can tell if it's new
                try:
                    # assumes that bookie's times are UTC
                    timestamp = datetime.strptime(json.loads(resp)['bmark']['stored'], '%Y-%m-%d %H:%M:%S')
                    if pytz:
                        tz = tools.get_timezone(bot.db, bot.config,
                                                trigger.nick, trigger.sender)
                        timestamp = tools.format_time(bot.db, bot.config, tz, trigger.nick,
                                                      trigger.sender, timestamp)
                    else:
                        timestamp += 'Z'
                    status = 'posted on ' + timestamp
                except KeyError:
                    # the 'stored' field is not in the response?
                    status = 'no timestamp in %s' % json.loads(resp)
                except ValueError as e:
                    if 'JSON' in str(e):
                        status = u'cannot parse JSON response: %s' % resp.decode('utf-8', 'ignore')
                    else:
                        raise
            message = '[ %s ] - %s (%s)' % (title, domain, status)
            # Guard against responding to other instances of this bot.
            if message != trigger:
                bot.say(message)
Example #23
0
def seen(bot, trigger):
    """Reports when and where the user was last seen."""
    if not trigger.group(2):
        bot.say(".seen <nick> - Reports when <nick> was last seen.")
        return
    nick = Nick(trigger.group(2).strip())
    if nick in seen_dict:
        timestamp = seen_dict[nick]['timestamp']
        channel = seen_dict[nick]['channel']
        message = seen_dict[nick]['message']

        tz = get_timezone(bot.db, bot.config, None, trigger.nick,
                          trigger.sender)
        saw = datetime.datetime.utcfromtimestamp(timestamp)
        timestamp = format_time(bot.db, bot.config, tz, trigger.nick,
                                trigger.sender, saw)

        msg = "I last saw %s at %s on %s, saying %s" % (nick, timestamp,
                                                        channel, message)
        bot.say(str(trigger.nick) + ': ' + msg)
    else:
        bot.say("Sorry, I haven't seen %s around." % nick)