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
0d1c0a020c
commit
011fedb1c2
2 changed files with 50 additions and 32 deletions
62
main.js
62
main.js
|
|
@ -18,17 +18,38 @@ var newPlayerTemplate = {
|
||||||
"dm_points": 0
|
"dm_points": 0
|
||||||
};
|
};
|
||||||
var processes = {
|
var processes = {
|
||||||
"!read": {
|
"help": {
|
||||||
title: "read",
|
title: "Help",
|
||||||
description: "Read a description of your character",
|
description: "Show a description of a command",
|
||||||
run: function (msg, data) { return read(msg, data); }
|
run: function (msg, data, args, file) { return help(msg, args); }
|
||||||
},
|
},
|
||||||
"!create": {
|
"read": {
|
||||||
title: "create",
|
title: "Read",
|
||||||
description: "Create a character, can only be used once.",
|
description: "Read a description of your squirrel",
|
||||||
run: function (msg, args) { return create(msg, args); }
|
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 authorId;
|
||||||
var playerFile;
|
var playerFile;
|
||||||
var rawPlayerData;
|
var rawPlayerData;
|
||||||
|
|
@ -62,26 +83,11 @@ client.on('message', function (msg) {
|
||||||
if (fs.existsSync(playerFile)) {
|
if (fs.existsSync(playerFile)) {
|
||||||
rawPlayerData = fs.readFileSync(playerFile);
|
rawPlayerData = fs.readFileSync(playerFile);
|
||||||
playerData = JSON.parse(rawPlayerData);
|
playerData = JSON.parse(rawPlayerData);
|
||||||
processes.forEach(function (process) {
|
Object.keys(processes).forEach(function (process) {
|
||||||
if (command === "!" + process.title) {
|
if ("!" + processes[process].title.toLowerCase() === command) {
|
||||||
process.run();
|
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") {
|
else if (command === "!create") {
|
||||||
console.log("Attempting to make a squirrel for " + authorId);
|
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();
|
return toCaps.charAt(0).toUpperCase() + toCaps.slice(1).toLowerCase();
|
||||||
}
|
}
|
||||||
// Commands:
|
// Commands:
|
||||||
|
function help(msg, args) {
|
||||||
|
}
|
||||||
function read(msg, data) {
|
function read(msg, data) {
|
||||||
var embed = new Discord.RichEmbed()
|
var embed = new Discord.RichEmbed()
|
||||||
.setTitle(msg.author.username)
|
.setTitle(msg.author.username)
|
||||||
.setDescription("Squirrel Info")
|
.setDescription("Squirrel Info")
|
||||||
.setColor("#E81B47")
|
.setColor(COLOR)
|
||||||
.setThumbnail(msg.author.avatarURL)
|
.setThumbnail(msg.author.avatarURL)
|
||||||
.addField("Name", data.name)
|
.addField("Name", data.name)
|
||||||
.addField("Race", raceText(data.race))
|
.addField("Race", raceText(data.race))
|
||||||
|
|
|
||||||
20
main.ts
20
main.ts
|
|
@ -19,6 +19,11 @@ const newPlayerTemplate: player = {
|
||||||
"dm_points": 0
|
"dm_points": 0
|
||||||
}
|
}
|
||||||
const processes: any = {
|
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": {
|
"read": {
|
||||||
title: "Read",
|
title: "Read",
|
||||||
description: "Read a description of your squirrel",
|
description: "Read a description of your squirrel",
|
||||||
|
|
@ -27,7 +32,7 @@ const processes: any = {
|
||||||
"create": {
|
"create": {
|
||||||
title: "Create",
|
title: "Create",
|
||||||
description: "Create a squirrel, can only be used once.",
|
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": {
|
"namechange": {
|
||||||
title: "Namechange",
|
title: "Namechange",
|
||||||
|
|
@ -45,6 +50,7 @@ const processes: any = {
|
||||||
run: (msg: any, data: player, args: string[], file: any) => printClasses(msg)
|
run: (msg: any, data: player, args: string[], file: any) => printClasses(msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const COLOR: string = "#E81B47";
|
||||||
|
|
||||||
let authorId: number;
|
let authorId: number;
|
||||||
let playerFile: string;
|
let playerFile: string;
|
||||||
|
|
@ -84,9 +90,9 @@ client.on('message', msg => {
|
||||||
rawPlayerData = fs.readFileSync(playerFile);
|
rawPlayerData = fs.readFileSync(playerFile);
|
||||||
playerData = JSON.parse(rawPlayerData);
|
playerData = JSON.parse(rawPlayerData);
|
||||||
|
|
||||||
processes.forEach(process => {
|
Object.keys(processes).forEach(process => {
|
||||||
if(command === `!${process.title}`){
|
if(`!${processes[process].title.toLowerCase()}` === command){
|
||||||
process.run(msg, playerData, args, playerFile);
|
processes[process].run(msg, playerData, args, playerFile);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -135,11 +141,15 @@ function capitalize(toCaps: string): string {
|
||||||
|
|
||||||
// Commands:
|
// Commands:
|
||||||
|
|
||||||
|
function help(msg: any, args: string[]) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
function read(msg: any, data: player): void {
|
function read(msg: any, data: player): void {
|
||||||
let embed = new Discord.RichEmbed()
|
let embed = new Discord.RichEmbed()
|
||||||
.setTitle(msg.author.username)
|
.setTitle(msg.author.username)
|
||||||
.setDescription("Squirrel Info")
|
.setDescription("Squirrel Info")
|
||||||
.setColor("#E81B47")
|
.setColor(COLOR)
|
||||||
.setThumbnail(msg.author.avatarURL)
|
.setThumbnail(msg.author.avatarURL)
|
||||||
.addField("Name", data.name)
|
.addField("Name", data.name)
|
||||||
.addField("Race", raceText(data.race))
|
.addField("Race", raceText(data.race))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue