From bf59265e94e3b7dfcaba33902bc8654c25f28c6a Mon Sep 17 00:00:00 2001 From: khuxkm fbexl Date: Wed, 16 Sep 2020 17:01:53 +0000 Subject: [PATCH] Wrap CosmicBot.check_rss in a try-except block This prevents cosmicbot's RSS checking thread from crashing if the RSS feed ends up malformed for any reason. --- bot.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/bot.py b/bot.py index bb84713..5537bb8 100644 --- a/bot.py +++ b/bot.py @@ -49,13 +49,19 @@ class CosmicBot(teambot.Handler): self.load_modules() self.tasks.run() def check_rss(self,state,base_state): - newtrans = rss.fetchNew(state["url"],[x["guid"] for x in state["known"]]) - if newtrans: - state["known"].extend(newpost(x) for x in newtrans) - for trans in newtrans: - self.say(state["channel"],"Transmission received: {transmission.title} ({transmission.link})".format(transmission=trans)) - toot.toot("Transmission received: {transmission.title}\n\n{transmission.link}".format(transmission=trans)) - time.sleep(1) + try: + newtrans = rss.fetchNew(state["url"],[x["guid"] for x in state["known"]]) + if newtrans: + state["known"].extend(newpost(x) for x in newtrans) + for trans in newtrans: + self.say(state["channel"],"Transmission received: {transmission.title} ({transmission.link})".format(transmission=trans)) + toot.toot("Transmission received: {transmission.title}\n\n{transmission.link}".format(transmission=trans)) + time.sleep(1) + except: + print("Error occurred while loading feed, will try again...") + print("Traceback is below:") + traceback.print_exc() + pass return state def on_pubmsg(self,channel,nick,text): self.is_admin = self.event.source.userhost == bot_op