From 03f0011e623f4adc4fd4a9e9c045a48591dab15d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Sat, 20 Jan 2018 16:54:13 +0200 Subject: [PATCH] Add botcmd.on_quit hook for bot cleanup --- botcmd.py | 7 +++++++ ircbot.py | 3 +++ 2 files changed, 10 insertions(+) diff --git a/botcmd.py b/botcmd.py index ce409f2..25dbce8 100644 --- a/botcmd.py +++ b/botcmd.py @@ -12,6 +12,13 @@ def initialize(*, config): def on_connect(*, irc): ... +# on_quit(*, irc) +# Called just before IRC bot sends QUIT +# Blocks the bot until it's done, including PING/PONG handling +# irc is the IRC API object +def on_quit(*, irc): + ... + # handle_message(*, prefix, message, nick, channel, irc) # Called for PRIVMSGs. # prefix is the prefix at the start of the message, without the leading ':' diff --git a/ircbot.py b/ircbot.py index 17b602c..0320f11 100644 --- a/ircbot.py +++ b/ircbot.py @@ -307,6 +307,9 @@ class ServerThread(threading.Thread): reconnecting = self.mainloop() if not reconnecting: + # Run bot cleanup code + botcmd.on_quit(irc = self.api) + # Tell the server we're quiting self.send_line_raw(b'QUIT :%s exiting normally' % self.server.username.encode('utf-8')) self.server_socket.close()