PagerMaid_Plugins/cosplay-multi.py

67 lines
2.3 KiB
Python
Raw Normal View History

from random import randint, random
2020-08-23 14:54:48 +00:00
from requests import get
2022-01-18 08:47:20 +00:00
from pagermaid import version
2020-08-23 14:54:48 +00:00
from pagermaid.listener import listener
2021-06-16 07:09:40 +00:00
from pagermaid.utils import alias_command
2020-08-23 14:54:48 +00:00
from os import remove
2021-06-16 07:09:40 +00:00
@listener(is_plugin=True, outgoing=True, command=alias_command("cosm"),
2020-08-23 14:54:48 +00:00
description="多网站随机获取cosplay图片会自动重试哦")
2021-06-16 07:09:40 +00:00
async def cosm(context):
2020-08-23 14:54:48 +00:00
await context.edit("获取中 . . .")
status = False
2021-06-16 07:09:40 +00:00
for _ in range(20): # 最多重试20次
website = randint(0, 6)
filename = "cosm" + str(random())[2:] + ".png"
try:
if website == 0:
img = get("https://api.helloworld.la/xiezhen_cosplay.php")
elif website == 1:
img = get("https://api.vvhan.com/api/mobil.girl?type=json")
elif website == 2:
img = get("https://api.helloworld.la/xiezhen_weimei.php")
elif website == 3:
img = get("http://api.rosysun.cn/cos")
elif website == 4:
img = get("https://uploadbeta.com/api/pictures/random/?key=%E5%8A%A8%E6%BC%AB")
elif website == 5:
img = get("https://uploadbeta.com/api/pictures/random/?key=%E4%BA%8C%E6%AC%A1%E5%85%83")
2021-06-16 07:09:40 +00:00
else:
img = get("https://xn--wcs142h.herokuapp.com/")
if img.status_code == 200:
if website == 3:
img = get(img.content)
if img.status_code != 200:
2021-06-16 07:09:40 +00:00
continue # 再试一次
with open(filename, 'wb') as f:
f.write(img.content)
await context.edit("上传中 . . .")
2021-06-16 07:09:40 +00:00
await context.client.send_file(context.chat_id, filename)
status = True
2021-06-16 07:09:40 +00:00
break # 成功了就赶紧结束啦!
except:
try:
remove(filename)
except:
pass
continue
try:
remove(filename)
except:
pass
try:
await context.delete()
except:
pass
2020-08-23 14:54:48 +00:00
if not status:
try:
remove(filename)
except:
pass
try:
await context.delete()
except:
pass
2021-06-16 07:09:40 +00:00
await context.client.send_message(context.chat_id, "出错了呜呜呜 ~ 试了好多好多次都无法访问到服务器 。")