mirror of
https://github.com/RockChinQ/QChatGPT.git
synced 2024-11-16 11:42:44 +08:00
45 lines
995 B
Python
45 lines
995 B
Python
from __future__ import annotations
|
|
import abc
|
|
import typing
|
|
|
|
import mirai
|
|
|
|
from ...core import app, entities as core_entities
|
|
from . import entities
|
|
|
|
|
|
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: mirai.MessageChain,
|
|
rule_dict: dict,
|
|
query: core_entities.Query
|
|
) -> entities.RuleJudgeResult:
|
|
"""判断消息是否匹配规则
|
|
"""
|
|
raise NotImplementedError
|