mirror of
https://github.com/TeamPGM/PagerMaid_Plugins.git
synced 2024-11-23 13:37:43 +00:00
calculator 新增进制转换功能 (#4)
This commit is contained in:
parent
c84edaf2ff
commit
1b2a4a10ae
@ -1,11 +1,10 @@
|
|||||||
from pagermaid import version
|
|
||||||
from pagermaid.listener import listener
|
from pagermaid.listener import listener
|
||||||
from pagermaid.utils import attach_log, execute, alias_command
|
from pagermaid.utils import attach_log, execute, alias_command
|
||||||
|
|
||||||
|
|
||||||
@listener(is_plugin=False, outgoing=True, command=alias_command("cal"),
|
@listener(is_plugin=False, outgoing=True, command=alias_command("cal"),
|
||||||
description="计算",
|
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="<加减乘除>")
|
parameters="<基本运算>")
|
||||||
async def cal(context):
|
async def cal(context):
|
||||||
command = context.arguments
|
command = context.arguments
|
||||||
if context.is_channel and not context.is_group:
|
if context.is_channel and not context.is_group:
|
||||||
@ -28,3 +27,31 @@ async def cal(context):
|
|||||||
await context.edit(f"{command}=\n`{result}`")
|
await context.edit(f"{command}=\n`{result}`")
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@listener(is_plugin=False, outgoing=True, command=alias_command("con"),
|
||||||
|
description="换算\n示例:\n`-con 2 99`将99转换为2进制",
|
||||||
|
parameters="<进制(数字)> <数值>")
|
||||||
|
async def con(context):
|
||||||
|
command = context.arguments.split()
|
||||||
|
if context.is_channel and not context.is_group:
|
||||||
|
await context.edit("`出错了呜呜呜 ~ 当前 PagerMaid-Modify 的配置禁止在频道中执行此命令。`")
|
||||||
|
return
|
||||||
|
|
||||||
|
if not command:
|
||||||
|
await context.edit("`出错了呜呜呜 ~ 无效的参数。`")
|
||||||
|
return
|
||||||
|
|
||||||
|
obase = command[0].upper().strip()
|
||||||
|
num = command[1].upper().strip()
|
||||||
|
await context.edit(f"{num}")
|
||||||
|
cmd = f'echo "obase={obase};{num}" | bc'
|
||||||
|
result = await execute(cmd)
|
||||||
|
|
||||||
|
if result:
|
||||||
|
if len(result) > 4096:
|
||||||
|
await attach_log(result, context.chat_id, "output.log", context.id)
|
||||||
|
return
|
||||||
|
|
||||||
|
await context.edit(f"{num}=\n`{result}`\n{obase}进制")
|
||||||
|
else:
|
||||||
|
return
|
@ -332,13 +332,13 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "calculator",
|
"name": "calculator",
|
||||||
"version": "1.021",
|
"version": "1.1",
|
||||||
"section": "chat",
|
"section": "chat",
|
||||||
"maintainer": "Pentacene",
|
"maintainer": "Pentacene,zhxycn",
|
||||||
"size": "1.0 kb",
|
"size": "1.48 kb",
|
||||||
"supported": true,
|
"supported": true,
|
||||||
"des-short": "小型计算器",
|
"des-short": "小型计算器",
|
||||||
"des": "/cal 6+4。"
|
"des": "支持基本运算(加减乘除乘方开方)及进制转换。\n命令:-cal [表达式] -con [进制] [数字]\n例如:`-cal 1+2` `-con 16 10`"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "paolu",
|
"name": "paolu",
|
||||||
|
Loading…
Reference in New Issue
Block a user