from nonebot import get_driver
from nonebot.params import State, ArgPlainText, Arg, CommandArg
from nonebot.plugin import on_command, on_message
from nonebot.rule import to_me
from nonebot.adapters.onebot.v11 import Bot, MessageEvent, Message
from nonebot.typing import T_State
from nonebot.utils import DataclassEncoder
import requests
import urllib.parse
import time
whatanime = on_command('whatanime')
@whatanime.handle()
async def handle_first_receive(event: MessageEvent, state: T_State, whatanime: Message = CommandArg()):
if whatanime:
state['whatanime'] = whatanime
@whatanime.got("whatanime",prompt="请发送番剧截图")
async def get_whatanime(bot: Bot,event: MessageEvent,msg: Message = Arg("whatanime")):
if msg[0].type == "image":
imgurl = msg[0].data["url"]
text = await whatanime(imgurl)
await bot.send(event,text)
async def whatanime(imgurl):
try:
result=requests.get("https://api.trace.moe/search?anilistInfo&url={}".format(urllib.parse.quote_plus(imgurl))).json()
aminename = result['result'][0]['anilist']['title']['native']
episode = result['result'][0]['episode']
fromtime = result['result'][0]['from']
fromtime = time.strftime("%M:%S", time.localtime(fromtime))
similarity = result['result'][0]['similarity']
similarity = str(round(similarity*100,2))+'%'
text = "{} 第{}集 出现时间为: {},准确度:{}".format(aminename,episode,fromtime,similarity)
return str(text)
except:
return "查询失败"
nonebot2以图搜番插件相关代码
最新推荐文章于 2025-03-03 09:28:53 发布