Browse Source

Reset pingresponder timer on SEND activity

dave/xdcc
dave 5 years ago
parent
commit
1a95add107
  1. 6
      pyircbot/irccore.py
  2. 7
      pyircbot/modules/PingResponder.py

6
pyircbot/irccore.py

@ -134,11 +134,10 @@ class IRCCore(object):
self.fire_hook(command, args=args, prefix=prefix, trailing=trailing)
def sendRaw(self, data):
self.log.warning(">>> {}".format(repr(data)))
self.log.debug(">>> {}".format(repr(data)))
self.fire_hook('_SEND', args=None, prefix=None, trailing=None)
self.writer.write((data + "\r\n").encode("UTF-8"))
" Module related code "
def initHooks(self):
"""Defines hooks that modules can listen for events of"""
@ -146,6 +145,7 @@ class IRCCore(object):
'_CONNECT',
'_DISCONNECT',
'_RECV',
'_SEND',
'NOTICE',
'MODE',
'PING',

7
pyircbot/modules/PingResponder.py

@ -18,7 +18,8 @@ class PingResponder(ModuleBase):
self.timer = PingRespondTimer(self)
self.hooks = [
ModuleHook("PING", self.pingrespond),
ModuleHook("_RECV", self.resettimer)
ModuleHook("_RECV", self.resettimer),
ModuleHook("_SEND", self.resettimer)
]
def pingrespond(self, args, prefix, trailing):
@ -56,8 +57,8 @@ class PingRespondTimer(Thread):
def run(self):
while self.alive:
sleep(5)
if time() - self.lastping > 300: # TODO: configurable timeout
self.master.log.info("No pings in %s seconds. Reconnecting" % str(time() - self.lastping))
if time() - self.lastping > self.config.get("activity_timeout", 300):
self.master.log.info("No activity in %s seconds. Reconnecting" % str(time() - self.lastping))
self.master.bot.disconnect("Reconnecting...")
self.reset()

Loading…
Cancel
Save