1+ /* A Lightning Fast Multi-Purpose Calculator Bot.
2+
3+ Dev: Mohammed Sohail
4+ Version: 1.1.0
5+ Demo: @powercalcbot
6+
7+ */
8+
9+ const nodeogram = require ( 'nodeogram' ) ,
10+ bot = new nodeogram . Bot ( 'token' ) ;
11+ const math = require ( 'mathjs' ) ;
12+ const Keyboard = nodeogram . Keyboard ;
13+
14+ var math2 = math . create ( {
15+ matrix : 'Array'
16+ } ) ;
17+
18+ bot . init ( ) ;
19+
20+ var keyboard = new Keyboard ( ) ;
21+ keyboard . addButton ( 0 , 0 , { text : "Pi" , callback_data : "π = 3.141592653589793 " } ) ;
22+ keyboard . addButton ( 0 , 1 , { text : "Imaginary Unit" , callback_data : "i = √–1 " } ) ;
23+ keyboard . addButton ( 1 , 0 , { text : "Euler's Number" , callback_data : "e = 2.718281828459045 " } ) ;
24+ keyboard . addButton ( 1 , 1 , { text : "Golden Ratio" , callback_data : "phi = 2.718281828459045 " } ) ;
25+ keyboard . addButton ( 2 , 0 , { text : "Pythagoras' constant" , callback_data : "√2 = 1.414213562373095 " } ) ;
26+ keyboard . addButton ( 2 , 1 , { text : "Theodorus' constant" , callback_data : "√3 = 1.732050807568877 " } ) ;
27+ keyboard . addButton ( 3 , 0 , { text : "Omega Constant" , callback_data : "Ω = 0.567143290409783 " } ) ;
28+ keyboard . addButton ( 3 , 1 , { text : "Gravity Constant" , callback_data : "G = 9.80665 (m/s)2 " } ) ;
29+ keyboard . toInline ( ) ;
30+
31+ bot . command ( 'start' , 'Displays "usage" For the first time' , true , ( args , message ) => {
32+ message . reply ( "*Welcome To PowerCalcBot*\n\n/help\n/examples\n\n⚒`Made By` @kamikazechaser" , { parse_mode : 'Markdown' } )
33+ } ) ;
34+
35+ bot . command ( 'examples' , 'Examples of commands' , false , ( args , message ) => {
36+ message . reply ( "`/evaluate 2 + 3 +7 - 3 = 9`\n`/evaluate 3 * 8 / 6.58 +0.32 - 2.01 = 1.9574`\n`/evaluate cos(45 deg) * sqrt(625) = 13.1330`\n`/permutate 5 = 120`\n`/nthroot 9 2 = 3, as 3^2 == 9`\n`/exp 2 = 7.3891`\n`/range 1 11 = An Matrix of The Range`" , { parse_mode : 'Markdown' } )
37+ } ) ;
38+
39+ bot . command ( 'root' , 'Returns the square root of a number. Usage /root [num]' , false , ( args , message ) => {
40+ message . reply ( math . sqrt ( args [ 0 ] ) ) ;
41+ } ) ;
42+
43+ bot . command ( 'range' , 'Returns the range between two integers in Matrix form. Usage /range [num1] [num2]' , false , ( args , message ) => {
44+ message . reply ( math2 . range ( args [ 0 ] , args [ 1 ] ) ) ;
45+ } ) ;
46+
47+ bot . command ( 'random' , 'Generates a random number. Usage /random' , false , ( args , message ) => {
48+ message . reply ( Math . floor ( ( Math . random ( ) * 100 ) + 1 ) ) ;
49+ } ) ;
50+
51+ bot . command ( 'log' , 'Returns the base 10 logarithm of a number. Usage /log [num]' , false , ( args , message ) => {
52+ message . reply ( Math . log10 ( args [ 0 ] ) ) ;
53+ } ) ;
54+
55+ bot . command ( 'tan' , 'Returns the tangent of an angle. Usage /tan [num]' , false , ( args , message ) => {
56+ message . reply ( Math . tan ( args [ 0 ] / 180 * Math . PI ) ) ;
57+ } ) ;
58+
59+ bot . command ( 'sin' , 'Returns the sine of an angle. Usage /sin [num]' , false , ( args , message ) => {
60+ message . reply ( Math . sin ( args [ 0 ] / 180 * Math . PI ) ) ;
61+ } ) ;
62+
63+ bot . command ( 'cos' , 'Returns the cosine of an angle. Usage /cos [num]' , false , ( args , message ) => {
64+ message . reply ( Math . cos ( args [ 0 ] / 180 * Math . PI ) ) ;
65+ } ) ;
66+
67+ bot . command ( 'round' , 'Rounds the number to the nearest integer. Usage /round [num]' , false , ( args , message ) => {
68+ message . reply ( Math . round ( args [ 0 ] ) ) ;
69+ } ) ;
70+
71+ bot . command ( 'permutate' , 'Returns total number of objects in a permutation. Usage /permutate [num]' , false , ( args , message ) => {
72+ message . reply ( 'permutations:' + ' ' + math . permutations ( args [ 0 ] ) ) ;
73+ } ) ;
74+
75+ bot . command ( 'power' , 'Returns the power of a number to the other. Usage /power [num1] [num2]' , false , ( args , message ) => {
76+ message . reply ( Math . pow ( args [ 0 ] , args [ 1 ] ) ) ;
77+ } ) ;
78+
79+ bot . command ( 'nthroot' , 'Returns the nth root solution. Usage /nthroot [value] [its root]' , false , ( args , message ) => {
80+ message . reply ( math . nthRoot ( args [ 0 ] , args [ 1 ] ) ) ;
81+ } ) ;
82+
83+ bot . command ( 'antilog' , 'Returns a number to the power of ten. Usage /antilog [num]' , false , ( args , message ) => {
84+ message . reply ( Math . pow ( 10 , args [ 0 ] ) ) ;
85+ } ) ;
86+
87+ bot . command ( 'evaluate' , 'Evaluates an expression, look at the /examples command for more information. Usage /evalaute ..' , false , ( args , message ) => {
88+ message . reply ( math . eval ( args . join ( " " ) ) ) ;
89+ } ) ;
90+
91+ bot . command ( 'lcm' , 'Returns the Least Coomon Multiple of two numbers. Usage /lcm [num1] [num2]' , false , ( args , message ) => {
92+ message . reply ( math . lcm ( args [ 0 ] , args [ 1 ] ) ) ;
93+ } ) ;
94+
95+ bot . command ( 'gcd' , 'Returns the Highest Common Factor of two numbers. usage /gcd [num1] [num2]' , false , ( args , message ) => {
96+ message . reply ( math . gcd ( args [ 0 ] , args [ 1 ] ) ) ;
97+ } ) ;
98+
99+ bot . command ( 'cube' , 'Returns the cube of the number. Usage /square [num]' , false , ( args , message ) => {
100+ message . reply ( math . cube ( args [ 0 ] ) ) ;
101+ } ) ;
102+
103+ bot . command ( 'cbrt' , 'Returns the cuberoot of the number. Usage /square [num]' , false , ( args , message ) => {
104+ message . reply ( math . cbrt ( args [ 0 ] ) ) ;
105+ } ) ;
106+
107+ bot . command ( 'square' , 'Returns the square of the number. Usage /square [num]' , false , ( args , message ) => {
108+ message . reply ( math . square ( args [ 0 ] ) ) ;
109+ } ) ;
110+
111+ bot . command ( 'exp' , 'Returns the exponent to the base of "e". Usage /square [num]' , false , ( args , message ) => {
112+ message . reply ( math . exp ( args [ 0 ] ) ) ;
113+ } ) ;
114+
115+ bot . command ( 'constants' , 'Mathematical Constants' , false , ( args , message ) => {
116+ message . reply ( "Mathematical Constants" , { reply_markup : keyboard } ) ;
117+ } ) ;
118+
119+ bot . on ( 'callback_query' , ( query ) => {
120+ query . answer ( '✅' , true ) ;
121+ if ( query . message ) query . message . editText ( `${ query . data } !` )
122+ } ) ;
0 commit comments