def check_and_answer(self, event, private): text = ascii_me(event.arguments[0]) source = event.source.nick if (source == self.owner and text == "%s: feeling better?" % self.nickname): self.reload_modules() print '\n\n reloading %s\n\n' % self.nickname self.broken = False elif not self.broken: try: messages = self.decide_what_to_say(source, text) except Exception as thisbroke: self.message(self.owner, "halp") print ("%s had an error of type %s: %s" % (self.nickname, type(thisbroke), thisbroke)) self.broken = True messages = [] for count, message in enumerate(messages): if not self.talk: break sleep(min(1.5, 0.3 * count)) try: if private: self.message(source, ascii_me(message)) else: self.message(self.channel, ascii_me(message)) except UnicodeDecodeError as error: print 'UnicodeDecodeError' print error print ascii_me(message) if private: self.message(source, 'derp; this is not ascii') else: self.message(self.channel, 'derp; this is not ascii')
def check_and_answer(self, event, private): text = ascii_me(event.arguments[0]) source = event.source.nick if (source == self.owner and text == "%s: feeling better?" % self.nickname): try: print '\n\n reloading decision module\n\n' reload(bot_action_decision) self.broken = False except Exception as thisbroke: self.message(self.owner, "halp reloading") print ("%s had an error of type %s: %s (in the reload action)" % (self.nickname, type(thisbroke), thisbroke)) self.broken = True elif not self.broken: try: target, messages = bot_action_decision.actions(self, source, text, private) except Exception as thisbroke: self.message(self.owner, "halp") try: error = ("%s had an error of type %s: %s (in the decision thread)" % (self.nickname, type(thisbroke), thisbroke)) print error self.message(self.owner, error) except: print 'had some trouble with the error logging' try: traceback = format_exc(thisbroke).split('\n') print tracebook self.message(self.owner, traceback) except: print 'had some trouble with the traceback' self.broken = True else: if target: self.messenger.messenger.add_to_queue(target, messages)
def send_message_with_exception_catch(self, target, message): if message: try: self.message(target, ascii_me(message)) except UnicodeDecodeError as error: print 'UnicodeDecodeError' print error print [message] raise except Exception as thisbroke: self.message(irc_connection.owner, "halp") print ("%s had an error of type %s: %s (in the messenger thread)" % (self.nickname, type(thisbroke), thisbroke))
def check_and_answer(self, event, private): text = ascii_me(event.arguments[0]) source = event.source.nick if (source == self.owner and text == "%s: feeling better?" % self.nickname): try: print '\n\n reloading decision module\n\n' reload(bot_action_decision) self.broken = False except Exception as thisbroke: self.raw_message(self.owner, "halp reloading") self.message_broken(thisbroke) elif not self.broken: try: target, messages = bot_action_decision.actions(self, source, text, private) except Exception as thisbroke: self.raw_message(self.owner, 'halp') self.message_broken(thisbroke) else: if target: self.message(target, messages)