mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-04 12:56:02 +00:00
* style: remove necessary imports * style: fix F841 * style: fix F401 * style: fix F811 * style: fix E402 * style: fix E721 * style: fix E722 * style: fix E722 * style: fix F541 * style: ruff format * style: all passed * style: add ruff in deps * style: more ignores in ruff.toml * style: add pre-commit
46 lines
1.0 KiB
Python
46 lines
1.0 KiB
Python
from __future__ import annotations
|
|
import abc
|
|
import typing
|
|
|
|
from ...core import app, entities as core_entities
|
|
from . import entities
|
|
|
|
from ...platform.types import message as platform_message
|
|
|
|
|
|
preregisetered_rules: list[typing.Type[GroupRespondRule]] = []
|
|
|
|
|
|
def rule_class(name: str):
|
|
def decorator(cls: typing.Type[GroupRespondRule]) -> typing.Type[GroupRespondRule]:
|
|
cls.name = name
|
|
preregisetered_rules.append(cls)
|
|
return cls
|
|
|
|
return decorator
|
|
|
|
|
|
class GroupRespondRule(metaclass=abc.ABCMeta):
|
|
"""群组响应规则的抽象类"""
|
|
|
|
name: str
|
|
|
|
ap: app.Application
|
|
|
|
def __init__(self, ap: app.Application):
|
|
self.ap = ap
|
|
|
|
async def initialize(self):
|
|
pass
|
|
|
|
@abc.abstractmethod
|
|
async def match(
|
|
self,
|
|
message_text: str,
|
|
message_chain: platform_message.MessageChain,
|
|
rule_dict: dict,
|
|
query: core_entities.Query,
|
|
) -> entities.RuleJudgeResult:
|
|
"""判断消息是否匹配规则"""
|
|
raise NotImplementedError
|