2017-11-22 19:26:40 -05:00
|
|
|
#! /usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
When was this user last seen.
|
|
|
|
"""
|
|
|
|
import time
|
|
|
|
import datetime
|
2018-01-05 08:46:52 -05:00
|
|
|
import argparse
|
|
|
|
|
2017-11-22 19:26:40 -05:00
|
|
|
from tools import Identifier
|
|
|
|
from tools.time import get_timezone, format_time, relativeTime
|
|
|
|
from module import commands, rule, priority, thread
|
|
|
|
|
|
|
|
|
|
|
|
@commands('seen')
|
|
|
|
def seen(bot, trigger):
|
|
|
|
"""Reports when and where the user was last seen."""
|
2018-01-05 08:46:52 -05:00
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument("nick")
|
|
|
|
parser.add_argument("-l", "--last", action="store_true")
|
|
|
|
args = parser.parse_args(trigger.group(2).split())
|
|
|
|
|
|
|
|
# if not trigger.group(2):
|
|
|
|
# bot.say(".seen <nick> - Reports when <nick> was last seen.")
|
|
|
|
# return
|
|
|
|
# nick = trigger.group(2).strip()
|
|
|
|
nick = args.nick
|
2017-11-22 19:26:40 -05:00
|
|
|
if nick == bot.nick:
|
|
|
|
bot.reply("I'm right here!")
|
|
|
|
return
|
|
|
|
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')
|
|
|
|
action = bot.db.get_nick_value(nick, 'seen_action')
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
reltime = relativeTime(bot, nick, timestamp)
|
|
|
|
msg = "Last heard from \x0308{}\x03 at {} (\x0312{}\x03) in \x0312{}".format(nick, timestamp, reltime, channel)
|
|
|
|
|
2018-01-05 08:46:52 -05:00
|
|
|
if args.last:
|
|
|
|
msg += "\x03 with \"\x0308{}\x03\"".format(message)
|
|
|
|
|
2017-11-22 19:26:40 -05:00
|
|
|
bot.reply(msg)
|
|
|
|
else:
|
|
|
|
bot.say("I haven't seen \x0308{}".format(nick))
|
|
|
|
|
|
|
|
|
|
|
|
@thread(False)
|
|
|
|
@rule('(.*)')
|
|
|
|
@priority('low')
|
|
|
|
def note(bot, trigger):
|
|
|
|
if not trigger.is_privmsg:
|
|
|
|
bot.db.set_nick_value(trigger.nick, 'seen_timestamp', time.time())
|
|
|
|
bot.db.set_nick_value(trigger.nick, 'seen_channel', trigger.sender)
|
|
|
|
bot.db.set_nick_value(trigger.nick, 'seen_message', trigger)
|
|
|
|
bot.db.set_nick_value(trigger.nick, 'seen_action', 'intent' in trigger.tags)
|