From 4c5087773d1659389d514417e98826ca76947872 Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Sun, 1 Dec 2013 22:52:33 +1300 Subject: [PATCH] refresh works vaugely better --- core/bot.py | 2 +- core/irc.py | 2 +- core/main.py | 16 +++++++++------- plugins/log.py | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/core/bot.py b/core/bot.py index 6994523..25accd4 100644 --- a/core/bot.py +++ b/core/bot.py @@ -28,7 +28,7 @@ def get_logger(): # add a file handler log_name = "bot.log" fh = logging.FileHandler(log_name) - fh.setLevel(logging.DEBUG) + fh.setLevel(logging.INFO) # stdout handler sh = logging.StreamHandler() diff --git a/core/irc.py b/core/irc.py index 39958bb..cbce685 100644 --- a/core/irc.py +++ b/core/irc.py @@ -106,7 +106,7 @@ class SendThread(threading.Thread): def run(self): while not self.shutdown: line = self.output_queue.get().splitlines()[0][:500] - print u"{}> {}".format(self.conn_name, line) + #print u"{}> {}".format(self.conn_name, line) self.output_buffer += line.encode('utf-8', 'replace') + '\r\n' while self.output_buffer: sent = self.socket.send(self.output_buffer) diff --git a/core/main.py b/core/main.py index 52ed9c2..a394816 100644 --- a/core/main.py +++ b/core/main.py @@ -53,7 +53,7 @@ class Input(dict): self[key] = value -def run(func, input, bot): +def run(bot, func, input): args = func._args uses_db = 'db' in args and 'db' not in input @@ -72,17 +72,20 @@ def run(func, input, bot): out = func(input.inp, **input) except: bot.logger.exception("Error in plugin {}:".format(func._filename)) + return else: kw = dict((key, input[key]) for key in args if key in input) try: out = func(input.inp, **kw) except: bot.logger.exception("Error in plugin {}:".format(func._filename)) + return else: try: out = func(input.inp) except: bot.logger.exception("Error in plugin {}:".format(func._filename)) + return if out is not None: input.reply(unicode(out)) @@ -95,8 +98,7 @@ def do_sieve(sieve, bot, input, func, type, args): try: return sieve(bot, input, func, type, args) except Exception: - print 'sieve error', - traceback.print_exc() + bot.logger.exception("Error in sieve {}:".format(func._filename)) return None @@ -118,12 +120,12 @@ class Handler(object): break if uses_db: - input.db = self.bot.db + input.db = None try: - run(self.func, input) + run(self.bot, self.func, input) except: - self.bot.logger.exception("Error in plugin {}:".format(self.Sfunc._filename)) + self.bot.logger.exception("Error in plugin {}:".format(self.func._filename)) def stop(self): self.input_queue.put(StopIteration) @@ -145,7 +147,7 @@ def dispatch(bot, input, kind, func, args, autohelp=False): if func._thread: bot.threads[func].put(input) else: - thread.start_new_thread(run, (func, input, bot)) + thread.start_new_thread(run, (bot, func, input)) def match_command(bot, command): diff --git a/plugins/log.py b/plugins/log.py index ef783fd..bec41b3 100644 --- a/plugins/log.py +++ b/plugins/log.py @@ -113,4 +113,4 @@ def log(paraml, input=None, bot=None): out = "{} {} {}".format(timestamp, input.chan, beau.encode('utf8', 'ignore')) - print out + bot.logger.debug(out)