Browse Source

Minor cleanup, additions, and bugfixes

tags/v0.1^2
Ben Kurtovic 12 years ago
parent
commit
fbada5c69a
4 changed files with 22 additions and 12 deletions
  1. +13
    -8
      earwigbot/bot.py
  2. +7
    -2
      earwigbot/commands/restart.py
  3. +1
    -1
      earwigbot/commands/threads.py
  4. +1
    -1
      earwigbot/irc/connection.py

+ 13
- 8
earwigbot/bot.py View File

@@ -97,12 +97,12 @@ class Bot(object):
thread.daemon = True # Stop if other threads stop thread.daemon = True # Stop if other threads stop
thread.start() thread.start()


def _stop_irc_components(self):
def _stop_irc_components(self, msg):
"""Request the IRC frontend and watcher to stop if enabled.""" """Request the IRC frontend and watcher to stop if enabled."""
if self.frontend: if self.frontend:
self.frontend.stop()
self.frontend.stop(msg)
if self.watcher: if self.watcher:
self.watcher.stop()
self.watcher.stop(msg)


def run(self): def run(self):
"""Main entry point into running the bot. """Main entry point into running the bot.
@@ -126,7 +126,7 @@ class Bot(object):
Thread(name=name, target=self.watcher.loop).start() Thread(name=name, target=self.watcher.loop).start()
sleep(2) sleep(2)


def restart(self):
def restart(self, msg=None):
"""Reload config, commands, tasks, and safely restart IRC components. """Reload config, commands, tasks, and safely restart IRC components.


This is thread-safe, and it will gracefully stop IRC components before 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 without restarting the bot with bot.commands.load() or
bot.tasks.load(). These should not interfere with running components bot.tasks.load(). These should not interfere with running components
or tasks. or tasks.

If given, 'msg' will be used as our quit message.
""" """
self.logger.info("Restarting bot per request from owner") self.logger.info("Restarting bot per request from owner")
with self.component_lock: with self.component_lock:
self._stop_irc_components()
self._stop_irc_components(msg)
self.config.load() self.config.load()
self.commands.load() self.commands.load()
self.tasks.load() self.tasks.load()
self._start_irc_components() 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") self.logger.info("Shutting down bot")
with self.component_lock: with self.component_lock:
self._stop_irc_components()
self._stop_irc_components(msg)
self._keep_looping = False self._keep_looping = False

+ 7
- 2
earwigbot/commands/restart.py View File

@@ -38,9 +38,14 @@ class Command(BaseCommand):


if data.command == "restart": if data.command == "restart":
self.logger.info("Restarting bot per owner request") 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": elif data.command == "reload":
self.logger.info("Reloading IRC commands") self.logger.info("Reloading IRC commands")
self.bot.commands.load() 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.")

+ 1
- 1
earwigbot/commands/threads.py View File

@@ -76,7 +76,7 @@ class Command(BaseCommand):
for thread in threads: for thread in threads:
tname = thread.name tname = thread.name
if tname == "MainThread": if tname == "MainThread":
t = "\x0302MainThread\x0301 (id {1})"
t = "\x0302MainThread\x0301 (id {0})"
normal_threads.append(t.format(thread.ident)) normal_threads.append(t.format(thread.ident))
elif tname in self.config.components: elif tname in self.config.components:
t = "\x0302{0}\x0301 (id {1})" t = "\x0302{0}\x0301 (id {1})"


+ 1
- 1
earwigbot/irc/connection.py View File

@@ -124,7 +124,7 @@ class IRCConnection(object):
def quit(self, msg=None): def quit(self, msg=None):
"""Issue a quit message to the server.""" """Issue a quit message to the server."""
if msg: if msg:
self._send("QUIT {0}".format(msg))
self._send("QUIT :{0}".format(msg))
else: else:
self._send("QUIT") self._send("QUIT")




Loading…
Cancel
Save