diff --git a/pyircbot/irccore.py b/pyircbot/irccore.py index 6af8aca..24b6690 100644 --- a/pyircbot/irccore.py +++ b/pyircbot/irccore.py @@ -88,13 +88,14 @@ class IRCCore(object): logging.info("Reconnecting in 3s...") await asyncio.sleep(3) - async def kill(self, message="Help! Another thread is killing me :("): + async def kill(self, message="Help! Another thread is killing me :(", forever=True): """Send quit message, flush queue, and close the socket :param message: Quit message to send before disconnecting :type message: str """ - self.alive = False + if forever: + self.alive = False self.act_QUIT(message) # TODO will this hang if the socket is having issues? await self.writer.drain() self.writer.close() diff --git a/pyircbot/modules/PingResponder.py b/pyircbot/modules/PingResponder.py index 3b3704c..addaa6b 100755 --- a/pyircbot/modules/PingResponder.py +++ b/pyircbot/modules/PingResponder.py @@ -59,6 +59,6 @@ class PingRespondTimer(Thread): sleep(5) if time() - self.lastping > self.master.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.master.bot.kill("Ping timeout", forever=False) self.reset() diff --git a/pyircbot/pyircbot.py b/pyircbot/pyircbot.py index 4f3eb64..b2ea7c7 100644 --- a/pyircbot/pyircbot.py +++ b/pyircbot/pyircbot.py @@ -92,16 +92,20 @@ class PyIRCBot(object): self.log.info("disconnect") self.kill(message=message) - def kill(self, message="Help! Another thread is killing me :("): - """Shut down the bot violently + def break_connection(self): + """Break the connection, e.g. in the case of an unresponsive server""" + + def kill(self, message="Help! Another thread is killing me :(", forever=True): + """Close the connection violently :param sys_exit: True causes sys.exit(0) to be called :type sys_exit: bool :param message: Quit message :type message: str """ - self.closeAllModules() - asyncio.run_coroutine_threadsafe(self.irc.kill(message=message), self.loop) + if forever: + self.closeAllModules() + asyncio.run_coroutine_threadsafe(self.irc.kill(message=message, forever=forever), self.loop) def initModules(self): """load modules specified in instance config"""