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

View File

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

View File

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