🆕:Command File Changed ❌:All commands
Currently only Create command works
This commit is contained in:
parent
2486f57e2b
commit
f83a4231f1
7 changed files with 226 additions and 227 deletions
141
commands/commands.old
Normal file
141
commands/commands.old
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
import { Discord, fs } from "../main";
|
||||
import { player } from "../scripts/enums";
|
||||
import { raceText, capitalize, randomInt } from "../scripts/functions";
|
||||
|
||||
//===Data stored for use, such as class, race, and last names===
|
||||
|
||||
let processes: any = {
|
||||
"test": {
|
||||
title: "Test",
|
||||
description: "For testing",
|
||||
args: "",
|
||||
run: (msg: any, data: player, args: string[], file: any) => encounter()
|
||||
},
|
||||
"help": {
|
||||
title: "Help",
|
||||
description: "Show a description of a command",
|
||||
args: "**command** - the command you'd like to know more about",
|
||||
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": {
|
||||
title: "Read",
|
||||
description: "Read a description of your squirrel",
|
||||
args: "",
|
||||
run: (msg: any, data: player, args: string[], file: any) => read(msg, data)
|
||||
},
|
||||
"namechange": {
|
||||
title: "Namechange",
|
||||
description: "Change the name of your squirrel, can only be used at level 1",
|
||||
args: "**name** - the new name for your squirrel",
|
||||
run: (msg: any, data: player, args: string[], file: any) => nameChange(msg, data, args, file)
|
||||
},
|
||||
"races": {
|
||||
title: "Races",
|
||||
description: "List all the races",
|
||||
args: "",
|
||||
run: (msg: any, data: player, args: string[], file: any) => printRaces(msg)
|
||||
},
|
||||
"classes": {
|
||||
title: "Classes",
|
||||
description: "List all the classes",
|
||||
args: "",
|
||||
run: (msg: any, data: player, args: string[], file: any) => printClasses(msg)
|
||||
},
|
||||
}
|
||||
|
||||
//===COMMAND FUNCTIONS==
|
||||
|
||||
function help(msg: any, args: string[]): void {
|
||||
let argument: string = args[0].toLowerCase();
|
||||
if (argument === "") {
|
||||
msg.reply(`Please provide a command, like "!help help", or "!help races"\nAlternatively type "!list" for a list of commands`);
|
||||
} else if (processes.hasOwnProperty(argument)) {
|
||||
let embed = new Discord.RichEmbed()
|
||||
.setTitle(processes[argument].title)
|
||||
.setColor(COLOR)
|
||||
.setDescription(processes[argument].description);
|
||||
if (processes[argument].args === "") {
|
||||
embed.addField("Arguments:", `This command has no arguments`);
|
||||
} else {
|
||||
embed.addField("Arguments:", processes[argument].args);
|
||||
}
|
||||
msg.channel.send(embed);
|
||||
} else {
|
||||
msg.reply(`That command does not exist`);
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
let embed = new Discord.RichEmbed()
|
||||
.setTitle(msg.author.username)
|
||||
.setColor(COLOR)
|
||||
.setThumbnail(msg.author.avatarURL)
|
||||
.setDescription("Squirrel Info")
|
||||
.addField("Name", data.name)
|
||||
.addField("Race", raceText(data.race))
|
||||
.addField("Class", capitalize(data.class))
|
||||
.addField("Nuts", data.nuts)
|
||||
.addField("Level", data.level);
|
||||
if (data.dm === true)
|
||||
embed.addField("DM Points", data.dm_points);
|
||||
|
||||
msg.channel.send(embed);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function nameChange(msg: any, data: player, args: string[], file: any): void {
|
||||
if (data.level == 1) {
|
||||
if (args.length >= 1) {
|
||||
data.name = capitalize(args[0]) + " " + data.name.split(' ')[1];
|
||||
fs.writeFileSync(file, JSON.stringify(data));
|
||||
msg.reply(`Name changed to ${data.name}`);
|
||||
} else {
|
||||
msg.reply(`Please provide a name`);
|
||||
}
|
||||
} else {
|
||||
msg.reply(`Sorry, you have to be level 1 to change your name. You're stuck with ${data.name}`);
|
||||
}
|
||||
}
|
||||
|
||||
function printRaces(msg: any): void {
|
||||
let print = "The races are: ";
|
||||
for (let i = 0; i < races.length; i++) {
|
||||
if (i === races.length - 1) {
|
||||
print += `& ${raceText(races[i])}s`;
|
||||
} else {
|
||||
print += `${raceText(races[i])}s, `;
|
||||
}
|
||||
}
|
||||
msg.reply(print);
|
||||
}
|
||||
|
||||
function printClasses(msg: any): void {
|
||||
let print = "The classes are: ";
|
||||
for (let i = 0; i < classes.length; i++) {
|
||||
if (i === classes.length - 1) {
|
||||
print += `& ${capitalize(classes[i])}s`;
|
||||
} else {
|
||||
print += `${capitalize(classes[i])}s, `;
|
||||
}
|
||||
}
|
||||
msg.reply(print);
|
||||
}
|
||||
34
commands/create.ts
Normal file
34
commands/create.ts
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import { squirrel } from "../scripts/enums";
|
||||
import { newSquirrel, updateSquirrelFile } from "../scripts/functions";
|
||||
|
||||
module.exports = {
|
||||
name: 'create',
|
||||
description: "Create a squirrel, can only be used once",
|
||||
args: "**name** - the name of the created squirrel\n**race** - The race of the created squirrel, type !races for race options\n**class** - The class of the created squirrel, type !classes for class options",
|
||||
execute(msg, args) {
|
||||
if (args.length !== 3) {
|
||||
msg.reply(`Too many or too few parameters were entered. The format is "create name race class". You only get to choose your first name, don't write a last name.`);
|
||||
return false;
|
||||
}
|
||||
|
||||
let newSquirrel: squirrel = squirrel(args[0], args[1], args[2]);
|
||||
|
||||
let incorrect: string = "";
|
||||
|
||||
if (newSquirrel.race === -1)
|
||||
incorrect += ` race as ${args[1]}`;
|
||||
if (newSquirrel.class === -1)
|
||||
incorrect += ` class as ${args[2]}`;
|
||||
|
||||
if (incorrect === "") {
|
||||
updateSquirrelFile(msg.author.id, newSquirrel);
|
||||
msg.reply(`Squirrel ${newSquirrel.name} has been created`);
|
||||
} else {
|
||||
msg.reply(`Some parameters were entered incorrectly. Remember the format is "create first_name race class". Your name can be whatever you want, but you have to choose from !race, and !class. You incorrectly entered:${incorrect}.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function squirrel(name: string, race: string, classtype: string): squirrel {
|
||||
return newSquirrel(name, race, classtype);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue