From 07a63926c6c46fa52f3cc6bd8cf41b186ad15beb 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 fd94b939e02a261f6e1d0a1fbd88a43edc501495 Mon Sep 17 00:00:00 2001 From: dongfix Date: Thu, 30 Aug 2018 15:55:57 +0100 Subject: Add strax.py .strax command. --- modules/strax.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 modules/strax.py diff --git a/modules/strax.py b/modules/strax.py new file mode 100644 index 00000000..85abad54 --- /dev/null +++ b/modules/strax.py @@ -0,0 +1,33 @@ +import random + + +class Module(object): + def __init__(self, bot): + bot.events.on("received.command.strax").hook( + self.strax, help="Glory to the sontaran empire, through IRC!") + + 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"] + method_of_attack_an = ["acid-heavy", "immediate", "overwhelming", "unstoppable"] + type_of_attack = ["assault", "attack", "bombardment", "offensive", "barrage", "charge", "strike", "operation", + "manoeuvre", "blitzkrieg"] + attack_adjective = ["laser", "berserker", "acid", "armoured attack", "proton", + "three kinds of", "atomic", "toxic", "explosive", + "red-hot", "thermal", "automated fire", "cluster", + "enhanced germ", "energy-drink-fueled"] + attack_object = ["bees", "chainsaws", "marmots", "acid", "monkeys", "mines", "bombs", "snakes", "spiders", + "knives", "rockets", "sharks", "owls", "repurposed cybermats", "cannons", "alligators"] + attack_object_two = ["robots", "ninjas", "grenades", "a dolphin full of napalm", "acid", "dynamite", + "xenomorphs", "lots and lots of C4", "tactical nukes", "MacGyver", "bio-weapons", + "rocket launchers", "an elephant", "a memory worm for afterwards", "this pencil"] + + method_of_attack = " an " + random.choice(method_of_attack_an) if random.choice(1, + 2) == 1 else " a " + random.choice( + method_of_attack_a) + + suggestion = random.choice( + suggestion_greeting) + method_of_attack + " " + type_of_attack + " with " + attack_adjective + " " + attack_object + " and " + attack_object_two + "?" + + event["stdout"].write(suggestion) -- cgit v1.3.1-10-gc9f91