From c10a35b6c08d390ca413cf59aae77c0b1196c555 Mon Sep 17 00:00:00 2001 From: jesopo Date: Thu, 30 Aug 2018 14:32:59 +0100 Subject: Log exceptions when calling events --- EventManager.py | 6 ++---- IRCLogging.py | 24 ++++++++++++------------ 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/EventManager.py b/EventManager.py index abb0a454..66006934 100644 --- a/EventManager.py +++ b/EventManager.py @@ -137,10 +137,8 @@ class EventHook(object): returns.append(hook.call(event)) except Exception as e: traceback.print_exc() - # TODO don't make this an event call. can lead to error cycles! - #self.bot.events.on("log").on("error").call( - # message="Failed to call event callback", - # data=traceback.format_exc()) + self.bot.log.error("failed to call event \"%s", [ + event_path], exc_info=True) called += 1 end = time.monotonic() diff --git a/IRCLogging.py b/IRCLogging.py index 7b01acee..c2fbde1c 100644 --- a/IRCLogging.py +++ b/IRCLogging.py @@ -33,15 +33,15 @@ class Log(object): file_handler.setFormatter(formatter) self.logger.addHandler(file_handler) - def debug(self, message, params): - self._log(message, params, logging.DEBUG) - def info(self, message, params): - self._log(message, params, logging.INFO) - def warn(self, message, params): - self._log(message, params, logging.WARN) - def error(self, message, params): - self._log(message, params, logging.ERROR) - def critical(self, message, params): - self._log(message, params, logging.CRITICAL) - def _log(self, message, params, level): - self.logger.log(level, message, *params) + def debug(self, message, params, **kwargs): + self._log(message, params, logging.DEBUG, kwargs) + def info(self, message, params, **kwargs): + self._log(message, params, logging.INFO, kwargs) + def warn(self, message, params, **kwargs): + self._log(message, params, logging.WARN, kwargs) + def error(self, message, params, **kwargs): + self._log(message, params, logging.ERROR, kwargs) + def critical(self, message, params, **kwargs): + self._log(message, params, logging.CRITICAL, kwargs) + def _log(self, message, params, level, kwargs): + self.logger.log(level, message, *params, **kwargs) -- cgit v1.3.1-10-gc9f91 From a4d660068cd9f6a0b4972da08afe99d4641d4ca1 Mon Sep 17 00:00:00 2001 From: jesopo Date: Thu, 30 Aug 2018 16:07:33 +0100 Subject: Add missing comma in strax.py --- modules/strax.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/strax.py b/modules/strax.py index ebb67a2c..9b6e431b 100644 --- a/modules/strax.py +++ b/modules/strax.py @@ -9,7 +9,7 @@ class Module(object): def strax(self, event): suggestion_greeting = ["Might I suggest", "I'd suggest", "We should attack now with", "We must attack now with"] method_of_attack_a = ["full-frontal", "pincer", "surprise", "brutally excessive", "multi-pronged", "glorious", - "violent", "devestating" "superior"] + "violent", "devestating", "superior"] method_of_attack_an = ["acid-heavy", "immediate", "overwhelming", "unstoppable"] type_of_attack = ["assault", "attack", "bombardment", "offensive", "barrage", "charge", "strike", "operation", "manoeuvre", "blitzkrieg"] -- cgit v1.3.1-10-gc9f91 From b6eae3220c1869e092b68ec7e82a4a4324e39707 Mon Sep 17 00:00:00 2001 From: jesopo Date: Thu, 30 Aug 2018 17:08:21 +0100 Subject: Database.add_server -> Database.servers.add --- start.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/start.py b/start.py index e4a26986..403815fd 100755 --- a/start.py +++ b/start.py @@ -55,7 +55,7 @@ else: nickname = input("nickname: ") username = input("username: ") realname = input("realname: ") - database.add_server(hostname, port, password, ipv4, + database.servers.add(hostname, port, password, ipv4, tls, nickname, username, realname) except KeyboardInterrupt: print() -- cgit v1.3.1-10-gc9f91 From 656cb8153a5db981152b852373d728734f1c2e44 Mon Sep 17 00:00:00 2001 From: jesopo Date: Thu, 30 Aug 2018 17:20:55 +0100 Subject: return "None" timeouts when there's no servers in IRCBot.servers --- IRCBot.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/IRCBot.py b/IRCBot.py index f803d61d..185abf83 100644 --- a/IRCBot.py +++ b/IRCBot.py @@ -91,11 +91,15 @@ class Bot(object): timeouts = [] for server in self.servers.values(): timeouts.append(server.until_next_ping()) + if not timeouts: + return None return min(timeouts) def next_read_timeout(self): timeouts = [] for server in self.servers.values(): timeouts.append(server.until_read_timeout()) + if not timeouts: + return None return min(timeouts) def get_poll_timeout(self): -- cgit v1.3.1-10-gc9f91