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.
This commit is contained in:
parent
d23ef4ae66
commit
bf59265e94
20
bot.py
20
bot.py
|
@ -49,13 +49,19 @@ class CosmicBot(teambot.Handler):
|
||||||
self.load_modules()
|
self.load_modules()
|
||||||
self.tasks.run()
|
self.tasks.run()
|
||||||
def check_rss(self,state,base_state):
|
def check_rss(self,state,base_state):
|
||||||
newtrans = rss.fetchNew(state["url"],[x["guid"] for x in state["known"]])
|
try:
|
||||||
if newtrans:
|
newtrans = rss.fetchNew(state["url"],[x["guid"] for x in state["known"]])
|
||||||
state["known"].extend(newpost(x) for x in newtrans)
|
if newtrans:
|
||||||
for trans in newtrans:
|
state["known"].extend(newpost(x) for x in newtrans)
|
||||||
self.say(state["channel"],"Transmission received: {transmission.title} ({transmission.link})".format(transmission=trans))
|
for trans in newtrans:
|
||||||
toot.toot("Transmission received: {transmission.title}\n\n{transmission.link}".format(transmission=trans))
|
self.say(state["channel"],"Transmission received: {transmission.title} ({transmission.link})".format(transmission=trans))
|
||||||
time.sleep(1)
|
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
|
return state
|
||||||
def on_pubmsg(self,channel,nick,text):
|
def on_pubmsg(self,channel,nick,text):
|
||||||
self.is_admin = self.event.source.userhost == bot_op
|
self.is_admin = self.event.source.userhost == bot_op
|
||||||
|
|
Loading…
Reference in New Issue