base64 Base64编码/解码 (#215)

* 添加Base64编码/解码
This commit is contained in:
zhxy-CN 2022-02-13 13:20:05 +08:00 committed by GitHub
parent c16a4c52c3
commit 8d75af6ff4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 0 deletions

39
base64.py Normal file
View File

@ -0,0 +1,39 @@
from base64 import b64decode, b64encode
from pagermaid import version
from pagermaid.listener import listener
from pagermaid.utils import attach_log, execute, alias_command, obtain_message
@listener(outgoing=True, command=alias_command("b64e"),
description="将文本转为Base64"
,parameters="<text>")
async def b64e(context):
try:
msg = await obtain_message(context)
except:
return await context.edit("`出错了呜呜呜 ~ 无效的参数。`")
result = b64encode(msg.encode("utf-8")).decode("utf-8")
if result:
if len(result) > 4096:
return await attach_log(result, context.chat_id, "output.log", context.id)
await context.edit(f"`{result}`")
@listener(outgoing=True, command=alias_command("b64d"),
description="将Base64转为文本"
,parameters="<text>")
async def b64d(context):
try:
msg = await obtain_message(context)
except:
return await context.edit("`出错了呜呜呜 ~ 无效的参数。`")
try:
result = b64decode(msg).decode("utf-8")
except:
return await context.edit("`出错了呜呜呜 ~ 无效的参数。`")
if result:
if len(result) > 4096:
return await attach_log(result, context.chat_id, "output.log", context.id)
await context.edit(f"`{msg}` ==> `{result}`")

View File

@ -889,6 +889,16 @@
"supported": true, "supported": true,
"des-short": "查询英语单词/俚语的意思。", "des-short": "查询英语单词/俚语的意思。",
"des": "查询英语单词/俚语的意思。\n指令-dictionary -urbandictionary" "des": "查询英语单词/俚语的意思。\n指令-dictionary -urbandictionary"
},
{
"name": "base64",
"version": "1.00",
"section": "chat",
"maintainer": "zhxycn,xtaodada",
"size": "1.4 kb",
"supported": true,
"des-short": "Base64编码/解码。",
"des": "Base64编码/解码。\n指令-b64e -b64d"
} }
] ]
} }