bitbot-3.11-fork/modules/seen.py
jesopo 8c6ab17e57 give an Exports object (actually, ExportsContex object) to each module, to
facilitate things like !set and !channelset without using the events system
2018-09-02 19:54:45 +01:00

27 lines
995 B
Python

import time
import Utils
class Module(object):
def __init__(self, bot, events, exports):
events.on("received").on("message").on("channel"
).hook(self.channel_message)
events.on("received").on("command").on("seen").hook(
self.seen, min_args=1,
help="Find out when a user was last seen",
usage="<username>")
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:
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))
else:
event["stderr"].write("I have never seen %s before." % (
event["args_split"][0]))