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.py29
1 files changed, 10 insertions, 19 deletions
diff --git a/ATRI/plugins/anime_search.py b/ATRI/plugins/anime_search.py
index 6e73640..535dec2 100644
--- a/ATRI/plugins/anime_search.py
+++ b/ATRI/plugins/anime_search.py
@@ -1,5 +1,4 @@
import re
-from aiohttp import FormData
from random import choice
from nonebot.typing import T_State
@@ -24,9 +23,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 +36,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["result"]
-
+
d = dict()
for i in range(len(data)):
if data[i]["anilist"]["title"]["native"] in d.keys():
@@ -49,7 +49,7 @@ class Anime(Service):
else:
from_m = data[i]["from"] / 60
from_s = data[i]["from"] % 60
-
+
to_m = data[i]["to"] / 60
to_s = data[i]["to"] % 60
@@ -63,7 +63,7 @@ class Anime(Service):
f"第{n}集",
f"约{int(from_m)}min{int(from_s)}s至{int(to_m)}min{int(to_s)}s处",
]
-
+
result = sorted(d.items(), key=lambda x: x[1], reverse=True)
t = 0
msg0 = str()
@@ -76,23 +76,16 @@ class Anime(Service):
f"Name: {i[0]}\n"
f"Time: {i[1][1]} {i[1][2]}"
)
-
+
if len(result) == 2:
return msg0
else:
- data = FormData()
- data.add_field("poster", "ATRI running log")
- data.add_field("syntax", "text")
- data.add_field("expiration", "day")
- data.add_field("content", msg0)
-
- repo = f"详细请移步此处~\n{await UbuntuPaste(data).paste()}"
+ repo = f"详细请移步此处~\n{await UbuntuPaste(content=msg0).paste()}"
return repo
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()
@@ -104,18 +97,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()
@@ -123,7 +114,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("请发送图片而不是其它东西!!")
-
+
await bot.send(event, "别急,在找了")
a = await Anime().search(img[0])
result = f"> {MessageSegment.at(user_id)}\n" + a