journee_mondiale: do not crash if text not found

This commit is contained in:
dece 2021-12-02 11:36:30 +01:00
parent 6b9430aabb
commit 1e9f10d549

View file

@ -19,16 +19,21 @@ class JourneeMondialePlugin(Plugin):
def on_pubmsg(self, event):
if not self.should_handle_command(event.arguments[0], no_content=True):
return False
response = http_get(self.config["url"])
if not response:
self.signal_failure(event.target)
return True
soup = BeautifulSoup(response, "html.parser")
try:
jm = soup.find("div", id="journeesDuJour").find("h2").string
except (ValueError, KeyError):
self.signal_failure(event.target)
return True
if jm:
self.bot.say(event.target, jm)
else:
self.signal_failure(event.target)
return True