completed all the commands and functions

This commit is contained in:
Mohammed Ashab Uddin
2020-07-31 15:46:05 +04:00
8 changed files with 712 additions and 339 deletions

View File

@@ -1,12 +1,12 @@
const { Command } = require("../models/commands");
const logic = require("../businessLogic/logic");
///////////
//add the commands here
///////////
const { Website } = require("../models/website");
const { Product } = require('../models/product');
//commands and the corresponding function to be executed
//are input in the array
const commands = [
new Command({
//User command
@@ -25,46 +25,43 @@ const commands = [
return message;
}
}),
new Command({
//User command
command: `wg product new <id>`,
//function to be executed
callback : logic.onCreateProduct
}),
new Command({
//User command
command: `wg product delete <id>`,
//function to be executed
callback : logic.onDeleteProduct
}),
new Command({
//User command
command: `wg product select <id>`,
//function to be executed
callback : logic.onSelectProduct
}),
//gives user information on how to create website
new Command({
//User command
command: 'wg help',
//function to be executed
callback : (input) => {
logic.onWG();
//mesage to be sent to the user
get_help = logic.help();
return get_help;
}
callback : logic.help
}),
//helps user to create a website. The first step.
new Command({
//User command
command: 'wg create <company_name>',
//function to be executed
callback : (input) =>
{
logic.onWG();
data = input['company_name'];
cn = logic.comp(data);
return cn;
}
callback : logic.onCreateWebsite
}),
//Inputs user's first name for website
new Command({
//User command
@@ -72,19 +69,7 @@ const commands = [
command: 'wg website firstname <firstName>',
//function to be executed
callback : (input) =>
{
logic.onWG();
//cdata = input['company'];
fdata = input['firstName'];
info = logic.firstName(fdata);
return info;
}
callback : logic.onSetFirstName
}),
@@ -92,45 +77,10 @@ const commands = [
new Command({
//User command
command: 'wg website lastname <lastname>',
command: 'wg website lastname <lastName>',
//function to be executed
callback : (input) =>
{
logic.onWG();
//cdata = input['company'];
ldata = input['lastname'];
info = logic.lastName(ldata);
return info;
}
}),
//inputs user companyname;in case they want to update the name
new Command({
//User command
command: 'wg website companyname <cname>',
//function to be executed
callback : (input) =>
{
logic.onWG();
//cdata = input['company'];
cdata = input['cname'];
info = logic.CompanyName_website(cdata);
return info;
}
callback : logic.onSetLastName
}),
//inputs the logo of the company to website using url of logo
@@ -140,19 +90,7 @@ const commands = [
command: 'wg website logo <url>',
//function to be executed
callback : (input) =>
{
logic.onWG();
//cdata = input['company'];
logoU = input['url'];
info = logic.logourl(logoU);
return info;
}
callback : logic.onSetLogo
}),
@@ -163,89 +101,131 @@ const commands = [
command: 'wg website banner <bannerURL>',
//function to be executed
callback : (input) =>
{
logic.onWG();
bannerU = input['bannerURL'];
info = logic.bannerurl(bannerU);
return info;
}
callback : logic.onSetBanner
}),
//inputs the description of the company to be seen in the website
new Command({
//User command
command: 'wg website description <descript>',
command: 'wg website desc <desc>',
//function to be executed
callback : (input) =>
{
logic.onWG();
websiteDescription = input['descript'];
info = logic.company_description(websiteDescription);
return info;
}
callback : logic.onSetDesc
}),
//inputs the email of the company for contacting.
new Command({
//User command
command: 'wg website email <Email>',
command: 'wg website email <email>',
//function to be executed
callback : (input) =>
{
logic.onWG();
mail = input['Email'];
info = logic.email(mail);
return info;
}
callback : logic.onSetEmail
}),
new Command({
//User command
command: 'wg website info',
//function to be executed
callback : logic.onGetInfo
}),
new Command({
//User command
command: 'wg website finished',
//function to be executed
callback : logic.onWebsiteFinished
}),
//gives user information on how to create website
new Command({
//User command
command: `wg product all`,
//function to be executed
callback : logic.onGetAllProducts
}),
new Command({
//User command
command: `wg product info`,
//function to be executed
callback : logic.onGetProductInfo
}),
new Command({
//User command
command: `wg product name <product-name>`,
//function to be executed
callback : logic.onSetProductName
}),
new Command({
//User command
command: `wg product cost <product-cost>`,
//function to be executed
callback : logic.onSetProductCost
}),
new Command({
//User command
command: 'wg product desc <product-desc>',
//function to be executed
callback : logic.onSetProductDesc
}),
new Command({
//User command
command: 'wg product image <product-image>',
//function to be executed
callback : logic.onSetProductImage
}),
];
module.exports= onMessage = (message, client) => {
module.exports= onMessage = async (message, client) => {
let command = null;
//if the message start with wg then proceed
if(message.body.startsWith("wg"))
{
//loop through all the commands
for (let c of commands){
//check if the message sent is equal to the commands
//if the message matches a command,
//then save the command in the command variable
if(c.equals(message.body))
{
command = c;
break;
}
}
//if the command is not null, implies, the message sent is a valid command
if(command != null){
let input = {};
if(command.requireInput)
{
//check if the command requires input
if(command.requireInput){
input = command.getInput(message.body);
}
//determine the user
logic.setUser(message.id.remote);
//determine the input
logic.setInput(input);
let messageToBeSent = command.callback(input);
//call callback function in the command
//await is used, so that if a command is an async function
//the program will wait until it is finished
//the callback returns a message to be sent to the user
let messageToBeSent = await command.callback();
// send the message to the user
for (let msg of messageToBeSent)
{
client.sendMessage(message.from, msg, new Object());
@@ -253,7 +233,7 @@ module.exports= onMessage = (message, client) => {
}
}
};
};