foundation is set

This commit is contained in:
Mohammed Ashab Uddin
2020-07-20 15:14:36 +04:00
parent 64a4b81f1d
commit cbe03c5954
8 changed files with 208 additions and 1 deletions

View File

@@ -0,0 +1,4 @@
module.exports.onWG = () => {
console.log('hello world');
}

View File

@@ -0,0 +1,50 @@
class Product {
constructor({ id = '', name = '', desc = '', cost = 0, image = null }) {
this.id = id;
this.name = name;
this.desc = desc;
this.cost = cost;
this.image = image;
}
getId(){
return this.id;
}
setName(name){
this.name = name;
}
getName(){
return this.name;
}
setDesc(desc){
this.desc = desc;
}
getDesc(){
return this.desc;
}
setCost(cost){
this.cost = cost;
}
getCost(){
return this.cost;
}
setImage(image){
this.imageUrl = image;
}
getImage(){
return this.imageUrl;
}
}
module.exports.Product = Product;

View File

@@ -0,0 +1,23 @@
const {Product} = require('./product');
class Website {
/**
* @param {Map<string,string>} details
*/
constructor(details){
this.details = details;
this.products = [];
}
/**
*
* @param {Product} product
*/
addProduct(product){
this.products.push(product);
}
}
module.exports.Website = Website;

View 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;

View 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;