From 8bcc781ce840518a8cb18ce39aa199a26c50747c Mon Sep 17 00:00:00 2001 From: zhxy-CN Date: Sun, 29 May 2022 12:00:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=20(#3)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add some plugins * Update main.py * Update main.py Co-authored-by: omg-xtao <100690902+omg-xtao@users.noreply.github.com> --- base64/main.py | 34 ++++++++++++++++++++++++++++++++++ calculator/main.py | 42 ++++++++++++++++++++++++++++++++++++++++++ list.json | 20 ++++++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 base64/main.py create mode 100644 calculator/main.py diff --git a/base64/main.py b/base64/main.py new file mode 100644 index 0000000..48dc115 --- /dev/null +++ b/base64/main.py @@ -0,0 +1,34 @@ +from pyrogram import Client +from pagermaid.listener import listener +from pagermaid.utils import Message +from base64 import b64decode, b64encode + + +@listener(command="b64e", + description="将文本转为Base64", + parameters="") +async def b64e(_: Client, message: Message): + msg = message.arguments + if not msg: + return await message.edit("`出错了呜呜呜 ~ 无效的参数。`") + + result = b64encode(msg.encode("utf-8")).decode("utf-8") + + if result: + await message.edit(f"`{result}`") + + +@listener(command="b64d", + description="将Base64转为文本", + parameters="") +async def b64d(_: Client, message: Message): + msg = message.arguments + if not msg: + return await message.edit("`出错了呜呜呜 ~ 无效的参数。`") + + try: + result = b64decode(msg).decode("utf-8") + except: + return await message.edit("`出错了呜呜呜 ~ 无效的参数。`") + if result: + await message.edit(f"`{result}`") diff --git a/calculator/main.py b/calculator/main.py new file mode 100644 index 0000000..ac5d9c2 --- /dev/null +++ b/calculator/main.py @@ -0,0 +1,42 @@ +from pyrogram import Client +from pagermaid.listener import listener +from pagermaid.utils import Message, execute + + +@listener(command="cal", + description="计算\n示例:\n`-cal 1+1`加法\n`-cal 2-1`减法\n`-cal 1*2`乘法\n`-cal 4/2`除法\n`-cal 4^2`幂运算\n`-cal sqrt(4)`开方", + parameters="<基本运算>") +async def cal(_: Client, message: Message): + command = message.arguments + if not command: + await message.edit("`出错了呜呜呜 ~ 无效的参数。`") + return + + await message.edit(f"{command}") + cmd = f'echo "scale=4;{command}" | bc' + result = await execute(cmd) + + if result: + await message.edit(f"{command}=\n`{result}`") + else: + return + +@listener(command="con", + description="换算\n示例:\n`-con 2 99`将99转换为2进制", + parameters="<进制(数字)> <数值>") +async def con(_: Client, message: Message): + command = message.arguments.split() + if not command: + await message.edit("`出错了呜呜呜 ~ 无效的参数。`") + return + + obase = command[0].upper().strip() + num = command[1].upper().strip() + await message.edit(f"{num}") + cmd = f'echo "obase={obase};{num}" | bc' + result = await execute(cmd) + + if result: + await message.edit(f"{num}=\n`{result}`\n{obase}进制") + else: + return diff --git a/list.json b/list.json index f05e261..b8e3d30 100644 --- a/list.json +++ b/list.json @@ -49,6 +49,26 @@ "supported": true, "des-short": "每日英语", "des": "支持群订阅" + }, + { + "name": "calculator", + "version": "1.1", + "section": "chat", + "maintainer": "Pentacene,zhxycn", + "size": "1.48 kb", + "supported": true, + "des-short": "小型计算器", + "des": "支持基本运算(加减乘除乘方开方)及进制转换。\n命令:,cal [表达式] ,con [进制] [数字]\n例如:`,cal 1+2` `,con 16 10`" + }, + { + "name": "base64", + "version": "1.00", + "section": "chat", + "maintainer": "zhxycn,xtaodada", + "size": "1.14 kb", + "supported": true, + "des-short": "Base64编码/解码。", + "des": "Base64编码/解码。\n命令:,b64e ,b64d" } ] }