From c8b5179cb56552a2e3b224711f1ac5295ca11410 Mon Sep 17 00:00:00 2001 From: Lonami Date: Tue, 30 Apr 2019 20:32:35 +0200 Subject: [PATCH] Allow plugins to define an unload function --- uniborg/uniborg.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/uniborg/uniborg.py b/uniborg/uniborg.py index 97465f1..0d556b4 100644 --- a/uniborg/uniborg.py +++ b/uniborg/uniborg.py @@ -3,6 +3,7 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. import asyncio import importlib.util +import inspect import logging from pathlib import Path @@ -79,7 +80,13 @@ class Uniborg(TelegramClient): if cb.__module__ == name: del self._event_builders[i] - del self._plugins[shortname] + plugin = self._plugins.pop(shortname) + if callable(getattr(plugin, 'unload', None)): + unload = plugin.unload() + if inspect.isawaitable(unload): + await unload + + del plugin self._logger.info(f"Removed plugin {shortname}") def await_event(self, event_matcher, filter=None):