Team Ai
Apppublic

azils3/bash

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
calculator.py154 linesDownload Raw Back to plugins
1# Ultroid - UserBot2# Copyright (C) 2021-2025 TeamUltroid3#4# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >5# PLease read the GNU Affero General Public License in6# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.7 8 9from . import get_help10 11__doc__ = get_help("help_calculator")12 13import re14 15from . import Button, asst, callback, get_string, in_pattern, udB, ultroid_cmd16 17CALC = {}18 19m = [20    "AC",21    "C",22    "⌫",23    "%",24    "7",25    "8",26    "9",27    "+",28    "4",29    "5",30    "6",31    "-",32    "1",33    "2",34    "3",35    "x",36    "00",37    "0",38    ".",39    "÷",40]41tultd = [Button.inline(f"{x}", data=f"calc{x}") for x in m]42lst = list(zip(tultd[::4], tultd[1::4], tultd[2::4], tultd[3::4]))43lst.append([Button.inline("=", data="calc=")])44 45 46@ultroid_cmd(pattern="calc")47async def icalc(e):48    udB.del_key("calc")49    if e.client._bot:50        return await e.reply(get_string("calc_1"), buttons=lst)51    results = await e.client.inline_query(asst.me.username, "calc")52    await results[0].click(e.chat_id, silent=True, hide_via=True)53    await e.delete()54 55 56@in_pattern("calc", owner=True)57async def _(e):58    calc = e.builder.article("Calc", text=get_string("calc_1"), buttons=lst)59    await e.answer([calc])60 61 62@callback(re.compile("calc(.*)"), owner=True)63async def _(e):64    x = (e.data_match.group(1)).decode()65    user = e.query.user_id66    get = None67    if x == "AC":68        if CALC.get(user):69            CALC.pop(user)70        await e.edit(71            get_string("calc_1"),72            buttons=[Button.inline(get_string("calc_2"), data="recalc")],73        )74    elif x == "C":75        if CALC.get(user):76            CALC.pop(user)77        await e.answer("cleared")78    elif x == "⌫":79        if CALC.get(user):80            get = CALC[user]81        if get:82            CALC.update({user: get[:-1]})83            await e.answer(str(get[:-1]))84    elif x == "%":85        if CALC.get(user):86            get = CALC[user]87        if get:88            CALC.update({user: f"{get}/100"})89            await e.answer(str(f"{get}/100"))90    elif x == "÷":91        if CALC.get(user):92            get = CALC[user]93        if get:94            CALC.update({user: f"{get}/"})95            await e.answer(str(f"{get}/"))96    elif x == "x":97        if CALC.get(user):98            get = CALC[user]99        if get:100            CALC.update({user: f"{get}*"})101            await e.answer(str(f"{get}*"))102    elif x == "=":103        if CALC.get(user):104            get = CALC[user]105        if get:106            if get.endswith(("*", ".", "/", "-", "+")):107                get = get[:-1]108            out = eval(get)109            try:110                num = float(out)111                await e.answer(f"Answer : {num}", cache_time=0, alert=True)112            except BaseException:113                CALC.pop(user)114                await e.answer(get_string("sf_8"), cache_time=0, alert=True)115        await e.answer("None")116    else:117        if CALC.get(user):118            get = CALC[user]119        if get:120            CALC.update({user: get + x})121            return await e.answer(str(get + x))122        CALC.update({user: x})123        await e.answer(str(x))124 125 126@callback("recalc", owner=True)127async def _(e):128    m = [129        "AC",130        "C",131        "⌫",132        "%",133        "7",134        "8",135        "9",136        "+",137        "4",138        "5",139        "6",140        "-",141        "1",142        "2",143        "3",144        "x",145        "00",146        "0",147        ".",148        "÷",149    ]150    tultd = [Button.inline(f"{x}", data=f"calc{x}") for x in m]151    lst = list(zip(tultd[::4], tultd[1::4], tultd[2::4], tultd[3::4]))152    lst.append([Button.inline("=", data="calc=")])153    await e.edit(get_string("calc_1"), buttons=lst)154