diff options
author | Kyomotoi <[email protected]> | 2023-06-04 17:57:36 +0800 |
---|---|---|
committer | Kyomotoi <[email protected]> | 2023-06-04 17:57:36 +0800 |
commit | 7cfcecc533d8ce7a09e14fdab719a4cd3ff8eae3 (patch) | |
tree | 8f4cbcd12d0f92b30e222550647e89c256325889 /ATRI/plugins/saucenao/__init__.py | |
parent | 98a5276ac1735be04bd2cb37a3a3674b8242152b (diff) | |
download | ATRI-7cfcecc533d8ce7a09e14fdab719a4cd3ff8eae3.tar.gz ATRI-7cfcecc533d8ce7a09e14fdab719a4cd3ff8eae3.tar.bz2 ATRI-7cfcecc533d8ce7a09e14fdab719a4cd3ff8eae3.zip |
♻️ 重构插件: 以图搜图
Diffstat (limited to 'ATRI/plugins/saucenao/__init__.py')
-rw-r--r-- | ATRI/plugins/saucenao/__init__.py | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/ATRI/plugins/saucenao/__init__.py b/ATRI/plugins/saucenao/__init__.py index add9c26..410a126 100644 --- a/ATRI/plugins/saucenao/__init__.py +++ b/ATRI/plugins/saucenao/__init__.py @@ -1,40 +1,38 @@ from random import choice from nonebot.adapters.onebot.v11 import MessageEvent, Message, MessageSegment -from nonebot.adapters.onebot.v11.helpers import extract_image_urls, Cooldown +from nonebot.adapters.onebot.v11.helpers import Cooldown, extract_image_urls from ATRI import conf from ATRI.log import log from ATRI.service import Service, ServiceTools -from .data_source import SauceNao + +from .data_source import SauceNAO plugin = Service("以图搜图").document("以图搜图,仅限二刺螈") -sau = SauceNao() _search_flmt_notice = choice(["慢...慢一..点❤", "冷静1下", "歇会歇会~~"]) -saucenao = plugin.on_command("以图搜图", "透过一张图搜索可能的来源") +search = plugin.on_command("以图搜图", "透过一张图搜索可能的来源") [email protected]("saucenao_img", "图呢?", [Cooldown(5, prompt=_search_flmt_notice)]) -async def _deal_search(event: MessageEvent): - # cache fix [email protected]("img", "图呢?", [Cooldown(5, prompt=_search_flmt_notice)]) +async def _do_search(event: MessageEvent): if not conf.SauceNAO.key: ServiceTools("以图搜图").service_controller(False) - log.warning("插件 SauceNao 所需的 key 未配置,将被全局禁用,后续填写请手动启用") + log.warning("插件 以图搜图 所需的 key (SauceNAO) 未配置,将被全局禁用,后续填写请手动启用") user_id = event.get_user_id() - img = extract_image_urls(event.message) + img = extract_image_urls(event.get_message()) if not img: - await saucenao.reject("请发送图片而不是其他东西!!") + await search.reject("请发送图片而不是其他东西!!") try: - a = SauceNao(conf.SauceNAO.key) - except Exception: - await saucenao.finish("失败了...") + result = await SauceNAO(conf.SauceNAO.key).search(img[0]) + except Exception as err: + await search.finish(f"搜索失败:{str(err)}") - result = f"> {MessageSegment.at(user_id)}" + await a.search(img[0]) # type: ignore - await saucenao.finish(Message(result)) + await search.finish(Message(f"> {MessageSegment.at(user_id)}\n" + result)) |