-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added calc module with regards to #88 #92
base: develop
Are you sure you want to change the base?
Conversation
modules/calc.js
Outdated
try { | ||
client.sendMessage( | ||
BotsApp.chatId, | ||
`output: ${output}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the argument itself instead of "output". e.g. 5+2 = 7
modules/calc.js
Outdated
output = math.evaluate(args[0]); | ||
} | ||
catch(err){ | ||
await inputSanitization.invalidFormat(err, client, BotsApp); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle invalid format error using db.js. No need of separate function.
sidekick/input-sanitization.js
Outdated
@@ -79,6 +79,14 @@ exports.isMember = async (chatId, groupMembers) => { | |||
} | |||
} | |||
|
|||
exports.invalidFormat = async(err, client, BotsApp) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not required.
modules/calc.js
Outdated
async handle(client, chat, BotsApp, args) { | ||
let output; | ||
try{ | ||
output = math.evaluate(args[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Handle the case where the user sends multiple expressions in a single command.
- Provide a list of operations allowed.
modules/calc.js
Outdated
name: "calc", | ||
description: calc.DESCRIPTION, | ||
extendedDescription: calc.EXTENDED_DESCRIPTION, | ||
demo: { isEnabled: true, text: ".calc" }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a sample expression for demo
demo: { isEnabled: true, text: ".calc 2^4+5!" }, | ||
async handle(client, chat, BotsApp, args) { | ||
let output = math.evaluate(args[0]); | ||
if(!isNaN(output)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having !
negates the condition, which equates to if not is not a number, then say invalid syntax. This means that if the output is a number, then say invalid syntax, which is not what we want.
if(!isNaN(output)) { | |
if(isNaN(output)) { |
extendedDescription: calc.EXTENDED_DESCRIPTION, | ||
demo: { isEnabled: true, text: ".calc 2^4+5!" }, | ||
async handle(client, chat, BotsApp, args) { | ||
let output = math.evaluate(args[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try { | ||
client.sendMessage( | ||
BotsApp.chatId, | ||
`${args[0]} = ${output}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can bold out the output using *, looks much better
extendedDescription: calc.EXTENDED_DESCRIPTION, | ||
demo: { isEnabled: true, text: ".calc 2^4+5!" }, | ||
async handle(client, chat, BotsApp, args) { | ||
let output = math.evaluate(args[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of restricting the user to add their expressions without any spaces (more values in the args array), it's better if we concatenate the full array in a single string before using the evaluate call.
Also, @IsomerX resolve the conversation threads with prashant for the issues you have resolved already. |
User just needs to type .calc (followed by any math equation)
for example:
.calc 2+2