Просмотр исходного кода

Minor cleanup, additions, and bugfixes

tags/v0.1^2
Ben Kurtovic 12 лет назад
Родитель
Сommit
fbada5c69a
4 измененных файлов: 22 добавлений и 12 удалений
  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 Просмотреть файл

@@ -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

+ 7
- 2
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.")

+ 1
- 1
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})"


+ 1
- 1
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")



Загрузка…
Отмена
Сохранить