nonebot-plugin-pErithacus 1.4.2__tar.gz → 1.4.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (23) hide show
  1. {nonebot_plugin_perithacus-1.4.2 → nonebot_plugin_perithacus-1.4.3}/PKG-INFO +1 -1
  2. {nonebot_plugin_perithacus-1.4.2 → nonebot_plugin_perithacus-1.4.3}/pyproject.toml +1 -1
  3. {nonebot_plugin_perithacus-1.4.2 → nonebot_plugin_perithacus-1.4.3}/src/nonebot_plugin_perithacus/__init__.py +1 -1
  4. {nonebot_plugin_perithacus-1.4.2 → nonebot_plugin_perithacus-1.4.3}/src/nonebot_plugin_perithacus/cmd_search.py +15 -21
  5. {nonebot_plugin_perithacus-1.4.2 → nonebot_plugin_perithacus-1.4.3}/src/nonebot_plugin_perithacus/lib.py +3 -3
  6. {nonebot_plugin_perithacus-1.4.2 → nonebot_plugin_perithacus-1.4.3}/README.md +0 -0
  7. {nonebot_plugin_perithacus-1.4.2 → nonebot_plugin_perithacus-1.4.3}/src/nonebot_plugin_perithacus/apscheduler.py +0 -0
  8. {nonebot_plugin_perithacus-1.4.2 → nonebot_plugin_perithacus-1.4.3}/src/nonebot_plugin_perithacus/cmd_add.py +0 -0
  9. {nonebot_plugin_perithacus-1.4.2 → nonebot_plugin_perithacus-1.4.3}/src/nonebot_plugin_perithacus/cmd_check.py +0 -0
  10. {nonebot_plugin_perithacus-1.4.2 → nonebot_plugin_perithacus-1.4.3}/src/nonebot_plugin_perithacus/cmd_delete.py +0 -0
  11. {nonebot_plugin_perithacus-1.4.2 → nonebot_plugin_perithacus-1.4.3}/src/nonebot_plugin_perithacus/cmd_detail.py +0 -0
  12. {nonebot_plugin_perithacus-1.4.2 → nonebot_plugin_perithacus-1.4.3}/src/nonebot_plugin_perithacus/cmd_edit.py +0 -0
  13. {nonebot_plugin_perithacus-1.4.2 → nonebot_plugin_perithacus-1.4.3}/src/nonebot_plugin_perithacus/cmd_list.py +0 -0
  14. {nonebot_plugin_perithacus-1.4.2 → nonebot_plugin_perithacus-1.4.3}/src/nonebot_plugin_perithacus/command.py +0 -0
  15. {nonebot_plugin_perithacus-1.4.2 → nonebot_plugin_perithacus-1.4.3}/src/nonebot_plugin_perithacus/database.py +0 -0
  16. {nonebot_plugin_perithacus-1.4.2 → nonebot_plugin_perithacus-1.4.3}/src/nonebot_plugin_perithacus/handle_args.py +0 -0
  17. {nonebot_plugin_perithacus-1.4.2 → nonebot_plugin_perithacus-1.4.3}/src/nonebot_plugin_perithacus/migrations/4184a6a150e9_.py +0 -0
  18. {nonebot_plugin_perithacus-1.4.2 → nonebot_plugin_perithacus-1.4.3}/src/nonebot_plugin_perithacus/migrations/59488f45afb7_.py +0 -0
  19. {nonebot_plugin_perithacus-1.4.2 → nonebot_plugin_perithacus-1.4.3}/src/nonebot_plugin_perithacus/migrations/bd67704f77ad_.py +0 -0
  20. {nonebot_plugin_perithacus-1.4.2 → nonebot_plugin_perithacus-1.4.3}/src/nonebot_plugin_perithacus/migrations/c2cbe27dd921_.py +0 -0
  21. {nonebot_plugin_perithacus-1.4.2 → nonebot_plugin_perithacus-1.4.3}/src/nonebot_plugin_perithacus/migrations/cc658325e0ad_.py +0 -0
  22. {nonebot_plugin_perithacus-1.4.2 → nonebot_plugin_perithacus-1.4.3}/src/nonebot_plugin_perithacus/trigger.py +0 -0
  23. {nonebot_plugin_perithacus-1.4.2 → nonebot_plugin_perithacus-1.4.3}/src/nonebot_plugin_perithacus/upgrade_database.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nonebot-plugin-pErithacus
3
- Version: 1.4.2
3
+ Version: 1.4.3
4
4
  Summary: pErithacus 是一个基于 NoneBot2 框架的聊天插件,可以根据用户设定的关键词自动回复相关内容。该插件提供了完整的词条管理功能,让用户能够轻松创建、编辑和管理自定义回复内容
5
5
  Keywords: nonebot2,chatbot,qqbot,nonebot-plugin
6
6
  Author: SnowMoonSS
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "nonebot-plugin-pErithacus"
3
- version = "1.4.2"
3
+ version = "1.4.3"
4
4
  description = "pErithacus 是一个基于 NoneBot2 框架的聊天插件,可以根据用户设定的关键词自动回复相关内容。该插件提供了完整的词条管理功能,让用户能够轻松创建、编辑和管理自定义回复内容"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.12, <4.0"
@@ -26,7 +26,7 @@ from .upgrade_database import upgrade_content_db
26
26
 
27
27
  driver = get_driver()
28
28
 
29
- __version__ = "1.4.2"
29
+ __version__ = "1.4.3"
30
30
  __plugin_meta__ = PluginMetadata(
31
31
  name="pErithacus",
32
32
  description=("pErithacus 是一个基于 NoneBot2 框架的聊天插件,"
@@ -12,11 +12,12 @@ from nonebot_plugin_alconna import (
12
12
  Query,
13
13
  UniMessage,
14
14
  )
15
+ from nonebot_plugin_alconna.uniseg.segment import At, Media
15
16
  from nonebot_plugin_orm import async_scoped_session # noqa: TC002
16
17
 
17
18
  from .command import pe
18
19
  from .database import Index, get_all_contents, get_entries, get_entry_by_id
19
- from .lib import dump_msg, get_scope, get_source, load_msg
20
+ from .lib import get_scope, get_source, load_msg, pe_download
20
21
 
21
22
  if TYPE_CHECKING:
22
23
  from collections.abc import Sequence
@@ -82,19 +83,17 @@ async def _( # noqa: PLR0913
82
83
  await pe.finish(UniMessage("搜索结果:\n无"))
83
84
 
84
85
  async def get_key(keyword: Match) -> str:
85
- keyword_text = await dump_msg(keyword.result, media_save_dir=False)
86
- pe_message_list = json.loads(keyword_text)
86
+ msg = UniMessage(keyword.result) if not isinstance(keyword.result, UniMessage) else keyword.result
87
+ msg = await pe_download(msg)
87
88
 
88
89
  # 检查pe_message_list中的每个元素
89
90
  key = None
90
- for item in pe_message_list:
91
- if not isinstance(item, dict):
92
- continue
93
- if item.get("media"):
94
- key = item["id"]
91
+ for seg in msg:
92
+ if isinstance(seg, Media):
93
+ key = seg.id
95
94
  break
96
- if item.get("type") == "at":
97
- key = item["target"]
95
+ if isinstance(seg, At):
96
+ key = seg.target
98
97
  break
99
98
  if not key:
100
99
  key = UniMessage(keyword.result).extract_plain_text()
@@ -110,9 +109,7 @@ async def search_in_entries(
110
109
  # 检查keyword列和alias列包含key的行
111
110
  if key in entry.keyword or (entry.alias and key in entry.alias):
112
111
  result_list.append(entry.id)
113
- logger.info(
114
- f"在 Index 中找到匹配的词条 {entry.id},关键词 {entry.keyword}"
115
- )
112
+ logger.info(f"在 Index 中找到匹配的词条 {entry.id},关键词 {entry.keyword}")
116
113
  return result_list
117
114
 
118
115
  async def search_in_contents(
@@ -124,14 +121,11 @@ async def search_in_contents(
124
121
  ) -> list[int]:
125
122
  contents = await get_all_contents(session)
126
123
  for content in contents:
127
- if not content.deleted and key in content.content:
128
- if content.entry_id not in result_list:
129
- if not await check_is_deleted(session, content.entry_id, scope_list):
130
- result_list.append(content.entry_id)
131
- else:
132
- logger.debug(f"跳过词条 {content.entry_id},该词条已存在搜索结果中")
133
- else:
134
- logger.debug(f"未在 {content.entry_id} 中找到包含 {key} 的内容")
124
+ if ((not content.deleted and key in content.content)
125
+ and (content.entry_id not in result_list)
126
+ and (not await check_is_deleted(session, content.entry_id, scope_list))):
127
+ result_list.append(content.entry_id)
128
+ logger.debug(f"在 {content.entry_id} 中找到包含 {key} 的内容")
135
129
 
136
130
  return result_list
137
131
 
@@ -247,10 +247,10 @@ async def pe_download(
247
247
  stream (bool, optional): 是否以流式下载. Defaults to False.
248
248
  **kwargs: 传递给下载器的参数
249
249
  """
250
- logger.debug("开始下载媒体数据")
251
250
  for media in self.select(Media):
252
251
  if not media.url:
253
252
  continue
253
+ logger.debug("开始下载媒体数据")
254
254
  raw: bytes = b""
255
255
  async with httpx.AsyncClient(**kwargs) as client:
256
256
  if stream:
@@ -363,7 +363,7 @@ def pe_save(
363
363
  return path.resolve()
364
364
 
365
365
  async def dump_msg(
366
- msg: UniMessage,
366
+ msg: UniMessage | str | tuple,
367
367
  *,
368
368
  media_save_dir: str | Path | bool | None = MEDIA_SAVE_DIR
369
369
  ) -> str:
@@ -382,7 +382,7 @@ async def dump_msg(
382
382
  :rtype: str
383
383
  """
384
384
 
385
- if isinstance(msg, tuple):
385
+ if not isinstance(msg, UniMessage):
386
386
  msg = UniMessage(msg)
387
387
 
388
388
  msg = await pe_download(msg)