Skip to content

Commit

Permalink
修复某api获取图片链接失败的问题, closes #1
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongwen-4 committed Oct 29, 2024
1 parent a867c9f commit 81cafb3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 44 deletions.
91 changes: 48 additions & 43 deletions nonebot_plugin_picsetu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
name="涩图插件",
description="随机获取一张涩图",
type="application",
homepage="https://github.com/zhongwen-4/nonebot-plugin-picsetu",
homepage="https://github.com/zhongwen-4/nonebot-plugin-setu",
supported_adapters={"~onebot.v11"},
usage="发送[setu, 涩图, 色图]任意一个就可以获取图片啦"
)
Expand All @@ -19,45 +19,50 @@
@setu_cmd.handle()
async def setu_handle():
a_randint = random.randint(1, 100)
if a_randint < 20:
await setu_cmd.send("稍等,图片正在赶来的路上")

async with httpx.AsyncClient() as client:
res = await client.get(
"https://api.lolicon.app/setu/v2"
)
url = await client.get(res.json()["data"][0]["urls"]["original"])

if url.status_code == 200:
await setu_cmd.finish(MessageSegment.image(res.json()["data"][0]["urls"]["original"]))
else:
await setu_cmd.finish("出错了,请重试")


if a_randint < 70 and a_randint > 20:
await setu_cmd.send("稍等,图片正在赶来的路上")

async with httpx.AsyncClient() as client:
res = await client.get(
"https://image.anosu.top/pixiv/json"
)
url = await client.get(res.json()[0]["url"])

if url.status_code == 200:
await setu_cmd.finish(MessageSegment.image(res.json()[0]["url"]))
else:
await setu_cmd.finish("出错了,请重试")


if a_randint > 70:
await setu_cmd.send("稍等,图片正在赶来的路上")
async with httpx.AsyncClient() as client:
res = await client.get(
"https://misaliu.top/api/randomfurry/?format=json"
)

url = await client.get(res.json()[0]["url"])
if url.status_code == 200:
await setu_cmd.finish(MessageSegment.image(res.json()[0]["url"]))
else:
await setu_cmd.finish("出错了,请重试")

try:
if a_randint < 20:
await setu_cmd.send("稍等,图片正在赶来的路上")

async with httpx.AsyncClient() as client:
res = await client.get(
"https://api.lolicon.app/setu/v2"
)
url = await client.get(res.json()["data"][0]["urls"]["original"])

if url.status_code == 200:
await setu_cmd.finish(MessageSegment.image(res.json()["data"][0]["urls"]["original"]))
else:
await setu_cmd.finish("出错了,请重试")


if a_randint < 70 and a_randint > 20:
await setu_cmd.send("稍等,图片正在赶来的路上")

async with httpx.AsyncClient() as client:
res = await client.get(
"https://image.anosu.top/pixiv/json"
)
url = await client.get(res.json()[0]["url"])

if url.status_code == 200:
await setu_cmd.finish(MessageSegment.image(res.json()[0]["url"]))
else:
await setu_cmd.finish("出错了,请重试")


if a_randint > 70:
await setu_cmd.send("稍等,图片正在赶来的路上")
async with httpx.AsyncClient() as client:
res = await client.get(
"https://misaliu.top/api/randomfurry/?format=json"
)

url = await client.get(res.json()["url"])
if url.status_code == 200:
await setu_cmd.finish(MessageSegment.image(res.json()["url"]))
else:
await setu_cmd.finish("出错了,请重试")

except KeyError as e:
await setu_cmd.finish(f"图片链接获取失败,请重试,code: {e}")
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "nonebot_plugin_picsetu"
version = "0.0.2"
version = "0.0.3"
description = "Default template for PDM package"
authors = [
{name = "zhongwen-4", email = "[email protected]"},
Expand Down

0 comments on commit 81cafb3

Please sign in to comment.