import asyncio
from pyrogram import Client, filters
from pyrogram.types import Message
from utils.misc import modules_help, prefix
@Client.on_message(filters.command('calc', prefix) & filters.me)
async def calc(_, message: Message):
if len(message.command) <= 1:
return
args = ' '.join(message.command[1:])
try:
result = str(eval(args)) # noqa: S307
if len(result) > 4096:
for i, x in enumerate(range(0, len(result), 4096)):
if i == 0:
await message.edit(
f'{args}={result[x : x + 4000]}',
parse_mode='HTML',
)
else:
await message.reply(f'{result[x : x + 4096]}', parse_mode='HTML')
await asyncio.sleep(0.18)
else:
await message.edit(f'{args}={result}', parse_mode='HTML')
except Exception as e:
await message.edit(f'{args}=={e}', parse_mode='HTML')
modules_help['calculator'] = {
'calc [expression]*': 'solve a math problem\n'
'+ – addition\n'
'– – subtraction\n'
'* – multiplication\n'
'/ – division\n'
'** – degree'
}