2019-05-25 20:40:06 +00:00
|
|
|
#--depends-on commands
|
2019-06-19 21:14:13 +00:00
|
|
|
#--depends-on format_activity
|
2019-05-25 20:40:06 +00:00
|
|
|
|
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())
|
2019-10-30 11:42:00 +00:00
|
|
|
channel.set_user_setting(user.get_id(), "seen-info", {"action": action})
|
2019-06-05 12:18:44 +00:00
|
|
|
|
|
|
|
@utils.hook("formatted.message.channel")
|
|
|
|
@utils.hook("formatted.notice.channel")
|
|
|
|
def on_formatted(self, event):
|
|
|
|
line = event["minimal"] or event["line"]
|
|
|
|
|
2019-11-30 16:43:41 +00:00
|
|
|
if not event["server"].is_own_nickname(event["user"].nickname):
|
2019-12-04 10:34:34 +00:00
|
|
|
self._change_seen(event["channel"], event["user"], line)
|
2016-03-29 11:56:58 +00:00
|
|
|
|
2020-02-28 22:57:16 +00:00
|
|
|
@utils.hook("received.command.seen")
|
|
|
|
@utils.kwarg("help", "Find out when a user was last seen")
|
|
|
|
@utils.spec("!<nickname>ouser")
|
2016-03-29 11:56:58 +00:00
|
|
|
def seen(self, event):
|
2020-02-28 22:57:16 +00:00
|
|
|
user = event["spec"][0]
|
2019-06-05 12:18:44 +00:00
|
|
|
seen_seconds = user.get_setting("seen")
|
|
|
|
|
2016-03-29 11:56:58 +00:00
|
|
|
if seen_seconds:
|
2019-10-30 11:42:00 +00:00
|
|
|
seen_info = None
|
|
|
|
if event["is_channel"]:
|
|
|
|
seen_info = event["target"].get_user_setting(
|
2019-11-04 15:33:57 +00:00
|
|
|
user.get_id(), "seen-info", None)
|
2019-10-30 11:42:00 +00:00
|
|
|
if seen_info:
|
|
|
|
seen_info = " (%s%s)" % (seen_info["action"],
|
|
|
|
utils.consts.RESET)
|
2019-06-05 12:18:44 +00:00
|
|
|
|
2020-02-24 10:18:55 +00:00
|
|
|
since = utils.datetime.format.to_pretty_since(
|
2020-01-30 21:12:31 +00:00
|
|
|
time.time()-seen_seconds, max_units=2)
|
2019-06-05 12:18:44 +00:00
|
|
|
event["stdout"].write("%s was last seen %s ago%s" % (
|
2020-03-08 21:42:31 +00:00
|
|
|
user.nickname, since, seen_info or ""))
|
2016-03-29 11:56:58 +00:00
|
|
|
else:
|
|
|
|
event["stderr"].write("I have never seen %s before." % (
|
2020-03-08 21:42:31 +00:00
|
|
|
user.nickname))
|