diff --git a/earwigbot/bot.py b/earwigbot/bot.py index 9a1bc79..1f23d5b 100644 --- a/earwigbot/bot.py +++ b/earwigbot/bot.py @@ -97,12 +97,12 @@ class Bot(object): thread.daemon = True # Stop if other threads stop thread.start() - def _stop_irc_components(self): + def _stop_irc_components(self, msg): """Request the IRC frontend and watcher to stop if enabled.""" if self.frontend: - self.frontend.stop() + self.frontend.stop(msg) if self.watcher: - self.watcher.stop() + self.watcher.stop(msg) def run(self): """Main entry point into running the bot. @@ -126,7 +126,7 @@ class Bot(object): Thread(name=name, target=self.watcher.loop).start() sleep(2) - def restart(self): + def restart(self, msg=None): """Reload config, commands, tasks, and safely restart IRC components. This is thread-safe, and it will gracefully stop IRC components before @@ -134,18 +134,23 @@ class Bot(object): without restarting the bot with bot.commands.load() or bot.tasks.load(). These should not interfere with running components or tasks. + + If given, 'msg' will be used as our quit message. """ self.logger.info("Restarting bot per request from owner") with self.component_lock: - self._stop_irc_components() + self._stop_irc_components(msg) self.config.load() self.commands.load() self.tasks.load() self._start_irc_components() - def stop(self): - """Gracefully stop all bot components.""" + def stop(self, msg=None): + """Gracefully stop all bot components. + + If given, 'msg' will be used as our quit message. + """ self.logger.info("Shutting down bot") with self.component_lock: - self._stop_irc_components() + self._stop_irc_components(msg) self._keep_looping = False diff --git a/earwigbot/commands/restart.py b/earwigbot/commands/restart.py index 8756fe1..2e15c9c 100644 --- a/earwigbot/commands/restart.py +++ b/earwigbot/commands/restart.py @@ -38,9 +38,14 @@ class Command(BaseCommand): if data.command == "restart": self.logger.info("Restarting bot per owner request") - self.bot.restart() + if data.args: + self.bot.restart(" ".join(data.args)) + else: + self.bot.restart() elif data.command == "reload": self.logger.info("Reloading IRC commands") self.bot.commands.load() - self.connection.reply("IRC commands reloaded.") + self.logger.info("Reloading bot tasks") + self.bot.tasks.load() + self.connection.reply("IRC commands and bot tasks reloaded.") diff --git a/earwigbot/commands/threads.py b/earwigbot/commands/threads.py index bfe894b..4f66cb6 100644 --- a/earwigbot/commands/threads.py +++ b/earwigbot/commands/threads.py @@ -76,7 +76,7 @@ class Command(BaseCommand): for thread in threads: tname = thread.name if tname == "MainThread": - t = "\x0302MainThread\x0301 (id {1})" + t = "\x0302MainThread\x0301 (id {0})" normal_threads.append(t.format(thread.ident)) elif tname in self.config.components: t = "\x0302{0}\x0301 (id {1})" diff --git a/earwigbot/irc/connection.py b/earwigbot/irc/connection.py index 62b0455..c733df1 100644 --- a/earwigbot/irc/connection.py +++ b/earwigbot/irc/connection.py @@ -124,7 +124,7 @@ class IRCConnection(object): def quit(self, msg=None): """Issue a quit message to the server.""" if msg: - self._send("QUIT {0}".format(msg)) + self._send("QUIT :{0}".format(msg)) else: self._send("QUIT")