From bbdc3ee077d06c95597d49f444b72087a1463b84 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Tue, 4 Jan 2022 17:03:15 +0800 Subject: [PATCH] =?UTF-8?q?jd=5Fcmd=20=E8=A7=A3=E6=9E=90=20JD=20=E5=8F=A3?= =?UTF-8?q?=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jd_cmd.py | 25 +++++++++++++++++++++++++ list.json | 10 ++++++++++ 2 files changed, 35 insertions(+) create mode 100644 jd_cmd.py diff --git a/jd_cmd.py b/jd_cmd.py new file mode 100644 index 0000000..8ad116e --- /dev/null +++ b/jd_cmd.py @@ -0,0 +1,25 @@ +""" PagerMaid module to handle jd command. """ + +from pagermaid.listener import listener +from pagermaid.utils import lang, alias_command, obtain_message, post + + +@listener(is_plugin=False, outgoing=True, command=alias_command("jd_cmd"), + description="解析 JD 口令", + parameters="") +async def jd_cmd(context): + try: + text = await obtain_message(context) + except ValueError: + return await context.edit("[jd_cmd] " + lang("msg_ValueError")) + try: + data = (await post("https://api.jds.codes/jCommand", data={"code": text}, json_body=True)).json() + except: + return await context.edit("[jd_cmd] 网络错误!") + if data["code"] != 200: + return await context.edit("[jd_cmd] 未找到 JD 口令!") + try: + data = data["data"] + await context.edit(f"[jd_cmd] [【{data['title']}】 - {data['userName']}]({data['jumpUrl']})") + except KeyError: + return await context.edit("[jd_cmd] 数据错误!") diff --git a/list.json b/list.json index ef0d651..f2380c9 100644 --- a/list.json +++ b/list.json @@ -799,6 +799,16 @@ "supported": true, "des-short": "获取假期剩余时间信息。", "des": "获取假期剩余时间信息。\n指令:-moyu" + }, + { + "name": "jd_cmd", + "version": "1.00", + "section": "chat", + "maintainer": "xtaodada", + "size": "1.00 kb", + "supported": true, + "des-short": "解析 JD 口令。", + "des": "解析 JD 口令。\n指令:-jd_cmd" } ] }