Alright fixed, and primed for Help command
Forgot that forEach cannot be use on an object, used Object.keys to fix the problem. Slightly less readable, but it works like a charm!
This commit is contained in:
parent
54276900bf
commit
55a7102994
2 changed files with 50 additions and 32 deletions
62
main.js
62
main.js
|
|
@ -18,17 +18,38 @@ var newPlayerTemplate = {
|
|||
"dm_points": 0
|
||||
};
|
||||
var processes = {
|
||||
"!read": {
|
||||
title: "read",
|
||||
description: "Read a description of your character",
|
||||
run: function (msg, data) { return read(msg, data); }
|
||||
"help": {
|
||||
title: "Help",
|
||||
description: "Show a description of a command",
|
||||
run: function (msg, data, args, file) { return help(msg, args); }
|
||||
},
|
||||
"!create": {
|
||||
title: "create",
|
||||
description: "Create a character, can only be used once.",
|
||||
run: function (msg, args) { return create(msg, args); }
|
||||
"read": {
|
||||
title: "Read",
|
||||
description: "Read a description of your squirrel",
|
||||
run: function (msg, data, args, file) { return read(msg, data); }
|
||||
},
|
||||
"create": {
|
||||
title: "Create",
|
||||
description: "Create a squirrel, can only be used once.",
|
||||
run: function (msg, data, args, file) { return msg.reply("You already have a squirrel silly."); }
|
||||
},
|
||||
"namechange": {
|
||||
title: "Namechange",
|
||||
description: "Change the name of your squirrel, can only be used once",
|
||||
run: function (msg, data, args, file) { return nameChange(msg, data, file); }
|
||||
},
|
||||
"races": {
|
||||
title: "Races",
|
||||
description: "List all the races",
|
||||
run: function (msg, data, args, file) { return printRaces(msg); }
|
||||
},
|
||||
"classes": {
|
||||
title: "Classes",
|
||||
description: "List all the classes",
|
||||
run: function (msg, data, args, file) { return printClasses(msg); }
|
||||
}
|
||||
};
|
||||
var COLOR = "#E81B47";
|
||||
var authorId;
|
||||
var playerFile;
|
||||
var rawPlayerData;
|
||||
|
|
@ -62,26 +83,11 @@ client.on('message', function (msg) {
|
|||
if (fs.existsSync(playerFile)) {
|
||||
rawPlayerData = fs.readFileSync(playerFile);
|
||||
playerData = JSON.parse(rawPlayerData);
|
||||
processes.forEach(function (process) {
|
||||
if (command === "!" + process.title) {
|
||||
process.run();
|
||||
Object.keys(processes).forEach(function (process) {
|
||||
if ("!" + processes[process].title.toLowerCase() === command) {
|
||||
processes[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") {
|
||||
console.log("Attempting to make a squirrel for " + authorId);
|
||||
|
|
@ -120,11 +126,13 @@ function capitalize(toCaps) {
|
|||
return toCaps.charAt(0).toUpperCase() + toCaps.slice(1).toLowerCase();
|
||||
}
|
||||
// Commands:
|
||||
function help(msg, args) {
|
||||
}
|
||||
function read(msg, data) {
|
||||
var embed = new Discord.RichEmbed()
|
||||
.setTitle(msg.author.username)
|
||||
.setDescription("Squirrel Info")
|
||||
.setColor("#E81B47")
|
||||
.setColor(COLOR)
|
||||
.setThumbnail(msg.author.avatarURL)
|
||||
.addField("Name", data.name)
|
||||
.addField("Race", raceText(data.race))
|
||||
|
|
|
|||
20
main.ts
20
main.ts
|
|
@ -19,6 +19,11 @@ const newPlayerTemplate: player = {
|
|||
"dm_points": 0
|
||||
}
|
||||
const processes: any = {
|
||||
"help": {
|
||||
title: "Help",
|
||||
description: "Show a description of a command",
|
||||
run: (msg: any, data: player, args: string[], file: any) => help(msg, args)
|
||||
},
|
||||
"read": {
|
||||
title: "Read",
|
||||
description: "Read a description of your squirrel",
|
||||
|
|
@ -27,7 +32,7 @@ const processes: any = {
|
|||
"create": {
|
||||
title: "Create",
|
||||
description: "Create a squirrel, can only be used once.",
|
||||
run: (msg: any, data: player, args: string[], file: any) => create(msg, args)
|
||||
run: (msg: any, data: player, args: string[], file: any) => msg.reply(`You already have a squirrel silly.`)
|
||||
},
|
||||
"namechange": {
|
||||
title: "Namechange",
|
||||
|
|
@ -45,6 +50,7 @@ const processes: any = {
|
|||
run: (msg: any, data: player, args: string[], file: any) => printClasses(msg)
|
||||
}
|
||||
}
|
||||
const COLOR: string = "#E81B47";
|
||||
|
||||
let authorId: number;
|
||||
let playerFile: string;
|
||||
|
|
@ -84,9 +90,9 @@ client.on('message', msg => {
|
|||
rawPlayerData = fs.readFileSync(playerFile);
|
||||
playerData = JSON.parse(rawPlayerData);
|
||||
|
||||
processes.forEach(process => {
|
||||
if(command === `!${process.title}`){
|
||||
process.run(msg, playerData, args, playerFile);
|
||||
Object.keys(processes).forEach(process => {
|
||||
if(`!${processes[process].title.toLowerCase()}` === command){
|
||||
processes[process].run(msg, playerData, args, playerFile);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -135,11 +141,15 @@ function capitalize(toCaps: string): string {
|
|||
|
||||
// Commands:
|
||||
|
||||
function help(msg: any, args: string[]) {
|
||||
|
||||
}
|
||||
|
||||
function read(msg: any, data: player): void {
|
||||
let embed = new Discord.RichEmbed()
|
||||
.setTitle(msg.author.username)
|
||||
.setDescription("Squirrel Info")
|
||||
.setColor("#E81B47")
|
||||
.setColor(COLOR)
|
||||
.setThumbnail(msg.author.avatarURL)
|
||||
.addField("Name", data.name)
|
||||
.addField("Race", raceText(data.race))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue