Added Args consistency

I also played around with the idea of multiple names like "Kit Kat" for a squirrel, but it was a massive pain. Ended up deciding hyphenated names were normal in Squirrel Society.
This commit is contained in:
Julia Lange 2019-03-22 15:08:20 -07:00
parent bac3dc6d1e
commit d3b57984c1
3 changed files with 27 additions and 18 deletions

View file

@ -1 +1,14 @@
# NovaBot
This is a temporary read me, and if you have trouble running the bot feel free to contact me.
To used this bot:
You must have node installed, and include the package discord.js.
Then create a info.json file, and in it include this:
{
"key": "your discord key",
"prefix": "!"
}
The key is the discord key for your bot, and the prefix is the command identifier, to say it a different way, the prefix is the character that goes before commands that the bot recoginizes.
Type `node main` in your terminal to start the bot.

16
main.js
View file

@ -188,12 +188,11 @@ function read(msg, data) {
}
function create(msg, args, file) {
if (args.length === 3) {
var newSquirrel_1 = msg.content.split(' ');
var newPlayer = newPlayerTemplate;
var incorrect_1 = "";
incorrect_1 = " race";
races.some(function (type) {
if (newSquirrel_1[2].toLowerCase() == type) {
if (args[1].toLowerCase() == type) {
incorrect_1 = "";
return true;
}
@ -203,7 +202,7 @@ function create(msg, args, file) {
else
incorrect_1 += ", and class";
classes.some(function (type) {
if (newSquirrel_1[3].toLowerCase() == type) {
if (args[2].toLowerCase() == type) {
if (incorrect_1 == " race, and class")
incorrect_1 = " race";
else
@ -212,9 +211,9 @@ function create(msg, args, file) {
}
});
if (incorrect_1 === "") {
newPlayer.name = newSquirrel_1[1] + " " + lastNames[randomInt(0, lastNames.length - 1)];
newPlayer.race = newSquirrel_1[2];
newPlayer["class"] = newSquirrel_1[3];
newPlayer.name = args[0] + " " + lastNames[randomInt(0, lastNames.length - 1)];
newPlayer.race = args[1];
newPlayer["class"] = args[2];
fs.writeFileSync(file, JSON.stringify(newPlayer));
msg.reply("Squirrel " + newPlayer.name + " has been created");
return true;
@ -231,9 +230,8 @@ function create(msg, args, file) {
}
function nameChange(msg, data, args, file) {
if (data.level == 1) {
if (args.length >= 2) {
var newName = args[1];
data.name = capitalize(newName) + " " + data.name.split(' ')[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);
}

16
main.ts
View file

@ -202,13 +202,12 @@ function read(msg: any, data: player): void {
function create(msg: any, args: Array<string>, file: any): boolean {
if (args.length === 3) {
let newSquirrel: Array<string> = msg.content.split(' ');
let newPlayer: player = newPlayerTemplate;
let incorrect: string = "";
incorrect = " race";
races.some(type => {
if (newSquirrel[2].toLowerCase() == type) {
if (args[1].toLowerCase() == type) {
incorrect = "";
return true;
}
@ -219,7 +218,7 @@ function create(msg: any, args: Array<string>, file: any): boolean {
else
incorrect += ", and class";
classes.some(type => {
if (newSquirrel[3].toLowerCase() == type) {
if (args[2].toLowerCase() == type) {
if (incorrect == " race, and class")
incorrect = " race";
else
@ -229,9 +228,9 @@ function create(msg: any, args: Array<string>, file: any): boolean {
});
if (incorrect === "") {
newPlayer.name = newSquirrel[1] + " " + lastNames[randomInt(0, lastNames.length - 1)];
newPlayer.race = newSquirrel[2];
newPlayer.class = newSquirrel[3];
newPlayer.name = args[0] + " " + lastNames[randomInt(0, lastNames.length - 1)];
newPlayer.race = args[1];
newPlayer.class = args[2];
fs.writeFileSync(file, JSON.stringify(newPlayer));
msg.reply(`Squirrel ${newPlayer.name} has been created`);
return true;
@ -247,9 +246,8 @@ function create(msg: any, args: Array<string>, file: any): boolean {
function nameChange(msg: any, data: player, args: string[], file: any): void {
if (data.level == 1) {
if (args.length >= 2) {
let newName: string = args[1];
data.name = capitalize(newName) + " " + data.name.split(' ')[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 {