summaryrefslogtreecommitdiff
path: root/ATRI/plugins/saucenao/__init__.py
diff options
context:
space:
mode:
authorKyomotoi <[email protected]>2022-02-03 14:36:24 +0800
committerKyomotoi <[email protected]>2022-02-03 14:36:24 +0800
commit3e32ca3964ff8f40e0b491e87f153040f2348fd0 (patch)
treed04d19ba5a25f6f1f6a9c4f8c398d49eb252df3c /ATRI/plugins/saucenao/__init__.py
parentf5a020d45f7294214bbcd488955b9c391d651a6d (diff)
downloadATRI-3e32ca3964ff8f40e0b491e87f153040f2348fd0.tar.gz
ATRI-3e32ca3964ff8f40e0b491e87f153040f2348fd0.tar.bz2
ATRI-3e32ca3964ff8f40e0b491e87f153040f2348fd0.zip
🔖 更新版本:
更新记录请参考文档: atri.kyomotoi.moe/changelog/overview/
Diffstat (limited to 'ATRI/plugins/saucenao/__init__.py')
-rw-r--r--ATRI/plugins/saucenao/__init__.py31
1 files changed, 10 insertions, 21 deletions
diff --git a/ATRI/plugins/saucenao/__init__.py b/ATRI/plugins/saucenao/__init__.py
index fed1096..092db50 100644
--- a/ATRI/plugins/saucenao/__init__.py
+++ b/ATRI/plugins/saucenao/__init__.py
@@ -1,9 +1,9 @@
from re import findall
from random import choice
-from nonebot.typing import T_State
-from nonebot.adapters.cqhttp import Bot, MessageEvent
-from nonebot.adapters.cqhttp.message import Message, MessageSegment
+from nonebot.matcher import Matcher
+from nonebot.params import ArgPlainText, CommandArg
+from nonebot.adapters.onebot.v11 import MessageEvent, Message, MessageSegment
from ATRI.config import SauceNAO
from ATRI.utils.limit import FreqLimiter
@@ -17,33 +17,22 @@ _search_flmt_notice = choice(["慢...慢一..点❤", "冷静1下", "歇会歇�
saucenao = SaouceNao().on_command("以图搜图", "透过一张图搜索可能的来源")
[email protected]_parser # type: ignore
-async def _get_img(bot: Bot, event: MessageEvent, state: T_State):
- msg = str(event.message).strip()
- quit_list = ["算了", "罢了", "不搜了"]
- if msg in quit_list:
- await saucenao.finish("好吧...")
- if not msg:
- await saucenao.reject("图呢?")
- else:
- state["img"] = msg
-
-
@saucenao.handle()
-async def _ready_search(bot: Bot, event: MessageEvent, state: T_State):
+async def _ready_search(
+ matcher: Matcher, event: MessageEvent, args: Message = CommandArg()
+):
user_id = event.get_user_id()
if not _search_flmt.check(user_id):
await saucenao.finish(_search_flmt_notice)
- msg = str(event.message).strip()
+ msg = args.extract_plain_text()
if msg:
- state["img"] = msg
+ matcher.set_arg("saucenao_img", args)
[email protected]("img", "图呢?")
-async def _deal_search(bot: Bot, event: MessageEvent, state: T_State):
[email protected]("saucenao_img", "图呢?")
+async def _deal_search(event: MessageEvent, msg: str = ArgPlainText("saucenao_img")):
user_id = event.get_user_id()
- msg = state["img"]
img = findall(r"url=(.*?)]", msg)
if not img:
await saucenao.reject("请发送图片而不是其他东西!!")