idna morse 支持回复消息

This commit is contained in:
Ricky8955555 2023-03-29 16:55:29 +08:00 committed by GitHub
parent d2399e10a0
commit 693b45ea60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 42 deletions

View File

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

View File

@ -5,25 +5,23 @@ 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:
@listener(command="punyencode", description="编码至 Punycode", parameters="[待编码内容] (支持回复消息)")
async def punyencode(message: Message):
if not (text := message.obtain_message()):
return await message.edit("请输入参数")
try:
result = message.arguments.encode("idna").decode()
encoded = text.encode("idna").decode()
except Exception:
result = "呜呜呜 ~ 转换失败了,可能含有非法字符。"
else:
result = "请输入参数"
await message.edit(f"`{result}`")
return await message.edit("呜呜呜 ~ 转换失败了,可能含有非法字符。")
await message.edit(f"`{encoded}`")
@listener(command="punydecode", description="从 Punycode 解码", parameters="[待解码内容]")
async def punydecode(message: Message) -> None:
if message.arguments:
@listener(command="punydecode", description="从 Punycode 解码", parameters="[待解码内容] (支持回复消息)")
async def punydecode(message: Message):
if not (text := message.obtain_message()):
return await message.edit("请输入参数")
try:
result = message.arguments.encode().decode("idna")
decoded = text.encode().decode("idna")
except Exception:
result = "呜呜呜 ~ 转换失败了,可能含有非法字符。"
else:
result = "请输入参数"
await message.edit(f"`{result}`")
return await message.edit("呜呜呜 ~ 转换失败了,可能含有非法字符。")
await message.edit(f"`{decoded}`")

View File

@ -1,5 +1,5 @@
摩斯密码转换 (支持非英文)
指令:
- `,enmorse <待转换文本>` (转换指定文本到摩斯密码)
- `,demorse <摩斯密码>` (转换摩斯密码到明文)
- `,enmorse <待转换文本> (支持回复消息)` (转换指定文本到摩斯密码)
- `,demorse <摩斯密码> (支持回复消息)` (转换摩斯密码到明文)

View File

@ -91,25 +91,23 @@ def decode(morse: str) -> str:
)
@listener(command="enmorse", description="转换指定文本到摩斯密码", parameters="[待转换文本]")
@listener(command="enmorse", description="转换指定文本到摩斯密码", parameters="[待转换文本] (支持回复消息)")
async def enmorse(message: Message):
if message.arguments:
if not (text := message.obtain_message()):
return await message.edit("请输入参数")
try:
result = encode(message.arguments)
morse = encode(text)
except Exception:
result = "呜呜呜 ~ 转换失败了,可能含有非法字符。"
else:
result = "请输入参数"
await message.edit(f"`{result}`")
return await message.edit("呜呜呜 ~ 转换失败了,可能含有非法字符。")
await message.edit(f"`{morse}`")
@listener(command="demorse", description="转换摩斯密码到明文", parameters="[摩斯密码]")
@listener(command="demorse", description="转换摩斯密码到明文", parameters="[摩斯密码] (支持回复消息)")
async def demorse(message: Message):
if message.arguments:
if not (morse := message.obtain_message()):
return await message.edit("请输入参数")
try:
result = decode(message.arguments)
text = decode(morse)
except Exception:
result = "呜呜呜 ~ 转换失败了,可能含有非法字符。"
else:
result = "请输入参数"
await message.edit(f"`{result}`")
return await message.edit("呜呜呜 ~ 转换失败了,可能含有非法字符。")
await message.edit(f"`{text}`")