From 8f806a25940bd8eed2f89049be02f24f45f5a5c7 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 11 Jun 2021 12:42:06 +0300 Subject: [PATCH] Add warning if webapp is disabled when using @web decorators. Fixes #65 --- maubot/plugin_base.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/maubot/plugin_base.py b/maubot/plugin_base.py index 034ccef..65e2039 100644 --- a/maubot/plugin_base.py +++ b/maubot/plugin_base.py @@ -55,6 +55,7 @@ class Plugin(ABC): self._handlers_at_startup = [] def register_handler_class(self, obj) -> None: + warned_webapp = False for key in dir(obj): val = getattr(obj, key) try: @@ -65,10 +66,17 @@ class Plugin(ABC): pass try: web_handlers = val.__mb_web_handler__ - for method, path, kwargs in web_handlers: - self.webapp.add_route(method=method, path=path, handler=val, **kwargs) except AttributeError: pass + else: + if len(web_handlers) > 0 and self.webapp is None: + if not warned_webapp: + self.log.warning(f"{type(obj).__name__} has web handlers, but the webapp" + " feature isn't enabled in the plugin's maubot.yaml") + warned_webapp = True + continue + for method, path, kwargs in web_handlers: + self.webapp.add_route(method=method, path=path, handler=val, **kwargs) async def pre_start(self) -> None: pass