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()