51 lines
1.6 KiB
Python
Executable File
51 lines
1.6 KiB
Python
Executable File
#! /usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
When was this user last seen.
|
|
"""
|
|
import time
|
|
import datetime
|
|
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."""
|
|
if not trigger.group(2):
|
|
bot.say(".seen <nick> - Reports when <nick> was last seen.")
|
|
return
|
|
nick = trigger.group(2).strip()
|
|
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)
|
|
|
|
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)
|