From 8d9ccd8dc9e69d7776fdf29232a613321ce648ea Mon Sep 17 00:00:00 2001 From: dece Date: Sun, 4 Sep 2022 15:27:13 +0200 Subject: [PATCH] wikipedia: fix crash --- edmond/plugin.py | 14 +++++++------- edmond/plugins/wikipedia.py | 10 ++++++---- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/edmond/plugin.py b/edmond/plugin.py index f267c95..d31c428 100644 --- a/edmond/plugin.py +++ b/edmond/plugin.py @@ -37,13 +37,13 @@ class Plugin: plugins. It can also save data using the Bot's storage feature to be available after a restart. - Initalisation should be very fast, no network connections or anything. They - are initialised before connecting to the server, so their `is_ready` flag - is set at that point. The loading order is more or less random, so a plugin - cannot assume another has been loaded during initialisation. If it wants to - interact with another plugin, the earliest point to do that is in the - on_welcome callback which is called after connecting to a server, and can - disable itself by setting its own `is_ready` flag to false. + Initialisation should be very fast, no network connections or anything. + They are initialised before connecting to the server, so their `is_ready` + flag is set at that point. The loading order is more or less random, so a + plugin cannot assume another has been loaded during initialisation. If it + wants to interact with another plugin, the earliest point to do that is in + the on_welcome callback which is called after connecting to a server, and + can disable itself by setting its own `is_ready` flag to false. A plugin can access its config once the base `__init__` has been called. The configuration is valid only is `is_ready` is True, else accessing its diff --git a/edmond/plugins/wikipedia.py b/edmond/plugins/wikipedia.py index 5d46427..a6c7c3c 100644 --- a/edmond/plugins/wikipedia.py +++ b/edmond/plugins/wikipedia.py @@ -38,14 +38,16 @@ class WikipediaPlugin(Plugin): return True def tell_random_summary(self, event): - summary = "" + page = None retries = self.NUM_RETRIES while retries > 0: try: - page = wikipedia.page(title=wikipedia.random(), sentences=1) + page = wikipedia.page(title=wikipedia.random()) break - except: # The wikipedia package can raise a lot of different stuff. - pass + except Exception as exc: + # The wikipedia package can raise a lot of different stuff, + # so we sort of have to catch broadly. + self.bot.log_d(f"Wikipedia exception: {exc}") retries -= 1 if page: if plus_plugin := self.bot.get_plugin("plus"):