idna 国际化域名 (IDNA) 编码转换工具

Co-authored-by: xtaodada <xtao@xtaolink.cn>
This commit is contained in:
Ricky8955555 2023-03-26 16:25:59 +08:00 committed by GitHub
parent 226c10f9aa
commit 68a60776f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 0 deletions

5
idna/DES.md Normal file
View File

@ -0,0 +1,5 @@
国际化域名 (IDNA) 编码转换工具
指令:
- `,punyencode <待编码内容>` (编码至 Punycode)
- `,punydecode <待解码内容>` (从 Punycode 解码)

29
idna/main.py Normal file
View File

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