diff options
| author | 2019-11-04 10:52:41 +0000 | |
|---|---|---|
| committer | 2019-11-04 10:52:41 +0000 | |
| commit | bcdffacab5625ee1fcf4645440c7a77f0434c7ed (patch) | |
| tree | a91b5fe75e54e3d380b97d66477fc457109bd15e /modules | |
| parent | change labeled-response WARN logging to DEBUG - it's mostly unimportant (diff) | |
| signature | ||
add on_pause() and on_resume() for module - use in rest_api.py
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/rest_api.py | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/modules/rest_api.py b/modules/rest_api.py index 7542a607..0f3a1d2e 100644 --- a/modules/rest_api.py +++ b/modules/rest_api.py @@ -175,17 +175,27 @@ class Module(ModuleManager.BaseModule): self.httpd = None if self.bot.get_setting("rest-api", False): - port = int(self.bot.config.get("api-port", str(DEFAULT_PORT))) - self.httpd = BitBotIPv6HTTPd(("::1", port), Handler) + self._start_httpd() - self.thread = threading.Thread(target=self.httpd.serve_forever) - self.thread.daemon = True - self.thread.start() + def _start_httpd(self): + port = int(self.bot.config.get("api-port", str(DEFAULT_PORT))) + self.httpd = BitBotIPv6HTTPd(("::1", port), Handler) - def unload(self): + self.thread = threading.Thread(target=self.httpd.serve_forever) + self.thread.daemon = True + self.thread.start() + def _stop_httpd(self): if self.httpd: self.httpd.shutdown() + def on_resume(self): + self._start_httpd() + + def unload(self): + self._stop_httpd() + def on_pause(self): + self._stop_httpd() + @utils.hook("received.command.apikey") @utils.kwarg("private_only", True) @utils.kwarg("min_args", 1) |
