2016-03-29 11:56:58 +00:00
|
|
|
import time
|
2018-09-24 14:13:27 +00:00
|
|
|
from src import Utils
|
2016-03-29 11:56:58 +00:00
|
|
|
|
|
|
|
class Module(object):
|
2018-09-02 18:54:45 +00:00
|
|
|
def __init__(self, bot, events, exports):
|
2018-09-19 12:25:12 +00:00
|
|
|
events.on("received.message.channel").hook(self.channel_message)
|
|
|
|
events.on("received.command.seen").hook(self.seen, min_args=1,
|
|
|
|
help="Find out when a user was last seen", usage="<username>")
|
2016-03-29 11:56:58 +00:00
|
|
|
|
|
|
|
def channel_message(self, event):
|
|
|
|
seen_seconds = time.time()
|
|
|
|
event["user"].set_setting("seen", seen_seconds)
|
|
|
|
|
|
|
|
def seen(self, event):
|
|
|
|
seen_seconds = event["server"].get_user(event["args_split"][0]
|
|
|
|
).get_setting("seen")
|
|
|
|
if seen_seconds:
|
2018-08-29 14:52:04 +00:00
|
|
|
since = Utils.to_pretty_time(time.time()-seen_seconds,
|
|
|
|
max_units=2)
|
|
|
|
event["stdout"].write("%s was last seen %s ago" % (
|
|
|
|
event["args_split"][0], since))
|
2016-03-29 11:56:58 +00:00
|
|
|
else:
|
|
|
|
event["stderr"].write("I have never seen %s before." % (
|
|
|
|
event["args_split"][0]))
|