forked from TeamUltroid/Ultroid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculator.py
141 lines (130 loc) · 3.42 KB
/
calculator.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# Ultroid - UserBot
# Copyright (C) 2021 TeamUltroid
#
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
# PLease read the GNU Affero General Public License in
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
"""
✘ Commands Available -
•`{i}calc` - Inline Calculator
"""
import re
from . import *
@ultroid_cmd(pattern="calc")
async def icalc(e):
udB.delete("calc")
results = await e.client.inline_query(asst.me.username, "calc")
await results[0].click(e.chat_id, silent=True, hide_via=True)
await e.delete()
@in_pattern("calc")
@in_owner
async def _(e):
m = [
"AC",
"C",
"⌫",
"%",
"7",
"8",
"9",
"+",
"4",
"5",
"6",
"-",
"1",
"2",
"3",
"x",
"00",
"0",
".",
"÷",
]
tultd = [Button.inline(f"{x}", data=f"calc{x}") for x in m]
lst = list(zip(tultd[::4], tultd[1::4], tultd[2::4], tultd[3::4]))
lst.append([Button.inline("=", data="calc=")])
calc = e.builder.article("Calc", text="• Ultroid Inline Calculator •", buttons=lst)
await e.answer([calc])
@callback(re.compile("calc(.*)"))
@owner
async def _(e):
x = (e.data_match.group(1)).decode()
if x == "AC":
udB.delete("calc")
return await e.edit(
"• Ultroid Inline Calculator •",
buttons=[Button.inline("Open Calculator Again", data="recalc")],
)
elif x == "C":
udB.delete("calc")
return await e.answer("cleared")
elif x == "⌫":
get = udB.get("calc")
if get:
udB.set("calc", get[:-1])
return await e.answer(str(get[:-1]))
elif x == "%":
get = udB.get("calc")
if get:
udB.set("calc", get + "/100")
return await e.answer(str(get + "/100"))
elif x == "÷":
get = udB.get("calc")
if get:
udB.set("calc", get + "/")
return await e.answer(str(get + "/"))
elif x == "x":
get = udB.get("calc")
if get:
udB.set("calc", get + "*")
return await e.answer(str(get + "*"))
elif x == "=":
get = udB.get("calc")
if get:
if get.endswith(("*", ".", "/", "-", "+")):
get = get[:-1]
out = await calcc(get, e)
try:
num = float(out)
return await e.answer(f"Answer : {num}", cache_time=0, alert=True)
except BaseException:
udB.delete("calc")
return await e.answer("Error", cache_time=0, alert=True)
return await e.answer("None")
else:
get = udB.get("calc")
if get:
udB.set("calc", get + x)
return await e.answer(str(get + x))
udB.set("calc", x)
return await e.answer(str(x))
@callback("recalc")
@owner
async def _(e):
m = [
"AC",
"C",
"⌫",
"%",
"7",
"8",
"9",
"+",
"4",
"5",
"6",
"-",
"1",
"2",
"3",
"x",
"00",
"0",
".",
"÷",
]
tultd = [Button.inline(f"{x}", data=f"calc{x}") for x in m]
lst = list(zip(tultd[::4], tultd[1::4], tultd[2::4], tultd[3::4]))
lst.append([Button.inline("=", data="calc=")])
await e.edit("Noice Inline Calculator", buttons=lst)