diff --git a/cloudbot.py b/cloudbot.py index b0a930b..5d627c3 100644 --- a/cloudbot.py +++ b/cloudbot.py @@ -1,12 +1,9 @@ #!/usr/bin/env python # we import bot as _bot for now, for legacy reasons from core import bot as _bot -from core import loader, main import os -import Queue import sys -import time # set up enviroment os.chdir(sys.path[0] or '.') # do stuff relative to the install directory @@ -19,13 +16,4 @@ bot.logger.debug("Bot initalized.") bot.logger.debug("Starting main loop.") while True: - loader.reload(bot) # these functions only do things - - for connection in bot.connections.itervalues(): - try: - out = connection.out.get_nowait() - main.main(bot, connection, out) - except Queue.Empty: - pass - while all(connection.out.empty() for connection in bot.connections.itervalues()): - time.sleep(.1) + bot.loop() diff --git a/core/bot.py b/core/bot.py index 40f9a73..8f3bbef 100644 --- a/core/bot.py +++ b/core/bot.py @@ -2,8 +2,9 @@ import time import logging import re import os +import Queue -from core import config, irc, loader +from core import config, irc, loader, main def clean_name(n): @@ -26,8 +27,25 @@ class Bot(object): self.connect() # run plugin loader - self.logger.debug("Bootstrapping reloader.") + self.logger.debug("Starting plugin reloader.") loader.reload(self, init=True) + self.logger.debug("Plugin reloader started.") + + + def loop(self): + """reloads plugins, then recives input from the IRC engine and processes it""" + loader.reload(self) # TODO: new plugin loader + + for connection in self.connections.itervalues(): + try: + incoming = connection.out.get_nowait() + main.main(self, connection, incoming) + except Queue.Empty: + pass + + # if no messages are in the incoming queue, sleep + while all(connection.out.empty() for connection in self.connections.itervalues()): + time.sleep(.1) def connect(self):