moved bot loop into bot class

This commit is contained in:
Luke Rogers 2013-10-02 13:43:01 +13:00
parent 7e4ea3a9ff
commit 1cc38cb139
2 changed files with 21 additions and 15 deletions

View file

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

View file

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