mirror of
https://github.com/RockChinQ/QChatGPT.git
synced 2024-11-16 11:42:44 +08:00
34 lines
799 B
Python
34 lines
799 B
Python
import re
|
|
|
|
import mirai
|
|
|
|
from .. import rule as rule_model
|
|
from .. import entities
|
|
from ....core import entities as core_entities
|
|
|
|
|
|
class RegExpRule(rule_model.GroupRespondRule):
|
|
|
|
async def match(
|
|
self,
|
|
message_text: str,
|
|
message_chain: mirai.MessageChain,
|
|
rule_dict: dict,
|
|
query: core_entities.Query
|
|
) -> entities.RuleJudgeResult:
|
|
regexps = rule_dict['regexp']
|
|
|
|
for regexp in regexps:
|
|
match = re.match(regexp, message_text)
|
|
|
|
if match:
|
|
return entities.RuleJudgeResult(
|
|
matching=True,
|
|
replacement=message_chain,
|
|
)
|
|
|
|
return entities.RuleJudgeResult(
|
|
matching=False,
|
|
replacement=message_chain
|
|
)
|