From 8d75af6ff4a7fa26668dfef409221449582877db Mon Sep 17 00:00:00 2001 From: zhxy-CN Date: Sun, 13 Feb 2022 13:20:05 +0800 Subject: [PATCH] =?UTF-8?q?base64=20Base64=E7=BC=96=E7=A0=81/=E8=A7=A3?= =?UTF-8?q?=E7=A0=81=20(#215)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 添加Base64编码/解码 --- base64.py | 39 +++++++++++++++++++++++++++++++++++++++ list.json | 10 ++++++++++ 2 files changed, 49 insertions(+) create mode 100644 base64.py diff --git a/base64.py b/base64.py new file mode 100644 index 0000000..5e5caf4 --- /dev/null +++ b/base64.py @@ -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="") +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="") +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}`") diff --git a/list.json b/list.json index 63834c0..c2aa8c4 100644 --- a/list.json +++ b/list.json @@ -889,6 +889,16 @@ "supported": true, "des-short": "查询英语单词/俚语的意思。", "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" } ] }