Fix ping responder module

This commit is contained in:
Dave Pedu 2015-12-13 13:40:53 -08:00
parent dd171d568a
commit 89e4a56d44
1 changed files with 14 additions and 1 deletions

View File

@ -15,16 +15,29 @@ class PingResponder(ModuleBase):
def __init__(self, bot, moduleName): def __init__(self, bot, moduleName):
ModuleBase.__init__(self, bot, moduleName); ModuleBase.__init__(self, bot, moduleName);
self.timer = PingRespondTimer(self) self.timer = PingRespondTimer(self)
self.hooks=[ModuleHook("PING", self.pingrespond)] self.hooks=[
ModuleHook("PING", self.pingrespond),
ModuleHook("_RECV", self.resettimer)
]
def pingrespond(self, args, prefix, trailing): def pingrespond(self, args, prefix, trailing):
"""Respond to the PING command""" """Respond to the PING command"""
# got a ping? send it right back # got a ping? send it right back
self.bot.act_PONG(trailing) self.bot.act_PONG(trailing)
self.log.info("%s Responded to a ping: %s" % (self.bot.get_nick(), trailing)) self.log.info("%s Responded to a ping: %s" % (self.bot.get_nick(), trailing))
def resettimer(self, msg):
"""Resets the connection failure timer"""
self.timer.reset() self.timer.reset()
def ondisable(self): def ondisable(self):
self.timer.disable() self.timer.disable()
class PingRespondTimer(Thread): class PingRespondTimer(Thread):
"Tracks last ping from server, and reconnects if over a threshold" "Tracks last ping from server, and reconnects if over a threshold"
def __init__(self, master): def __init__(self, master):