PagerMaid_Plugins/jd_cmd.py

27 lines
1.0 KiB
Python
Raw Normal View History

2022-01-04 09:03:15 +00:00
""" PagerMaid module to handle jd command. """
2022-01-18 08:47:20 +00:00
from pagermaid import version
2022-01-04 09:03:15 +00:00
from pagermaid.listener import listener
2022-01-20 13:03:15 +00:00
from pagermaid.utils import lang, alias_command, obtain_message, client
2022-01-04 09:03:15 +00:00
@listener(is_plugin=False, outgoing=True, command=alias_command("jd_cmd"),
description="解析 JD 口令",
parameters="<JD 口令>")
async def jd_cmd(context):
try:
text = await obtain_message(context)
except ValueError:
return await context.edit("[jd_cmd] " + lang("msg_ValueError"))
try:
2022-02-10 06:38:21 +00:00
data = (await client.post("https://api.jds.codes/jd/jCommand", json={"code": text})).json()
2022-01-04 09:03:15 +00:00
except:
return await context.edit("[jd_cmd] 网络错误!")
if data["code"] != 200:
return await context.edit("[jd_cmd] 未找到 JD 口令!")
try:
data = data["data"]
2022-01-04 09:07:38 +00:00
await context.edit(f"【jd_cmd】 [【{data['title']}】 - {data['userName']}]({data['jumpUrl']})")
2022-01-04 09:03:15 +00:00
except KeyError:
return await context.edit("[jd_cmd] 数据错误!")