Files
HeXi/hexi/plugins/nonebot_plugin_picfinder_take/services/search.py
T
sansenhoshiandClaude 9371a28e35 refactor: restructure plugins per MTSS standard, consolidate assets to res/
Per docs/plugin-audit-report.md (plugins normalized to
Trigger(handlers) → Service(services) → Model(repository/models) + utils):

- Split monolithic __init__.py into handlers/services/utils across
  dailywife, deer_pipe, dice, galgame_card, helldivers_tools,
  huoziyinshua, learning_chat, makeaquote, mc_server_status,
  ncm_saying, picfinder_take, picstatus, random_jm_code, regif,
  steam_info, video_analysis, group_tools
- Move static assets under res/: deer_pipe font/img, makeaquote font,
  helldivers img/templates, huoziyinshua HuoZiYinShua
- Add config.py + register_config_items to ncm_saying, random_jm_code,
  group_tools; learning_chat unified config bridge
- Remove deprecated: voice_trans plugin, bf_bot/test.py, dead code in
  dailywife/deer_pipe, empty dirs, debug scripts under helldivers temp
- Disable brash_general_supercredits_tools (stub comment only)
- bot.py: optional stdout/stderr redirect to log file for Web log viewer,
  force ANSI colorize on non-TTY sinks
- Move runtime data (jm_code.json) out of plugin dir into hexi/data
- Docs: plugin-audit-report.md; README reflects removed plugins

Co-Authored-By: Claude <noreply@anthropic.com>
2026-09-03 00:44:38 +08:00

68 lines
2.4 KiB
Python

"""搜图 —— 搜索编排(Service 层)。"""
from __future__ import annotations
from nonebot import get_driver
from nonebot.adapters.onebot.v11 import Bot, GroupMessageEvent
from nonebot.log import logger
from ..config import CHAIN_REPLY, SAUCENAO_KEY, threshold
from .image import get_image_data_ascii, get_image_data_sauce
from .state import lmtd
_driver = get_driver()
SUPERUSERS = list(_driver.config.superusers)
_NICKNAMES = list(_driver.config.nickname) if _driver.config.nickname else ["竹竹"]
NICKNAME = _NICKNAMES[0]
async def chain_reply(bot: Bot, ev: GroupMessageEvent, chain, msg):
if not CHAIN_REPLY:
return chain
data = {
"type": "node",
"data": {
"name": str(NICKNAME) if str(NICKNAME) else "竹竹",
"uin": str(ev.self_id),
"content": str(msg),
},
}
chain.append(data)
return chain
async def picfinder(bot: Bot, ev: GroupMessageEvent, image_data):
uid = ev.user_id
chain = []
result = await get_image_data_sauce(image_data, SAUCENAO_KEY)
image_data_report = result[0]
simimax = result[1]
if "Index #" in image_data_report:
su = next(iter(SUPERUSERS))
await bot.send_private_msg(user_id=int(su), message="发生index解析错误")
await bot.send_private_msg(user_id=int(su), message=image_data)
await bot.send_private_msg(user_id=int(su), message=image_data_report)
chain = await chain_reply(bot, ev, chain, image_data_report)
if float(simimax) > float(threshold):
lmtd.increase(uid)
else:
if simimax != 0:
chain = await chain_reply(bot, ev, chain, "相似度过低,换用ascii2d检索中…")
else:
logger.error("SauceNao not found imageInfo")
chain = await chain_reply(bot, ev, chain, "SauceNao检索失败,换用ascii2d检索中…")
image_data_report = await get_image_data_ascii(image_data)
if image_data_report[0]:
chain = await chain_reply(bot, ev, chain, image_data_report[0])
lmtd.increase(uid)
if image_data_report[1]:
chain = await chain_reply(bot, ev, chain, image_data_report[1])
if not (image_data_report[0] or image_data_report[1]):
logger.error("ascii2d not found imageInfo")
chain = await chain_reply(bot, ev, chain, "ascii2d检索失败…")
if CHAIN_REPLY:
await bot.send_group_forward_msg(group_id=ev.group_id, messages=chain)