mirror of
https://github.com/maubot/maubot
synced 2025-08-29 19:00:39 +00:00
Pass asyncio event loop and http session to plugin instances
This commit is contained in:
parent
9e066478a9
commit
767885cec7
3 changed files with 16 additions and 7 deletions
|
@ -17,6 +17,7 @@ from typing import Dict, List, Optional
|
|||
from sqlalchemy.orm import Session
|
||||
from ruamel.yaml.comments import CommentedMap
|
||||
from ruamel.yaml import YAML
|
||||
from asyncio import AbstractEventLoop
|
||||
import logging
|
||||
import io
|
||||
|
||||
|
@ -38,6 +39,7 @@ yaml.indent(4)
|
|||
class PluginInstance:
|
||||
db: Session = None
|
||||
mb_config: Config = None
|
||||
loop: AbstractEventLoop = None
|
||||
cache: Dict[str, 'PluginInstance'] = {}
|
||||
plugin_directories: List[str] = []
|
||||
|
||||
|
@ -109,8 +111,8 @@ class PluginInstance:
|
|||
except (FileNotFoundError, KeyError):
|
||||
base_file = None
|
||||
self.config = config_class(self.load_config, lambda: base_file, self.save_config)
|
||||
self.plugin = cls(self.client.client, self.id, self.log, self.config,
|
||||
self.mb_config["plugin_directories.db"])
|
||||
self.plugin = cls(self.client.client, self.loop, self.client.http_client, self.id,
|
||||
self.log, self.config, self.mb_config["plugin_directories.db"])
|
||||
try:
|
||||
await self.plugin.start()
|
||||
except Exception:
|
||||
|
@ -178,6 +180,7 @@ class PluginInstance:
|
|||
# endregion
|
||||
|
||||
|
||||
def init(db: Session, config: Config):
|
||||
def init(db: Session, config: Config, loop: AbstractEventLoop):
|
||||
PluginInstance.db = db
|
||||
PluginInstance.mb_config = config
|
||||
PluginInstance.loop = loop
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue