forked from yimo0908/nonebot_jx3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jx3_requirement.py
35 lines (28 loc) · 1.18 KB
/
jx3_requirement.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
from nonebot import on_command, CommandSession
import httpx
@on_command('条件', only_to_me=False)
async def jx3_requirement(session):
name = session.get('name', prompt='你想查询哪个奇遇的条件呢?')
report = await check_requirement(name)
await session.send(report)
# 命令解析器
@jx3_requirement.args_parser
async def _(session: CommandSession):
stripped_arg = session.current_arg_text.strip()
if session.is_first_run:
if stripped_arg:
session.state['name'] = stripped_arg
return
if not stripped_arg:
session.pause('要查询服务器名称不能为空呢,请重新输入')
session.state[session.current_key] = stripped_arg
async def check_requirement(name):
api = f'https://jx3api.com/app/getMethod?name={name}'
async with httpx.AsyncClient() as sess:
res = await sess.get(api)
data = res.json()
if data['code'] == 400:
return '消息处理失败,请检查输入的奇遇名称是否正确!'
else:
msg = ("奇遇名称:{name}\n触发方式:{method}\n奇遇前置:{need}\n加分项目:{other}\n奇遇奖励:{reward}".format(**data['data']))
return msg