-
Notifications
You must be signed in to change notification settings - Fork 33
/
diy.py
84 lines (78 loc) · 3 KB
/
diy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import json
from random import randint, choice
from time import sleep
from pagermaid import version
from pagermaid.listener import listener
from pagermaid.utils import alias_command, client
def get_api(num):
api = ['https://api.ghser.com/saohua/?type=json',
'https://api.lovelive.tools/api/SweetNothings/?type=json',
f'https://api.lovelive.tools/api/SweetNothing/Keyword/{randint(1, 20)}',
'https://api.muxiaoguo.cn/api/tiangourj',
'https://xiaojieapi.com/api/v1/get/security',
'https://api.muxiaoguo.cn/api/Gushici'
]
name = ['骚话', '情话', '渣男语录', '舔狗语录', '保安日记', '古诗词']
return api[num], name[num]
def process_web_data(num, req):
data = json.loads(req.text)
if num == 0:
res = data['ishan']
elif num == 1 or num == 2:
if len(data['returnObj']) == 0:
res = "出错了呜呜呜 ~ API 服务器 返回了空数据。"
else:
res = choice(data['returnObj'])
elif num == 3:
res = data['data']['comment']
elif num == 4:
res = f"{data['date']} {data['week']} {data['weather']}\n{data['msg']}"
else:
poet = data['data']['Poet']
if poet == 'null':
poet = '未知'
res = f"{data['data']['Poetry']} ——《{data['data']['Poem_title']}》({poet})"
return res
@listener(is_plugin=True, outgoing=True, command=alias_command("diy"),
description="多个随机api。")
async def diy(context):
short_name = ['sao', 'qh', 'zn', 'tg', 'ba', 'gs']
try:
if not len(context.parameter) == 0:
api = context.parameter[0]
if api in short_name:
num = short_name.index(api)
api_url, name = get_api(num)
text = "正在编" + name
else:
await context.edit("正在掷🎲 . . .")
num = randint(0, 5)
api_url, name = get_api(num)
text = f"🎲点数为 `{str(num + 1)}` 正在编{name}"
else:
await context.edit("正在掷🎲 . . .")
num = randint(0, 5)
api_url, name = get_api(num)
text = f"🎲点数为 `{str(num + 1)}` 正在编{name}"
except:
await context.edit("正在掷🎲 . . .")
num = randint(0, 5)
api_url, name = get_api(num)
text = f"🎲点数为 `{str(num + 1)}` 正在编{name}"
await context.edit(text)
status = False
for _ in range(20): # 最多尝试20次
req = await client.get(api_url)
if req.status_code == 200:
try:
await context.edit(process_web_data(num, req), parse_mode='html', link_preview=False)
except:
pass
status = True
break
else:
continue
if not status:
await context.edit("出错了呜呜呜 ~ 试了好多好多次都无法访问到 API 服务器 。")
sleep(2)
await context.delete()