From b91bb2c0ccce4443c1cfe6b7de5ba33439ca6cf2 Mon Sep 17 00:00:00 2001 From: Lint Action Date: Thu, 26 Aug 2021 02:45:06 +0000 Subject: =?UTF-8?q?:rotating=5Flight:=20=E8=87=AA=E5=8A=A8=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E4=BB=A3=E7=A0=81=E6=A0=BC=E5=BC=8F=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ATRI/plugins/saucenao/__init__.py | 7 +++++-- ATRI/plugins/saucenao/data_source.py | 26 +++++++++++++++----------- 2 files changed, 20 insertions(+), 13 deletions(-) (limited to 'ATRI/plugins/saucenao') diff --git a/ATRI/plugins/saucenao/__init__.py b/ATRI/plugins/saucenao/__init__.py index 468b001..b55f18c 100644 --- a/ATRI/plugins/saucenao/__init__.py +++ b/ATRI/plugins/saucenao/__init__.py @@ -16,6 +16,7 @@ _search_flmt_notice = choice(["慢...慢一..点❤", "冷静1下", "歇会歇 saucenao = SaouceNao().on_command("以图搜图", "透过一张图搜索可能的来源") + @saucenao.args_parser # type: ignore async def _get_img(bot: Bot, event: MessageEvent, state: T_State): msg = str(event.message).strip() @@ -27,16 +28,18 @@ async def _get_img(bot: Bot, event: MessageEvent, state: T_State): else: state["img"] = msg + @saucenao.handle() async def _ready_search(bot: Bot, event: MessageEvent, state: T_State): user_id = event.get_user_id() if not _search_flmt.check(user_id): await saucenao.finish(_search_flmt_notice) - + msg = str(event.message).strip() if msg: state["img"] = msg + @saucenao.got("img", "图呢?") async def _deal_search(bot: Bot, event: MessageEvent, state: T_State): user_id = event.get_user_id() @@ -44,7 +47,7 @@ async def _deal_search(bot: Bot, event: MessageEvent, state: T_State): img = findall(r"url=(.*?)]", msg) if not img: await saucenao.reject("请发送图片而不是其他东西!!") - + a = SaouceNao(SauceNAO.key) result = f"> {MessageSegment.at(user_id)}" + await a.search(img[0]) _search_flmt.start_cd(user_id) diff --git a/ATRI/plugins/saucenao/data_source.py b/ATRI/plugins/saucenao/data_source.py index 4f38f2c..fa90e5f 100644 --- a/ATRI/plugins/saucenao/data_source.py +++ b/ATRI/plugins/saucenao/data_source.py @@ -13,13 +13,15 @@ __doc__ = """ class SaouceNao(Service): - def __init__(self, - api_key: str = None, - output_type=2, - testmode=1, - dbmaski=32768, - db=5, - numres=5): + def __init__( + self, + api_key: str = None, + output_type=2, + testmode=1, + dbmaski=32768, + db=5, + numres=5, + ): Service.__init__(self, "以图搜图", __doc__, rule=is_in_service("以图搜图")) params = dict() @@ -59,10 +61,12 @@ class SaouceNao(Service): msg0 = str() for i in result: - msg0 += ("\n——————————\n" - f"Similarity: {i['similarity']}\n" - f"Name: {i['index_name']}\n" - f"URL: {i['url'].replace('https://', '')}") + msg0 += ( + "\n——————————\n" + f"Similarity: {i['similarity']}\n" + f"Name: {i['index_name']}\n" + f"URL: {i['url'].replace('https://', '')}" + ) if not result: return "没有相似的结果呢..." -- cgit v1.2.3