mirror of
https://github.com/RockChinQ/QChatGPT.git
synced 2024-11-16 11:42:44 +08:00
feat: 群响应规则的扩展性
This commit is contained in:
parent
1d963d0f0c
commit
8c6ce1f030
|
@ -21,15 +21,13 @@ class GroupRespondRuleCheckStage(stage.PipelineStage):
|
|||
async def initialize(self):
|
||||
"""初始化检查器
|
||||
"""
|
||||
self.rule_matchers = [
|
||||
atbot.AtBotRule(self.ap),
|
||||
prefix.PrefixRule(self.ap),
|
||||
regexp.RegExpRule(self.ap),
|
||||
random.RandomRespRule(self.ap),
|
||||
]
|
||||
|
||||
for rule_matcher in self.rule_matchers:
|
||||
await rule_matcher.initialize()
|
||||
self.rule_matchers = []
|
||||
|
||||
for rule_matcher in rule.preregisetered_rules:
|
||||
rule_inst = rule_matcher(self.ap)
|
||||
await rule_inst.initialize()
|
||||
self.rule_matchers.append(rule_inst)
|
||||
|
||||
async def process(self, query: core_entities.Query, stage_inst_name: str) -> entities.StageProcessResult:
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from __future__ import annotations
|
||||
import abc
|
||||
import typing
|
||||
|
||||
import mirai
|
||||
|
||||
|
@ -7,9 +8,20 @@ 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
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ from .. import entities
|
|||
from ....core import entities as core_entities
|
||||
|
||||
|
||||
@rule_model.rule_class("at-bot")
|
||||
class AtBotRule(rule_model.GroupRespondRule):
|
||||
|
||||
async def match(
|
||||
|
|
|
@ -5,6 +5,7 @@ from .. import entities
|
|||
from ....core import entities as core_entities
|
||||
|
||||
|
||||
@rule_model.rule_class("prefix")
|
||||
class PrefixRule(rule_model.GroupRespondRule):
|
||||
|
||||
async def match(
|
||||
|
|
|
@ -7,6 +7,7 @@ from .. import entities
|
|||
from ....core import entities as core_entities
|
||||
|
||||
|
||||
@rule_model.rule_class("random")
|
||||
class RandomRespRule(rule_model.GroupRespondRule):
|
||||
|
||||
async def match(
|
||||
|
|
|
@ -7,6 +7,7 @@ from .. import entities
|
|||
from ....core import entities as core_entities
|
||||
|
||||
|
||||
@rule_model.rule_class("regexp")
|
||||
class RegExpRule(rule_model.GroupRespondRule):
|
||||
|
||||
async def match(
|
||||
|
|
Loading…
Reference in New Issue
Block a user