List command. Fixed namechange

Added list command, and fixed an inconsistency in namechange
This commit is contained in:
Julia Lange 2019-03-22 14:19:23 -07:00
parent 7b075255b2
commit bac3dc6d1e
2 changed files with 54 additions and 18 deletions

35
main.js
View file

@ -24,6 +24,12 @@ var processes = {
args: "command - the command you'd like to know more about\n", args: "command - the command you'd like to know more about\n",
run: function (msg, data, args, file) { return help(msg, args); } run: function (msg, data, args, file) { return help(msg, args); }
}, },
"list": {
title: "List",
description: "List all commands",
args: "",
run: function (msg, data, args, file) { return list(msg); }
},
"read": { "read": {
title: "Read", title: "Read",
description: "Read a description of your squirrel", description: "Read a description of your squirrel",
@ -32,15 +38,15 @@ var processes = {
}, },
"create": { "create": {
title: "Create", title: "Create",
description: "Create a squirrel, can only be used once.", description: "Create a squirrel, can only be used once",
args: "name - the name of the created squirrel\nrace - The race of the created squirrel, type !races for race options\nclass - The class of the created squirrel, type !classes for class options", args: "name - the name of the created squirrel\nrace - The race of the created squirrel, type !races for race options\nclass - The class of the created squirrel, type !classes for class options",
run: function (msg, data, args, file) { return msg.reply("You already have a squirrel silly."); } run: function (msg, data, args, file) { return msg.reply("You already have a squirrel silly."); }
}, },
"namechange": { "namechange": {
title: "Namechange", title: "Namechange",
description: "Change the name of your squirrel, can only be used once", description: "Change the name of your squirrel, can only be used at level 1",
args: "name - the new name for your squirrel", args: "name - the new name for your squirrel",
run: function (msg, data, args, file) { return nameChange(msg, data, file); } run: function (msg, data, args, file) { return nameChange(msg, data, args, file); }
}, },
"races": { "races": {
title: "Races", title: "Races",
@ -140,8 +146,8 @@ function help(msg, args) {
else if (processes.hasOwnProperty(argument)) { else if (processes.hasOwnProperty(argument)) {
var embed = new Discord.RichEmbed() var embed = new Discord.RichEmbed()
.setTitle(processes[argument].title) .setTitle(processes[argument].title)
.setDescription(processes[argument].description) .setColor(COLOR)
.setColor(COLOR); .setDescription(processes[argument].description);
if (processes[argument].args === "") { if (processes[argument].args === "") {
embed.addField("Arguments:", "This command has no arguments"); embed.addField("Arguments:", "This command has no arguments");
} }
@ -154,12 +160,23 @@ function help(msg, args) {
msg.reply("That command does not exist"); msg.reply("That command does not exist");
} }
} }
function list(msg) {
var embed = new Discord.RichEmbed()
.setTitle("List of Commands")
.setColor(COLOR);
var description = "";
Object.keys(processes).forEach(function (process) {
description += "**" + processes[process].title + ":** " + processes[process].description + ".\n";
});
embed.setDescription(description);
msg.author.send(embed);
}
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")
.setColor(COLOR) .setColor(COLOR)
.setThumbnail(msg.author.avatarURL) .setThumbnail(msg.author.avatarURL)
.setDescription("Squirrel Info")
.addField("Name", data.name) .addField("Name", data.name)
.addField("Race", raceText(data.race)) .addField("Race", raceText(data.race))
.addField("Class", capitalize(data["class"])) .addField("Class", capitalize(data["class"]))
@ -212,10 +229,10 @@ function create(msg, args, file) {
return false; return false;
} }
} }
function nameChange(msg, data, file) { function nameChange(msg, data, args, file) {
if (data.level == 1) { if (data.level == 1) {
if (msg.content.split(' ').length >= 2) { if (args.length >= 2) {
var newName = msg.content.split(' ')[1]; var newName = args[1];
data.name = capitalize(newName) + " " + data.name.split(' ')[1]; data.name = capitalize(newName) + " " + data.name.split(' ')[1];
fs.writeFileSync(file, JSON.stringify(data)); fs.writeFileSync(file, JSON.stringify(data));
msg.reply("Name changed to " + data.name); msg.reply("Name changed to " + data.name);

37
main.ts
View file

@ -5,6 +5,7 @@ const Discord = require('discord.js');
const client = new Discord.Client(); const client = new Discord.Client();
const info = JSON.parse(fs.readFileSync(`./data/info.json`)); const info = JSON.parse(fs.readFileSync(`./data/info.json`));
import { player } from "./data/enums/playerdata"; import { player } from "./data/enums/playerdata";
import { listenerCount } from "cluster";
const races: Array<string> = ["tree", "ground", "chipmunk"]; const races: Array<string> = ["tree", "ground", "chipmunk"];
const classes: Array<string> = ["rogue", "berserker", "knight", "ranger", "huntsman", "priest"]; const classes: Array<string> = ["rogue", "berserker", "knight", "ranger", "huntsman", "priest"];
@ -25,6 +26,12 @@ const processes: any = {
args: "command - the command you'd like to know more about\n", args: "command - the command you'd like to know more about\n",
run: (msg: any, data: player, args: string[], file: any) => help(msg, args) run: (msg: any, data: player, args: string[], file: any) => help(msg, args)
}, },
"list": {
title: "List",
description: "List all commands",
args: "",
run: (msg: any, data: player, args: string[], file: any) => list(msg)
},
"read": { "read": {
title: "Read", title: "Read",
description: "Read a description of your squirrel", description: "Read a description of your squirrel",
@ -33,15 +40,15 @@ 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",
args: "name - the name of the created squirrel\nrace - The race of the created squirrel, type !races for race options\nclass - The class of the created squirrel, type !classes for class options", args: "name - the name of the created squirrel\nrace - The race of the created squirrel, type !races for race options\nclass - The class of the created squirrel, type !classes for class options",
run: (msg: any, data: player, args: string[], file: any) => msg.reply(`You already have a squirrel silly.`) run: (msg: any, data: player, args: string[], file: any) => msg.reply(`You already have a squirrel silly.`)
}, },
"namechange": { "namechange": {
title: "Namechange", title: "Namechange",
description: "Change the name of your squirrel, can only be used once", description: "Change the name of your squirrel, can only be used at level 1",
args: "name - the new name for your squirrel", args: "name - the new name for your squirrel",
run: (msg: any, data: player, args: string[], file: any) => nameChange(msg, data, file) run: (msg: any, data: player, args: string[], file: any) => nameChange(msg, data, args, file)
}, },
"races": { "races": {
title: "Races", title: "Races",
@ -151,8 +158,8 @@ function help(msg: any, args: string[]): void {
} else if(processes.hasOwnProperty(argument)){ } else if(processes.hasOwnProperty(argument)){
let embed = new Discord.RichEmbed() let embed = new Discord.RichEmbed()
.setTitle(processes[argument].title) .setTitle(processes[argument].title)
.setDescription(processes[argument].description) .setColor(COLOR)
.setColor(COLOR); .setDescription(processes[argument].description);
if(processes[argument].args === "") { if(processes[argument].args === "") {
embed.addField("Arguments:", `This command has no arguments`); embed.addField("Arguments:", `This command has no arguments`);
} else { } else {
@ -164,12 +171,24 @@ function help(msg: any, args: string[]): void {
} }
} }
function list(msg: any): void {
let embed = new Discord.RichEmbed()
.setTitle("List of Commands")
.setColor(COLOR);
let description: string = "";
Object.keys(processes).forEach(process => {
description += `**${processes[process].title}:** ${processes[process].description}.\n`;
});
embed.setDescription(description);
msg.author.send(embed);
}
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")
.setColor(COLOR) .setColor(COLOR)
.setThumbnail(msg.author.avatarURL) .setThumbnail(msg.author.avatarURL)
.setDescription("Squirrel Info")
.addField("Name", data.name) .addField("Name", data.name)
.addField("Race", raceText(data.race)) .addField("Race", raceText(data.race))
.addField("Class", capitalize(data.class)) .addField("Class", capitalize(data.class))
@ -226,10 +245,10 @@ function create(msg: any, args: Array<string>, file: any): boolean {
} }
} }
function nameChange(msg: any, data: player, file: any): void { function nameChange(msg: any, data: player, args: string[], file: any): void {
if (data.level == 1) { if (data.level == 1) {
if (msg.content.split(' ').length >= 2) { if (args.length >= 2) {
let newName: string = msg.content.split(' ')[1]; let newName: string = args[1];
data.name = capitalize(newName) + " " + data.name.split(' ')[1]; data.name = capitalize(newName) + " " + data.name.split(' ')[1];
fs.writeFileSync(file, JSON.stringify(data)); fs.writeFileSync(file, JSON.stringify(data));
msg.reply(`Name changed to ${data.name}`); msg.reply(`Name changed to ${data.name}`);