stuff
This commit is contained in:
parent
bae3c819ca
commit
355f5ce2e6
5 changed files with 23 additions and 19 deletions
10
core/bot.py
10
core/bot.py
|
@ -32,12 +32,12 @@ def get_logger():
|
||||||
|
|
||||||
# stdout handler
|
# stdout handler
|
||||||
sh = logging.StreamHandler()
|
sh = logging.StreamHandler()
|
||||||
sh.setLevel(logging.INFO)
|
sh.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
# create a formatter and set the formatter for the handler.
|
# create a formatter and set the formatter for the handler.
|
||||||
frmt = logging.Formatter('%(asctime)s [%(levelname)s] %(message)s')
|
frmt = logging.Formatter('%(asctime)s [%(levelname)s] %(message)s')
|
||||||
fh.setFormatter(frmt)
|
fh.setFormatter(frmt)
|
||||||
simple_frmt = logging.Formatter('%(message)s')
|
simple_frmt = logging.Formatter('[%(levelname)s] %(message)s')
|
||||||
sh.setFormatter(simple_frmt)
|
sh.setFormatter(simple_frmt)
|
||||||
|
|
||||||
# add the Handlers to the logger
|
# add the Handlers to the logger
|
||||||
|
@ -99,23 +99,23 @@ class Bot(threading.Thread):
|
||||||
"""create the logger and config objects"""
|
"""create the logger and config objects"""
|
||||||
# logging
|
# logging
|
||||||
self.logger = get_logger()
|
self.logger = get_logger()
|
||||||
self.logger.debug("Logging engine started.")
|
self.logger.debug("Logging system ready.")
|
||||||
|
|
||||||
# data folder
|
# data folder
|
||||||
self.data_dir = os.path.abspath('persist')
|
self.data_dir = os.path.abspath('persist')
|
||||||
if not os.path.exists(self.data_dir):
|
if not os.path.exists(self.data_dir):
|
||||||
self.logger.debug("Data folder not found, creating.")
|
self.logger.debug("Data folder not found, creating.")
|
||||||
os.mkdir(self.data_dir)
|
os.mkdir(self.data_dir)
|
||||||
self.logger.debug("Created data folder.")
|
|
||||||
|
|
||||||
# config
|
# config
|
||||||
self.config = config.Config(self)
|
self.config = config.Config(self)
|
||||||
self.logger.debug("Config object created.")
|
self.logger.debug("Config system ready.")
|
||||||
|
|
||||||
# db
|
# db
|
||||||
engine = create_engine('sqlite:///cloudbot.db')
|
engine = create_engine('sqlite:///cloudbot.db')
|
||||||
db_factory = sessionmaker(bind=engine)
|
db_factory = sessionmaker(bind=engine)
|
||||||
self.db_session = scoped_session(db_factory)
|
self.db_session = scoped_session(db_factory)
|
||||||
|
self.logger.debug("Database system ready.")
|
||||||
|
|
||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
|
|
|
@ -70,8 +70,8 @@ class PluginLoader(object):
|
||||||
namespace = {}
|
namespace = {}
|
||||||
eval(code, namespace)
|
eval(code, namespace)
|
||||||
except Exception:
|
except Exception:
|
||||||
self.bot.logger.error("Error compiling {}:".format(filename))
|
self.bot.logger.exception("Error compiling {}:".format(filename))
|
||||||
self.bot.logger.error(traceback.format_exc())
|
#self.bot.logger.error(traceback.format_exc())
|
||||||
return
|
return
|
||||||
|
|
||||||
# remove plugins already loaded from this file
|
# remove plugins already loaded from this file
|
||||||
|
|
23
core/main.py
23
core/main.py
|
@ -53,7 +53,7 @@ class Input(dict):
|
||||||
self[key] = value
|
self[key] = value
|
||||||
|
|
||||||
|
|
||||||
def run(func, input):
|
def run(func, input, bot):
|
||||||
args = func._args
|
args = func._args
|
||||||
|
|
||||||
uses_db = 'db' in args and 'db' not in input
|
uses_db = 'db' in args and 'db' not in input
|
||||||
|
@ -68,12 +68,21 @@ def run(func, input):
|
||||||
if 'input' in args:
|
if 'input' in args:
|
||||||
input.input = input
|
input.input = input
|
||||||
if 0 in args:
|
if 0 in args:
|
||||||
out = func(input.inp, **input)
|
try:
|
||||||
|
out = func(input.inp, **input)
|
||||||
|
except:
|
||||||
|
bot.logger.exception("Error in plugin {}:".format(func._filename))
|
||||||
else:
|
else:
|
||||||
kw = dict((key, input[key]) for key in args if key in input)
|
kw = dict((key, input[key]) for key in args if key in input)
|
||||||
out = func(input.inp, **kw)
|
try:
|
||||||
|
out = func(input.inp, **kw)
|
||||||
|
except:
|
||||||
|
bot.logger.exception("Error in plugin {}:".format(func._filename))
|
||||||
else:
|
else:
|
||||||
out = func(input.inp)
|
try:
|
||||||
|
out = func(input.inp)
|
||||||
|
except:
|
||||||
|
bot.logger.exception("Error in plugin {}:".format(func._filename))
|
||||||
if out is not None:
|
if out is not None:
|
||||||
input.reply(unicode(out))
|
input.reply(unicode(out))
|
||||||
|
|
||||||
|
@ -114,9 +123,7 @@ class Handler(object):
|
||||||
try:
|
try:
|
||||||
run(self.func, input)
|
run(self.func, input)
|
||||||
except:
|
except:
|
||||||
import traceback
|
self.bot.logger.exception("Error in plugin {}:".format(self.Sfunc._filename))
|
||||||
|
|
||||||
traceback.print_exc()
|
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.input_queue.put(StopIteration)
|
self.input_queue.put(StopIteration)
|
||||||
|
@ -138,7 +145,7 @@ def dispatch(bot, input, kind, func, args, autohelp=False):
|
||||||
if func._thread:
|
if func._thread:
|
||||||
bot.threads[func].put(input)
|
bot.threads[func].put(input)
|
||||||
else:
|
else:
|
||||||
thread.start_new_thread(run, (func, input))
|
thread.start_new_thread(run, (func, input, bot))
|
||||||
|
|
||||||
|
|
||||||
def match_command(bot, command):
|
def match_command(bot, command):
|
||||||
|
|
|
@ -19,9 +19,6 @@ class PermissionManager(object):
|
||||||
self.perm_users = {}
|
self.perm_users = {}
|
||||||
|
|
||||||
self.reload()
|
self.reload()
|
||||||
print self.group_perms
|
|
||||||
print self.group_users
|
|
||||||
print self.perm_users
|
|
||||||
|
|
||||||
def reload(self):
|
def reload(self):
|
||||||
self.logger.info("Reloading permissions for {}.".format(self.conn.name))
|
self.logger.info("Reloading permissions for {}.".format(self.conn.name))
|
||||||
|
|
|
@ -113,4 +113,4 @@ def log(paraml, input=None, bot=None):
|
||||||
|
|
||||||
out = "{} {} {}".format(timestamp, input.chan, beau.encode('utf8', 'ignore'))
|
out = "{} {} {}".format(timestamp, input.chan, beau.encode('utf8', 'ignore'))
|
||||||
|
|
||||||
sys.stdout.write(out + os.linesep)
|
print out
|
||||||
|
|
Reference in a new issue