From 8b0bd510f902a035faac122d6c2ddfa902ad68c6 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sat, 13 Jul 2019 15:48:13 +0300 Subject: [PATCH] Stop requiring super call to activate event handlers in plugin start/stop methods --- maubot/instance.py | 4 ++-- maubot/plugin_base.py | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/maubot/instance.py b/maubot/instance.py index 11b5da6..e883ba7 100644 --- a/maubot/instance.py +++ b/maubot/instance.py @@ -173,7 +173,7 @@ class PluginInstance: database=self.inst_db, webapp=self.inst_webapp, webapp_url=self.inst_webapp_url) try: - await self.plugin.start() + await self.plugin.internal_start() except Exception: self.log.exception("Failed to start instance") self.db_instance.enabled = False @@ -190,7 +190,7 @@ class PluginInstance: self.log.debug("Stopping plugin instance...") self.started = False try: - await self.plugin.stop() + await self.plugin.internal_stop() except Exception: self.log.exception("Failed to stop instance") self.plugin = None diff --git a/maubot/plugin_base.py b/maubot/plugin_base.py index 1033756..3793f0f 100644 --- a/maubot/plugin_base.py +++ b/maubot/plugin_base.py @@ -52,7 +52,7 @@ class Plugin(ABC): self.webapp_url = webapp_url self._handlers_at_startup = [] - async def start(self) -> None: + async def internal_start(self) -> None: for key in dir(self): val = getattr(self, key) try: @@ -67,12 +67,20 @@ class Plugin(ABC): self.webapp.add_route(method=method, path=path, handler=val, **kwargs) except AttributeError: pass + await self.start() - async def stop(self) -> None: + async def start(self) -> None: + pass + + async def internal_stop(self) -> None: for func, event_type in self._handlers_at_startup: self.client.remove_event_handler(event_type, func) if self.webapp is not None: self.webapp.clear() + await self.stop() + + async def stop(self) -> None: + pass @classmethod def get_config_class(cls) -> Optional[Type['BaseProxyConfig']]: