-
Notifications
You must be signed in to change notification settings - Fork 33
/
base64.py
39 lines (33 loc) · 1.34 KB
/
base64.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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}`")