This commit is contained in:
Luke Rogers 2013-11-09 20:31:16 +13:00
parent fbb6204f83
commit 926b8c3f05
2 changed files with 18 additions and 15 deletions

View file

@ -31,19 +31,19 @@ def exit_gracefully(signum, frame):
original_sigint = signal.getsignal(signal.SIGINT) original_sigint = signal.getsignal(signal.SIGINT)
signal.signal(signal.SIGINT, exit_gracefully) signal.signal(signal.SIGINT, exit_gracefully)
# create new bot object # create a bot thread and start it
cloudbot = bot.Bot() cloudbot = bot.Bot()
cloudbot.start()
cloudbot.run() # watch to see if the bot stops running or needs a restart
while True:
# wait for the bot loop to stop if cloudbot.running:
time.sleep(.1)
if cloudbot.do_restart:
# this kills the bot
# TODO: make it not just kill the bot
time.sleep(2)
sys.exit()
else: else:
print "wtf" if cloudbot.do_restart:
time.sleep(2) # create a new bot thread and start it
sys.exit() cloudbot = bot.Bot()
cloudbot.start()
continue
else:
break

View file

@ -4,6 +4,7 @@ import re
import os import os
import Queue import Queue
import collections import collections
import threading
from sqlalchemy.orm import scoped_session, sessionmaker from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy import create_engine from sqlalchemy import create_engine
@ -45,7 +46,7 @@ def get_logger():
return logger return logger
class Bot(object): class Bot(threading.Thread):
def __init__(self): def __init__(self):
# basic variables # basic variables
self.start_time = time.time() self.start_time = time.time()
@ -71,6 +72,8 @@ class Bot(object):
self.loader = PluginLoader(self) self.loader = PluginLoader(self)
threading.Thread.__init__(self)
def run(self): def run(self):
"""recieves input from the IRC engine and processes it""" """recieves input from the IRC engine and processes it"""