mirror of
https://github.com/langbot-app/LangBot.git
synced 2025-11-25 19:37:36 +08:00
22 lines
679 B
Python
22 lines
679 B
Python
import random
|
|
|
|
|
|
from .. import rule as rule_model
|
|
from .. import entities
|
|
import langbot_plugin.api.entities.builtin.platform.message as platform_message
|
|
import langbot_plugin.api.entities.builtin.pipeline.query as pipeline_query
|
|
|
|
|
|
@rule_model.rule_class('random')
|
|
class RandomRespRule(rule_model.GroupRespondRule):
|
|
async def match(
|
|
self,
|
|
message_text: str,
|
|
message_chain: platform_message.MessageChain,
|
|
rule_dict: dict,
|
|
query: pipeline_query.Query,
|
|
) -> entities.RuleJudgeResult:
|
|
random_rate = rule_dict['random']
|
|
|
|
return entities.RuleJudgeResult(matching=random.random() < random_rate, replacement=message_chain)
|