From 68a60776f062fcc47d5ac19689321b3dbc39c4b1 Mon Sep 17 00:00:00 2001 From: Ricky8955555 Date: Sun, 26 Mar 2023 16:25:59 +0800 Subject: [PATCH] =?UTF-8?q?idna=20=E5=9B=BD=E9=99=85=E5=8C=96=E5=9F=9F?= =?UTF-8?q?=E5=90=8D=20(IDNA)=20=E7=BC=96=E7=A0=81=E8=BD=AC=E6=8D=A2?= =?UTF-8?q?=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: xtaodada --- idna/DES.md | 5 +++++ idna/main.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 idna/DES.md create mode 100644 idna/main.py diff --git a/idna/DES.md b/idna/DES.md new file mode 100644 index 0000000..9c49a52 --- /dev/null +++ b/idna/DES.md @@ -0,0 +1,5 @@ +国际化域名 (IDNA) 编码转换工具 + +指令: +- `,punyencode <待编码内容>` (编码至 Punycode) +- `,punydecode <待解码内容>` (从 Punycode 解码) diff --git a/idna/main.py b/idna/main.py new file mode 100644 index 0000000..6746af7 --- /dev/null +++ b/idna/main.py @@ -0,0 +1,29 @@ +# pyright: basic + + +from pagermaid.enums import Message +from pagermaid.listener import listener + + +@listener(command="punyencode", description="编码至 Punycode", parameters="[待编码内容]") +async def punyencode(message: Message) -> None: + if message.arguments: + try: + result = message.arguments.encode("idna").decode() + except Exception: + result = "呜呜呜 ~ 转换失败了,可能含有非法字符。" + else: + result = "请输入参数" + await message.edit(f"`{result}`") + + +@listener(command="punydecode", description="从 Punycode 解码", parameters="[待解码内容]") +async def punydecode(message: Message) -> None: + if message.arguments: + try: + result = message.arguments.encode().decode("idna") + except Exception: + result = "呜呜呜 ~ 转换失败了,可能含有非法字符。" + else: + result = "请输入参数" + await message.edit(f"`{result}`")