added callbacks for whois idle time, .updick works on others now
This commit is contained in:
parent
4140f52c69
commit
76ad41ec48
22
bot.py
22
bot.py
|
@ -476,6 +476,18 @@ class Fulvia(irc.IRCClient):
|
||||||
self.realname = realname
|
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
|
## User commands, from client->server
|
||||||
|
|
||||||
def msg(self, user, message, length=None):
|
def msg(self, user, message, length=None):
|
||||||
|
@ -570,12 +582,20 @@ class Fulvia(irc.IRCClient):
|
||||||
def irc_RPL_WHOISUSER(self, prefix, params):
|
def irc_RPL_WHOISUSER(self, prefix, params):
|
||||||
"""
|
"""
|
||||||
Called when we receive the server's response from our "WHOIS [user]"
|
Called when we receive the server's response from our "WHOIS [user]"
|
||||||
query.
|
query. Contains hostmask information.
|
||||||
"""
|
"""
|
||||||
_, nick, ident, host, _, realname = params
|
_, nick, ident, host, _, realname = params
|
||||||
self.whoisUser(nick, ident, host, realname)
|
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():
|
class FulviaWrapper():
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -4,12 +4,15 @@ How long the bot has been running.
|
||||||
"""
|
"""
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
from twisted.internet import defer
|
||||||
|
|
||||||
from module import commands
|
from module import commands
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
if "uptime" not in bot.memory:
|
if "uptime" not in bot.memory:
|
||||||
bot.memory["uptime"] = datetime.datetime.now()
|
bot.memory["uptime"] = datetime.datetime.now()
|
||||||
|
bot.memory["idle_callbacks"] = {}
|
||||||
|
|
||||||
|
|
||||||
@commands('uptime')
|
@commands('uptime')
|
||||||
|
@ -23,5 +26,22 @@ def uptime(bot, trigger):
|
||||||
@commands('updick')
|
@commands('updick')
|
||||||
def updick(bot, trigger):
|
def updick(bot, trigger):
|
||||||
""".updick - Returns the uptime of Fulvia, measured in dicks."""
|
""".updick - Returns the uptime of Fulvia, measured in dicks."""
|
||||||
|
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"]
|
delta = datetime.datetime.now() - bot.memory["uptime"]
|
||||||
bot.msg("8" + "="*delta.days + "D")
|
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")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user