forked from kate/uniborg
Allow plugins to define an unload function
This commit is contained in:
parent
c2197e5280
commit
c8b5179cb5
|
@ -3,6 +3,7 @@
|
||||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
import asyncio
|
import asyncio
|
||||||
import importlib.util
|
import importlib.util
|
||||||
|
import inspect
|
||||||
import logging
|
import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
@ -79,7 +80,13 @@ class Uniborg(TelegramClient):
|
||||||
if cb.__module__ == name:
|
if cb.__module__ == name:
|
||||||
del self._event_builders[i]
|
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}")
|
self._logger.info(f"Removed plugin {shortname}")
|
||||||
|
|
||||||
def await_event(self, event_matcher, filter=None):
|
def await_event(self, event_matcher, filter=None):
|
||||||
|
|
Loading…
Reference in New Issue