2019-05-25 20:40:06 +00:00
|
|
|
#--depends-on commands
|
|
|
|
|
2016-03-29 11:56:58 +00:00
|
|
|
import time
|
2018-10-03 12:22:37 +00:00
|
|
|
from src import ModuleManager, utils
|
2016-03-29 11:56:58 +00:00
|
|
|
|
2018-09-26 17:27:17 +00:00
|
|
|
class Module(ModuleManager.BaseModule):
|
2019-06-05 12:18:44 +00:00
|
|
|
def _change_seen(self, channel, user, action):
|
|
|
|
user.set_setting("seen", time.time())
|
|
|
|
user.set_setting("seen-info", {"action": action})
|
|
|
|
|
|
|
|
@utils.hook("formatted.message.channel")
|
|
|
|
@utils.hook("formatted.notice.channel")
|
|
|
|
@utils.hook("formatted.join")
|
|
|
|
@utils.hook("formatted.part")
|
|
|
|
@utils.hook("formatted.nick")
|
|
|
|
@utils.hook("formatted.quit")
|
|
|
|
def on_formatted(self, event):
|
|
|
|
line = event["minimal"] or event["line"]
|
|
|
|
|
|
|
|
if event["channel"]:
|
|
|
|
self._change_seen(event["channel"], event["user"], line)
|
|
|
|
elif event["user"]:
|
|
|
|
for channel in event["user"].channels:
|
|
|
|
self._change_seen(channel, event["user"], line)
|
2016-03-29 11:56:58 +00:00
|
|
|
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.hook("received.command.seen", min_args=1)
|
2016-03-29 11:56:58 +00:00
|
|
|
def seen(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-09-30 16:29:09 +00:00
|
|
|
:help: Find out when a user was last seen
|
|
|
|
:usage: <nickname>
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2019-06-05 12:18:44 +00:00
|
|
|
user = event["server"].get_user(event["args_split"][0])
|
|
|
|
seen_seconds = user.get_setting("seen")
|
|
|
|
|
2016-03-29 11:56:58 +00:00
|
|
|
if seen_seconds:
|
2019-06-05 12:18:44 +00:00
|
|
|
seen_info = user.get_setting("seen-info", None)
|
|
|
|
seen_info = "" if seen_info == None else (
|
|
|
|
" (%s)" % seen_info["action"])
|
|
|
|
|
2018-10-03 12:22:37 +00:00
|
|
|
since = utils.to_pretty_time(time.time()-seen_seconds,
|
2018-08-29 14:52:04 +00:00
|
|
|
max_units=2)
|
2019-06-05 12:18:44 +00:00
|
|
|
event["stdout"].write("%s was last seen %s ago%s" % (
|
|
|
|
event["args_split"][0], since, seen_info))
|
2016-03-29 11:56:58 +00:00
|
|
|
else:
|
|
|
|
event["stderr"].write("I have never seen %s before." % (
|
|
|
|
event["args_split"][0]))
|