From 76ad41ec48b31d427bfef4a5f3cbd38ec6a127bb Mon Sep 17 00:00:00 2001 From: iou1name Date: Tue, 29 May 2018 17:41:47 -0400 Subject: [PATCH] added callbacks for whois idle time, .updick works on others now --- bot.py | 22 +++++++++++++++++++++- modules/uptime.py | 22 +++++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/bot.py b/bot.py index a73f112..feaf420 100755 --- a/bot.py +++ b/bot.py @@ -474,6 +474,18 @@ class Fulvia(irc.IRCClient): self.username = ident self.host = host self.realname = realname + + + def whoisIdle(self, nick, idle, signon): + """ + Called when the bot receives a WHOIS about a particular user. + nick - nickname of the user + idle - seconds since last activity from user + signon - unix timestamp when user signed on + """ + if self.memory.get("idle_callbacks"): + self.memory["idle_callbacks"][nick].callback((nick, idle, signon)) + self.memory["idle_callbacks"].pop(nick) ## User commands, from client->server @@ -570,12 +582,20 @@ class Fulvia(irc.IRCClient): def irc_RPL_WHOISUSER(self, prefix, params): """ Called when we receive the server's response from our "WHOIS [user]" - query. + query. Contains hostmask information. """ _, nick, ident, host, _, realname = params self.whoisUser(nick, ident, host, realname) + def irc_RPL_WHOISIDLE(self, prefix, params): + """ + Called when we receive the server's response from our "WHOIS [user]" + query. Contains idle and signon time information. + """ + _, nick, idle, signon, _ = params + self.whoisIdle(nick, idle, signon) + class FulviaWrapper(): """ diff --git a/modules/uptime.py b/modules/uptime.py index 0ec464f..6d6ce0f 100755 --- a/modules/uptime.py +++ b/modules/uptime.py @@ -4,12 +4,15 @@ How long the bot has been running. """ import datetime +from twisted.internet import defer + from module import commands def setup(bot): if "uptime" not in bot.memory: bot.memory["uptime"] = datetime.datetime.now() + bot.memory["idle_callbacks"] = {} @commands('uptime') @@ -23,5 +26,22 @@ def uptime(bot, trigger): @commands('updick') def updick(bot, trigger): """.updick - Returns the uptime of Fulvia, measured in dicks.""" - delta = datetime.datetime.now() - bot.memory["uptime"] + if trigger.group(2): + if trigger.group(2) in bot.users: + d = defer.Deferred() + d.addCallback(idleTime, bot) + bot.memory["idle_callbacks"][trigger.group(2)] = d + bot.whois(trigger.group(2)) + else: + delta = datetime.datetime.now() - bot.memory["uptime"] + bot.msg("8" + "="*delta.days + "D") + + +def idleTime(result, bot): + """ + result - tuple containing (nick, idle, signon) + """ + nick, idle, signon = result + t = datetime.datetime.fromtimestamp(int(signon)) + delta = datetime.datetime.now() - t bot.msg("8" + "="*delta.days + "D")