mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2026-05-10 18:57:56 +08:00
:recycles: 仿照 platform_manager 添加 site_manager
This commit is contained in:
@@ -4,6 +4,7 @@ from collections import defaultdict
|
||||
from importlib import import_module
|
||||
|
||||
from .platform import Platform, make_no_target_group
|
||||
from ..utils import Site
|
||||
|
||||
_package_dir = str(Path(__file__).resolve().parent)
|
||||
for _, module_name, _ in iter_modules([_package_dir]):
|
||||
@@ -22,3 +23,11 @@ for name, platform_list in _platform_list.items():
|
||||
platform_manager[name] = platform_list[0]
|
||||
else:
|
||||
platform_manager[name] = make_no_target_group(platform_list)
|
||||
|
||||
|
||||
site_manager: dict[str, type[Site]] = {}
|
||||
for site in Site.registry:
|
||||
if not hasattr(site, "name"):
|
||||
continue
|
||||
site_manager[site.name] = site
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ from nonebot_plugin_saa import PlatformTarget
|
||||
from ..post import Post
|
||||
from ..utils import Site, ProcessContext
|
||||
from ..plugin_config import plugin_config
|
||||
from ..types import Tag, Target, RawPost, SubUnit, Category
|
||||
from ..types import Tag, Target, RawPost, SubUnit, Category, RegistryMeta
|
||||
|
||||
|
||||
class CategoryNotSupport(Exception):
|
||||
@@ -29,21 +29,6 @@ class CategoryNotRecognize(Exception):
|
||||
"""raise in get_category, when you don't know the category of post"""
|
||||
|
||||
|
||||
class RegistryMeta(type):
|
||||
def __new__(cls, name, bases, namespace, **kwargs):
|
||||
return super().__new__(cls, name, bases, namespace)
|
||||
|
||||
def __init__(cls, name, bases, namespace, **kwargs):
|
||||
if kwargs.get("base"):
|
||||
# this is the base class
|
||||
cls.registry = []
|
||||
elif not kwargs.get("abstract"):
|
||||
# this is the subclass
|
||||
cls.registry.append(cls)
|
||||
|
||||
super().__init__(name, bases, namespace, **kwargs)
|
||||
|
||||
|
||||
P = ParamSpec("P")
|
||||
R = TypeVar("R")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user