mirror of
https://github.com/maubot/maubot
synced 2025-08-30 14:30:38 +00:00
Make it run
This commit is contained in:
parent
eef052b1e9
commit
dce2771588
8 changed files with 88 additions and 28 deletions
|
@ -20,17 +20,22 @@ 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 .__meta__ import __version__
|
||||
|
||||
parser = argparse.ArgumentParser(description="A plugin-based Matrix bot system.",
|
||||
prog="python -m maubot")
|
||||
parser.add_argument("-c", "--config", type=str, default="config.yaml",
|
||||
metavar="<path>", help="the path to your config file")
|
||||
parser.add_argument("-b", "--base-config", type=str, default="example-config.yaml",
|
||||
metavar="<path>", help="the path to the example config "
|
||||
"(for automatic config updates)")
|
||||
args = parser.parse_args()
|
||||
|
||||
config = Config(args.config, args.base_config)
|
||||
|
@ -38,13 +43,14 @@ config.load()
|
|||
config.update()
|
||||
|
||||
logging.config.dictConfig(copy.deepcopy(config["logging"]))
|
||||
log = logging.getLogger("maubot")
|
||||
log = logging.getLogger("maubot.init")
|
||||
log.debug(f"Initializing maubot {__version__}")
|
||||
|
||||
db_engine: sql.engine.Engine = sql.create_engine(config["database"])
|
||||
db_factory = orm.sessionmaker(bind=db_engine)
|
||||
db_session = orm.scoping.scoped_session(db_factory)
|
||||
Base.metadata.bind=db_engine
|
||||
Base.metadata.bind = db_engine
|
||||
Base.metadata.create_all()
|
||||
|
||||
loop = asyncio.get_event_loop()
|
||||
|
||||
|
@ -52,8 +58,22 @@ init_db(db_session)
|
|||
init_client(loop)
|
||||
server = MaubotServer(config, loop)
|
||||
|
||||
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}.")
|
||||
|
||||
try:
|
||||
loop.run_until_complete(server.start())
|
||||
log.debug("Startup actions complete, running forever.")
|
||||
loop.run_forever()
|
||||
except KeyboardInterrupt:
|
||||
log.debug("Keyboard interrupt received, stopping...")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue