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}`")