Feature: 添加正则匹配文本注入 (#1457)

Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Akirami
2022-12-09 14:42:54 +08:00
committed by GitHub
parent 8176cd189c
commit 36d7b44741
7 changed files with 47 additions and 9 deletions

View File

@ -5,6 +5,7 @@ FrontMatter:
description: nonebot.params 模块
"""
import warnings
from typing import Any, Dict, List, Tuple, Union, Optional
from nonebot.typing import T_State
@ -24,6 +25,7 @@ from nonebot.internal.params import MatcherParam as MatcherParam
from nonebot.internal.params import ExceptionParam as ExceptionParam
from nonebot.consts import (
CMD_KEY,
REGEX_STR,
PREFIX_KEY,
REGEX_DICT,
SHELL_ARGS,
@ -136,9 +138,24 @@ def _regex_matched(state: T_State) -> str:
def RegexMatched() -> str:
"""正则匹配结果"""
warnings.warn(
'"RegexMatched()" will be changed to "re.Match" object, '
'use "RegexStr()" instead. '
"See https://github.com/nonebot/nonebot2/pull/1453 .",
DeprecationWarning,
)
return Depends(_regex_matched, use_cache=False)
def _regex_str(state: T_State) -> str:
return state[REGEX_STR]
def RegexStr() -> str:
"""正则匹配结果文本"""
return Depends(_regex_str, use_cache=False)
def _regex_group(state: T_State):
return state[REGEX_GROUP]