Finished Process for single point of creation for new commands

Streamlined command creation to an object and function with single point of change.
This commit is contained in:
Dalton 2019-03-21 12:27:39 -07:00
parent 2aa514168b
commit 54276900bf

44
main.ts
View file

@ -19,15 +19,30 @@ const newPlayerTemplate: player = {
"dm_points": 0 "dm_points": 0
} }
const processes: any = { const processes: any = {
"!read": { "read": {
title: "read", title: "Read",
description: "Read a description of your character", description: "Read a description of your squirrel",
run: (msg, data) => read(msg, data) run: (msg: any, data: player, args: string[], file: any) => read(msg, data)
}, },
"!create": { "create": {
title: "create", title: "Create",
description: "Create a character, can only be used once.", description: "Create a squirrel, can only be used once.",
run: (msg, args) => create(msg, args) run: (msg: any, data: player, args: string[], file: any) => create(msg, args)
},
"namechange": {
title: "Namechange",
description: "Change the name of your squirrel, can only be used once",
run: (msg: any, data: player, args: string[], file: any) => nameChange(msg, data, file)
},
"races": {
title: "Races",
description: "List all the races",
run: (msg: any, data: player, args: string[], file: any) => printRaces(msg)
},
"classes": {
title: "Classes",
description: "List all the classes",
run: (msg: any, data: player, args: string[], file: any) => printClasses(msg)
} }
} }
@ -71,20 +86,9 @@ client.on('message', msg => {
processes.forEach(process => { processes.forEach(process => {
if(command === `!${process.title}`){ if(command === `!${process.title}`){
process.run() process.run(msg, playerData, args, playerFile);
} }
}); });
if (command === `!read`) {
read(msg, playerData);
} else if (command === `!create`) {
msg.reply(`You already have a squirrel silly.`);
} else if (command === `!namechange`) {
nameChange(msg, playerData, playerFile);
} else if (command === `!races`) {
printRaces(msg);
} else if (command === `!classes`) {
printClasses(msg);
}
} else if (command === `!create`) { } else if (command === `!create`) {
console.log(`Attempting to make a squirrel for ${authorId}`); console.log(`Attempting to make a squirrel for ${authorId}`);