foundation is set
This commit is contained in:
23
whatsapp-web.js/src/userInteraction/commands.js
Normal file
23
whatsapp-web.js/src/userInteraction/commands.js
Normal file
@@ -0,0 +1,23 @@
|
||||
class Command{
|
||||
|
||||
|
||||
constructor({command, message, callback}){
|
||||
this.command = command;
|
||||
this.message = message;
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
getCommand(){
|
||||
return this.command;
|
||||
}
|
||||
|
||||
getCallback(){
|
||||
return this.callback;
|
||||
}
|
||||
|
||||
getMessage(){
|
||||
return this.message;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.Command = Command;
|
||||
52
whatsapp-web.js/src/userInteraction/messages.js
Normal file
52
whatsapp-web.js/src/userInteraction/messages.js
Normal file
@@ -0,0 +1,52 @@
|
||||
|
||||
const { Command } = require("./commands");
|
||||
const { onWG } = require("../businessLogic/logic");
|
||||
|
||||
///////////
|
||||
//add the commands here
|
||||
///////////
|
||||
const commands = [
|
||||
|
||||
new Command({
|
||||
command: 'wg',
|
||||
message : [
|
||||
`stop it and get some help by using the following command *wg help*`,
|
||||
`Hope everything works well`
|
||||
] ,
|
||||
callback : () => {
|
||||
onWG();
|
||||
}
|
||||
}),
|
||||
|
||||
];
|
||||
|
||||
|
||||
|
||||
module.exports= onMessage = (message, client) => {
|
||||
|
||||
let command = null;
|
||||
|
||||
//if the message start with wg then proceed
|
||||
if(message.body.startsWith("wg"))
|
||||
{
|
||||
for (let c of commands){
|
||||
if(c.getCommand() == message.body)
|
||||
{
|
||||
command = c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(command != null){
|
||||
command.getCallback()();
|
||||
for (let msg of command.getMessage())
|
||||
{
|
||||
client.sendMessage(message.from, msg, new Object());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
//export default onMessage;
|
||||
Reference in New Issue
Block a user