-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Added calc module with regards to #88 #92
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
base: develop
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| const { MessageType } = require("@adiwajshing/baileys"); | ||
| const Strings = require("../lib/db"); | ||
| const format = require("python-format-js"); | ||
| const inputSanitization = require("../sidekick/input-sanitization"); | ||
| const calc = Strings.calc; | ||
| const math = require("mathjs"); | ||
|
|
||
| module.exports = { | ||
| name: "calc", | ||
| description: calc.DESCRIPTION, | ||
| extendedDescription: calc.EXTENDED_DESCRIPTION, | ||
| demo: { isEnabled: true, text: ".calc" }, | ||
| async handle(client, chat, BotsApp, args) { | ||
| let output; | ||
| try{ | ||
| output = math.evaluate(args[0]); | ||
|
||
| } | ||
| catch(err){ | ||
| await inputSanitization.invalidFormat(err, client, BotsApp); | ||
|
||
| return; | ||
| } | ||
| try { | ||
| client.sendMessage( | ||
| BotsApp.chatId, | ||
| `output: ${output}`, | ||
|
||
| MessageType.text | ||
| ).catch(err => inputSanitization.handleError(err, client, BotsApp)); | ||
| } catch (err) { | ||
| await inputSanitization.handleError(err, client, BotsApp); | ||
| } | ||
| }, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,6 +79,14 @@ exports.isMember = async (chatId, groupMembers) => { | |
| } | ||
| } | ||
|
|
||
| exports.invalidFormat = async(err, client, BotsApp) => { | ||
|
||
| client.sendMessage( | ||
| BotsApp.chatId, | ||
| "*Invalid format.*\nApproved Syntax:\n```1. 1 + 2``` \n```2. (1*2) + 2``` \n```3. 4! + 2^2```", | ||
| MessageType.text | ||
| ); | ||
| } | ||
|
|
||
| exports.handleError = async(err, client, BotsApp, customMessage = "```Something went wrong. The error has been logged in log chats```") => { | ||
| console.log(chalk.redBright.bold("[ERROR] " + err)); | ||
| data = { | ||
|
|
||
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