summaryrefslogtreecommitdiff
path: root/ATRI/plugins/anime_search.py
diff options
context:
space:
mode:
Diffstat (limited to 'ATRI/plugins/anime_search.py')
-rw-r--r--ATRI/plugins/anime_search.py18
1 files changed, 8 insertions, 10 deletions
diff --git a/ATRI/plugins/anime_search.py b/ATRI/plugins/anime_search.py
index 80d8a94..de64501 100644
--- a/ATRI/plugins/anime_search.py
+++ b/ATRI/plugins/anime_search.py
@@ -24,9 +24,10 @@ __doc__ = """
class Anime(Service):
+
def __init__(self):
Service.__init__(self, "以图搜番", __doc__, rule=is_in_service("以图搜番"))
-
+
@staticmethod
async def _request(url: str) -> dict:
aim = URL + url
@@ -36,12 +37,12 @@ class Anime(Service):
raise RequestError("Request failed!")
result = await res.json()
return result
-
+
@classmethod
async def search(cls, url: str) -> str:
data = await cls._request(url)
data = data["docs"]
-
+
d = dict()
for i in range(len(data)):
if data[i]["title_chinese"] in d.keys():
@@ -60,7 +61,7 @@ class Anime(Service):
f"第{n}集",
f"{int(m)}分{int(s)}秒处",
]
-
+
result = sorted(d.items(), key=lambda x: x[1], reverse=True)
t = 0
msg0 = str()
@@ -73,7 +74,7 @@ class Anime(Service):
f"Name: {i[0]}\n"
f"Time: {i[1][1]} {i[1][2]}"
)
-
+
if len(result) == 2:
return msg0
else:
@@ -89,7 +90,6 @@ class Anime(Service):
anime_search = Anime().on_command("以图搜番", "发送一张图以搜索可能的番剧")
-
@anime_search.args_parser # type: ignore
async def _get_anime(bot: Bot, event: MessageEvent, state: T_State):
msg = str(event.message).strip()
@@ -101,18 +101,16 @@ async def _get_anime(bot: Bot, event: MessageEvent, state: T_State):
else:
state["anime"] = msg
-
@anime_search.handle()
async def _ready_sear(bot: Bot, event: MessageEvent, state: T_State):
user_id = event.get_user_id()
if not _anime_flmt.check(user_id):
await anime_search.finish(_anime_flmt_notice)
-
+
msg = str(event.message).strip()
if msg:
state["anime"] = msg
-
@anime_search.got("anime", "图呢?")
async def _deal_sear(bot: Bot, event: MessageEvent, state: T_State):
user_id = event.get_user_id()
@@ -120,7 +118,7 @@ async def _deal_sear(bot: Bot, event: MessageEvent, state: T_State):
img = re.findall(r"url=(.*?)]", msg)
if not img:
await anime_search.reject("请发送图片而不是其它东西!!")
-
+
a = await Anime().search(img[0])
result = f"> {MessageSegment.at(user_id)}\n" + a
_anime_flmt.start_cd(user_id)