Skip to content

Commit

Permalink
fix #17
Browse files Browse the repository at this point in the history
  • Loading branch information
lgc2333 committed Feb 20, 2024
1 parent 7793350 commit b4d785e
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 17 deletions.
32 changes: 25 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,27 @@

_✨ 自动回复 ✨_

<img src="https://img.shields.io/badge/python-3.9+-blue.svg" alt="python">
<a href="https://pdm.fming.dev">
<img src="https://img.shields.io/badge/pdm-managed-blueviolet" alt="pdm-managed">
</a>
<a href="https://wakatime.com/badge/user/b61b0f9a-f40b-4c82-bc51-0a75c67bfccf/project/3eb869b8-2edf-46dd-b325-916d9f8a4888">
<img src="https://wakatime.com/badge/user/b61b0f9a-f40b-4c82-bc51-0a75c67bfccf/project/3eb869b8-2edf-46dd-b325-916d9f8a4888.svg" alt="wakatime">
</a>

<br />

<a href="https://pydantic.dev">
<img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/lgc-NB2Dev/readme/main/template/pyd-v1-or-v2.json" alt="Pydantic Version 1 Or 2" >
</a>
<a href="./LICENSE">
<img src="https://img.shields.io/github/license/lgc2333/nonebot-plugin-autoreply.svg" alt="license">
<img src="https://img.shields.io/github/license/lgc-NB2Dev/nonebot-plugin-autoreply.svg" alt="license">
</a>
<a href="https://pypi.python.org/pypi/nonebot-plugin-autoreply">
<img src="https://img.shields.io/pypi/v/nonebot-plugin-autoreply.svg" alt="pypi">
<img src="https://img.shields.io/pypi/v/nonebot-plugin-autoreply.svg" alt="pypi">
</a>
<img src="https://img.shields.io/badge/python-3.9+-blue.svg" alt="python">
<a href="https://pypi.python.org/pypi/nonebot-plugin-autoreply">
<img src="https://img.shields.io/pypi/dm/nonebot-plugin-autoreply" alt="pypi download">
</a>
<a href="https://wakatime.com/badge/user/b61b0f9a-f40b-4c82-bc51-0a75c67bfccf/project/3eb869b8-2edf-46dd-b325-916d9f8a4888">
<img src="https://wakatime.com/badge/user/b61b0f9a-f40b-4c82-bc51-0a75c67bfccf/project/3eb869b8-2edf-46dd-b325-916d9f8a4888.svg" alt="wakatime">
<img src="https://img.shields.io/pypi/dm/nonebot-plugin-autoreply" alt="pypi download">
</a>
</div>

Expand Down Expand Up @@ -151,6 +160,15 @@ Telegram:[@lgc2333](https://t.me/lgc2333)

## 📝 更新日志

### 0.2.12

- 适配 Pydantic V1 & V2
- 修复 [#17](https://github.com/lgc-NB2Dev/nonebot-plugin-autoreply/issues/17)

### 0.2.11

- 🎉 NoneBot 2.0 🚀

### 0.2.10

- 新增了 `start``end` 匹配方式
Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_autoreply/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from . import __main__ as __main__
from .config import ConfigModel, reload_replies as reload_replies

__version__ = "0.2.11"
__version__ = "0.2.12"
__plugin_meta__ = PluginMetadata(
name="AutoReply",
description="配置文件高度可自定义的自动回复插件",
Expand Down
21 changes: 16 additions & 5 deletions nonebot_plugin_autoreply/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
from nonebot.permission import SUPERUSER
from nonebot.typing import T_State

from nonebot_plugin_autoreply.util import VarDictType, get_var_dict, replace_message_var

from .config import (
FilterModel,
MatchModel,
Expand All @@ -42,6 +40,7 @@
reload_replies,
replies,
)
from .util import VarDictType, get_var_dict, replace_message_var

T = TypeVar("T")
TArgs = TypeVarTuple("TArgs")
Expand Down Expand Up @@ -115,18 +114,30 @@ def check_message(
msg_plaintext = msg_plaintext.strip()

if match.type == "regex":
plaintext = False
flag = re.IGNORECASE if match.ignore_case else 0
match_obj = re.search(match_template, msg_str, flag)
if (not match_obj) and match.allow_plaintext:
plaintext = True
match_obj = re.search(match_template, msg_plaintext, flag)

if match_obj:
var_dict = {}
var_dict["v0"] = match_obj.string
var_dict["v0"] = (
match_obj.string if plaintext else Message(match_obj.string)
)
var_dict.update(
{
f"v{i + 1}": (str(x) if plaintext else Message(x) if x else "")
for i, x in enumerate(match_obj.groups())
},
)
var_dict.update(
{f"v{i + 1}": str(x or "") for i, x in enumerate(match_obj.groups())},
{
k: (str(v) if plaintext else Message(v) if v else "")
for k, v in match_obj.groupdict().items()
},
)
var_dict.update({k: str(v or "") for k, v in match_obj.groupdict().items()})
return True, var_dict

return False, None
Expand Down
4 changes: 2 additions & 2 deletions nonebot_plugin_autoreply/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
)

import yaml
from nonebot import get_driver
from nonebot import get_plugin_config
from nonebot.log import logger
from pydantic import BaseModel

Expand Down Expand Up @@ -96,7 +96,7 @@ class ConfigModel(BaseModel):


replies: List[ReplyEntryModel] = []
config = ConfigModel.parse_obj(get_driver().config)
config = get_plugin_config(ConfigModel)


def iter_config_path(root_path: Path = DATA_PATH) -> Iterator[Path]:
Expand Down
8 changes: 6 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[project]
name = "nonebot-plugin-autoreply"
version = "0.2.11.post1"
dynamic = ["version"]
description = "A powerful auto reply plugin for NoneBot2"
authors = [{ name = "student_2333", email = "lgc2333@126.com" }]
dependencies = [
"nonebot2>=2.2.0",
"pydantic>=1.10.0,<2",
"pydantic>=1.10.0,<2",
"nonebot-adapter-onebot>=2.2.3",
"typing-extensions>=4.4.0",
"PyYAML>=6.0",
Expand All @@ -21,6 +21,10 @@ homepage = "https://github.com/lgc-NB2Dev/nonebot-plugin-autoreply"
[tool.pdm.build]
includes = []

[tool.pdm.version]
source = "file"
path = "nonebot_plugin_autoreply/__init__.py"

[build-system]
requires = ["pdm-backend"]
build-backend = "pdm.backend"

0 comments on commit b4d785e

Please sign in to comment.