mirror of
https://github.com/maubot/maubot
synced 2025-08-30 14:30:38 +00:00
Make it work
This commit is contained in:
parent
dce2771588
commit
1d8de8b5f2
7 changed files with 139 additions and 32 deletions
|
@ -20,13 +20,13 @@ import argparse
|
|||
import asyncio
|
||||
import copy
|
||||
import sys
|
||||
import os
|
||||
|
||||
from .config import Config
|
||||
from .db import Base, init as init_db
|
||||
from .server import MaubotServer
|
||||
from .client import Client, init as init_client
|
||||
from .loader import ZippedPluginLoader, MaubotZipImportError
|
||||
from .loader import ZippedPluginLoader
|
||||
from .plugin import PluginInstance
|
||||
from .__meta__ import __version__
|
||||
|
||||
parser = argparse.ArgumentParser(description="A plugin-based Matrix bot system.",
|
||||
|
@ -57,27 +57,22 @@ loop = asyncio.get_event_loop()
|
|||
init_db(db_session)
|
||||
init_client(loop)
|
||||
server = MaubotServer(config, loop)
|
||||
ZippedPluginLoader.load_all(*config["plugin_directories"])
|
||||
plugins = PluginInstance.all()
|
||||
|
||||
loader_log = logging.getLogger("maubot.loader.zip")
|
||||
loader_log.debug("Preloading plugins...")
|
||||
for directory in config["plugin_directories"]:
|
||||
for file in os.listdir(directory):
|
||||
if not file.endswith(".mbp"):
|
||||
continue
|
||||
path = os.path.join(directory, file)
|
||||
try:
|
||||
loader = ZippedPluginLoader.get(path)
|
||||
loader_log.debug(f"Preloaded plugin {loader.id} from {loader.path}.")
|
||||
except MaubotZipImportError:
|
||||
loader_log.exception(f"Failed to load plugin at {path}.")
|
||||
for plugin in plugins:
|
||||
plugin.load()
|
||||
|
||||
try:
|
||||
loop.run_until_complete(server.start())
|
||||
loop.run_until_complete(asyncio.gather(
|
||||
server.start(),
|
||||
*[plugin.start() for plugin in plugins]))
|
||||
log.debug("Startup actions complete, running forever.")
|
||||
loop.run_forever()
|
||||
except KeyboardInterrupt:
|
||||
log.debug("Keyboard interrupt received, stopping...")
|
||||
for client in Client.cache.values():
|
||||
client.stop()
|
||||
db_session.commit()
|
||||
loop.run_until_complete(server.stop())
|
||||
sys.exit(0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue