moved bot loop into bot class
This commit is contained in:
parent
7e4ea3a9ff
commit
1cc38cb139
2 changed files with 21 additions and 15 deletions
14
cloudbot.py
14
cloudbot.py
|
@ -1,12 +1,9 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# we import bot as _bot for now, for legacy reasons
|
# we import bot as _bot for now, for legacy reasons
|
||||||
from core import bot as _bot
|
from core import bot as _bot
|
||||||
from core import loader, main
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import Queue
|
|
||||||
import sys
|
import sys
|
||||||
import time
|
|
||||||
|
|
||||||
# set up enviroment
|
# set up enviroment
|
||||||
os.chdir(sys.path[0] or '.') # do stuff relative to the install directory
|
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.")
|
bot.logger.debug("Starting main loop.")
|
||||||
while True:
|
while True:
|
||||||
loader.reload(bot) # these functions only do things
|
bot.loop()
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
22
core/bot.py
22
core/bot.py
|
@ -2,8 +2,9 @@ import time
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
|
import Queue
|
||||||
|
|
||||||
from core import config, irc, loader
|
from core import config, irc, loader, main
|
||||||
|
|
||||||
|
|
||||||
def clean_name(n):
|
def clean_name(n):
|
||||||
|
@ -26,8 +27,25 @@ class Bot(object):
|
||||||
self.connect()
|
self.connect()
|
||||||
|
|
||||||
# run plugin loader
|
# run plugin loader
|
||||||
self.logger.debug("Bootstrapping reloader.")
|
self.logger.debug("Starting plugin reloader.")
|
||||||
loader.reload(self, init=True)
|
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):
|
def connect(self):
|
||||||
|
|
Reference in a new issue