From 7cfcecc533d8ce7a09e14fdab719a4cd3ff8eae3 Mon Sep 17 00:00:00 2001
From: Kyomotoi <0w0@imki.moe>
Date: Sun, 4 Jun 2023 17:57:36 +0800
Subject: =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=E9=87=8D=E6=9E=84=E6=8F=92?=
 =?UTF-8?q?=E4=BB=B6:=20=E4=BB=A5=E5=9B=BE=E6=90=9C=E5=9B=BE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 ATRI/plugins/saucenao/__init__.py | 28 +++++++++++++---------------
 1 file changed, 13 insertions(+), 15 deletions(-)

(limited to 'ATRI/plugins/saucenao/__init__.py')

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("以图搜图", "透过一张图搜索可能的来源")
 
 
-@saucenao.got("saucenao_img", "图呢?", [Cooldown(5, prompt=_search_flmt_notice)])
-async def _deal_search(event: MessageEvent):
-    # cache fix
+@search.got("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))
-- 
cgit v1.2.3