mirror of
https://github.com/nonebot/nonebot2.git
synced 2024-11-30 17:15:08 +08:00
29 lines
746 B
Python
29 lines
746 B
Python
import abc
|
|
from typing import TYPE_CHECKING
|
|
from collections import defaultdict
|
|
from collections.abc import Mapping, MutableMapping
|
|
|
|
if TYPE_CHECKING:
|
|
from .matcher import Matcher
|
|
|
|
|
|
class MatcherProvider(abc.ABC, MutableMapping[int, list[type["Matcher"]]]):
|
|
"""事件响应器存储器基类
|
|
|
|
参数:
|
|
matchers: 当前存储器中已有的事件响应器
|
|
"""
|
|
|
|
@abc.abstractmethod
|
|
def __init__(self, matchers: Mapping[int, list[type["Matcher"]]]):
|
|
raise NotImplementedError
|
|
|
|
|
|
class _DictProvider(defaultdict, MatcherProvider):
|
|
def __init__(self, matchers: Mapping[int, list[type["Matcher"]]]):
|
|
super().__init__(list, matchers)
|
|
|
|
|
|
DEFAULT_PROVIDER_CLASS = _DictProvider
|
|
"""默认存储器类型"""
|