From d7adb17b37a267bf512cf669a3dc74c2601ca157 Mon Sep 17 00:00:00 2001 From: Mohammed Ashab Uddin Date: Tue, 21 Jul 2020 13:58:19 +0400 Subject: [PATCH] slight changes --- whatsapp-web.js/src/models/data.js | 4 +-- .../src/userInteraction/messages.js | 31 ++++++++++++------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/whatsapp-web.js/src/models/data.js b/whatsapp-web.js/src/models/data.js index 39cbd95..d792761 100644 --- a/whatsapp-web.js/src/models/data.js +++ b/whatsapp-web.js/src/models/data.js @@ -1,5 +1,5 @@ -const { User } = require("../models/user"); -const { Website } = require("../models/website"); +const { User } = require("./user"); +const { Website } = require("./website"); module.exports.data = new StructuredData(); diff --git a/whatsapp-web.js/src/userInteraction/messages.js b/whatsapp-web.js/src/userInteraction/messages.js index 1f39c14..e23b262 100644 --- a/whatsapp-web.js/src/userInteraction/messages.js +++ b/whatsapp-web.js/src/userInteraction/messages.js @@ -1,20 +1,26 @@ -const { Command } = require("./commands"); -const { onWG } = require("../businessLogic/logic"); +const { Command } = require("../models/commands"); +const logic = require("../businessLogic/logic"); /////////// //add the commands here /////////// const commands = [ - new Command({ + //User command command: 'wg', - message : [ - `stop it and get some help by using the following command *wg help*`, - `Hope everything works well` - ] , + + //function to be executed callback : () => { - onWG(); + + logic.onWG(); + //mesage to be sent to the user + let message = [ + `stop it and get some help by using the following command *wg help*`, + `Hope everything works well` + ]; + + return message; } }), @@ -22,7 +28,7 @@ const commands = [ -module.exports= onMessage = (message, client) => { +const onMessage = (message, client) => { let command = null; @@ -30,7 +36,7 @@ module.exports= onMessage = (message, client) => { if(message.body.startsWith("wg")) { for (let c of commands){ - if(c.getCommand() == message.body) + if(c.command == message.body) { command = c; break; @@ -38,8 +44,8 @@ module.exports= onMessage = (message, client) => { } if(command != null){ - command.getCallback()(); - for (let msg of command.getMessage()) + let messageToBeSent = command.callback(); + for (let msg of messageToBeSent) { client.sendMessage(message.from, msg, new Object()); } @@ -48,5 +54,6 @@ module.exports= onMessage = (message, client) => { }; +module.exports.onMessage = onMessage; //export default onMessage; \ No newline at end of file