remove js files, update readme, updated player template

This commit is contained in:
Julia Lange 2019-11-10 21:11:34 -08:00
parent 72ffbe1888
commit 18e6d98211
7 changed files with 52 additions and 326 deletions

1
.gitignore vendored
View file

@ -75,3 +75,4 @@ typings/
# FuseBox cache
.fusebox/
*.json
*.js

View file

@ -3,8 +3,10 @@
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:
First run `npm install` or `yarn install` whichever you prefer.
you will need to compile the typescript, to do so type `tsc main.ts`
create the file data/info.json, and inside of it include:
{
"key": "your discord key",
"prefix": "!"

View file

@ -1,3 +0,0 @@
"use strict";
// Generated by https://quicktype.io
exports.__esModule = true;

View file

@ -1,11 +0,0 @@
// Generated by https://quicktype.io
export interface player {
name: string;
race: string;
class: string;
level: number;
nuts: number;
dm: boolean;
dm_points: number;
}

19
enums.ts Normal file
View file

@ -0,0 +1,19 @@
export interface player {
name: string;
race: string;
class: string;
weapon: weapon;
nuts: number;
level: number;
staminaMax: number;
stamina: number;
dm: boolean;
dm_points: number;
}
export interface weapon {
weaponName: string;
attackStat: number;
defenseStat: number;
secondStat: number;
}

288
main.js
View file

@ -1,288 +0,0 @@
"use strict";
// Created by Julia Lange
exports.__esModule = true;
//===Requirements===
var fs = require('fs');
var Discord = require('discord.js');
var client = new Discord.Client();
var info = JSON.parse(fs.readFileSync("./data/info.json"));
//===Data stored for use, such as class, race, and last names===
var races = ["tree", "ground", "chipmunk"];
var classes = ["rogue", "berserker", "knight", "ranger", "huntsman", "priest"];
var lastNames = ["Nutcrack", "Seedsower", "McScuiri", "Rodentia", "Arbora", "Patagi"];
var COLOR = "#E81B47";
var newPlayerTemplate = {
"name": "",
"race": "",
"class": "",
"level": 1,
"nuts": 0,
"dm": false,
"dm_points": 0
};
//===Commands===
var processes = {
"help": {
title: "Help",
description: "Show a description of a command",
args: "**command** - the command you'd like to know more about",
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": {
title: "Read",
description: "Read a description of your squirrel",
args: "",
run: function (msg, data, args, file) { return read(msg, data); }
},
"create": {
title: "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",
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 at level 1",
args: "**name** - the new name for your squirrel",
run: function (msg, data, args, file) { return nameChange(msg, data, args, file); }
},
"races": {
title: "Races",
description: "List all the races",
args: "",
run: function (msg, data, args, file) { return printRaces(msg); }
},
"classes": {
title: "Classes",
description: "List all the classes",
args: "",
run: function (msg, data, args, file) { return printClasses(msg); }
}
};
//===Global editable variables===
var encounterChannel;
var preparingChannel;
var generalChannel;
var barChannel;
// let encounterInProgress: boolean;
//===Initalization===
client.on('ready', function () {
console.log("Logged in as " + client.user.tag + "!");
encounterChannel = client.channels.find(function (ch) { return ch.name === 'the-wild'; });
preparingChannel = client.channels.find(function (ch) { return ch.name === 'preparing-for-expedition'; });
generalChannel = client.channels.find(function (ch) { return ch.name === 'general-table'; });
barChannel = client.channels.find(function (ch) { return ch.name === 'the-bar'; });
// const preparingCollector = new Discord.MessageCollector(preparingChannel);
// preparingCollector.on('collect', msg => {
// console.log(msg.content);
// });
// setInterval( function() { encounter(encounterChannel); }, 300000 );
// encounter(encounterChannel);
});
//===When receiving messages
client.on('message', function (msg) {
//Reasons to exit
// if (msg.channel.type === "dm") return;
if (!msg.content.split(" ")[0].startsWith(info.prefix))
return;
var messageContent = msg.content.split(" ");
var command = messageContent[0]; // This is the command they are using
var args = [""]; // arguments of the message
if (messageContent.length > 1)
args = messageContent.slice(1);
var authorId = msg.author.id; // Message Author
var playerFile = "./data/playerdata/" + authorId + ".json";
if (fs.existsSync(playerFile)) { // If they're file exists, they can use commands, otherwise direct them to the create command
var rawPlayerData = fs.readFileSync(playerFile);
var playerData_1 = JSON.parse(rawPlayerData);
Object.keys(processes).forEach(function (process) {
if ("" + info.prefix + processes[process].title.toLowerCase() === command) {
processes[process].run(msg, playerData_1, args, playerFile);
}
});
}
else {
if (command === info.prefix + "create") {
console.log("Attempting to make a squirrel for " + authorId);
if (create(msg, args, playerFile))
console.log("Squirrel made succesfully for " + authorId);
else
console.log("Failed to create a squirrel for " + authorId);
}
else {
msg.reply("Please make a squirrel before interacting with the bot. To do so please use the create command. For more information on creation type \"!help create\"");
}
}
});
// Log the bot in
client.login(info.key);
//===FUNCTIONS===
/*
function encounter(encounterChannel: any): void {
if (!encounterInProgress) { // randomInt(1,60) === 60 &&
console.log("Starting Encounter");
encounterInProgress = true;
encounterChannel.send("An encounter is beginning!");
encounterChannel.send(`\`■■■ ■■■ ■■■ ■■■\`\n\`■■■ ■■■ ■■■ ■■■\`\n\`■■■ ■■■ ■■■ ■■■\``).then(msg => {
console.log("Encounter finished");
encounterInProgress = false;
});
}
}
*/
function randomInt(low, high) {
return Math.floor(Math.random() * (high - low + 1) + low);
}
function raceText(race) {
if (race === races[2])
return capitalize(race);
else if (race === races[0] || race === races[1])
return capitalize(race) + " Squirrel";
else {
console.log("Error " + race + " is not a valid race");
return "";
}
}
function capitalize(toCaps) {
return toCaps.charAt(0).toUpperCase() + toCaps.slice(1).toLowerCase();
}
//===COMMAND FUNCTIONS==
function help(msg, args) {
var argument = 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)) {
var 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) {
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) {
var 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 create(msg, args, file) {
if (args.length === 3) {
var newPlayer = newPlayerTemplate;
var incorrect_1 = "";
incorrect_1 = " race";
races.some(function (type) {
if (args[1].toLowerCase() == type) {
incorrect_1 = "";
return true;
}
});
if (incorrect_1 == "")
incorrect_1 = " class";
else
incorrect_1 += ", and class";
classes.some(function (type) {
if (args[2].toLowerCase() == type) {
if (incorrect_1 == " race, and class")
incorrect_1 = " race";
else
incorrect_1 = "";
return true;
}
});
if (incorrect_1 === "") {
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;
}
else {
msg.reply("Some parameters were entered incorrectly. Remember the format is \"create name race class\". Your name can be whatever you want, but you have to choose from !race, and !class. You incorrectly entered your:" + incorrect_1 + ".");
return false;
}
}
else {
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;
}
}
function nameChange(msg, data, args, file) {
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) {
var print = "The races are: ";
for (var 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) {
var print = "The classes are: ";
for (var 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);
}

50
main.ts
View file

@ -5,21 +5,29 @@ const fs = require('fs');
const Discord = require('discord.js');
const client = new Discord.Client();
const info = JSON.parse(fs.readFileSync(`./data/info.json`));
import { player } from "./data/enums/playerdata";
import { player } from "./enums";
//===Data stored for use, such as class, race, and last names===
const races: Array<string> = ["tree", "ground", "chipmunk"];
const classes: Array<string> = ["rogue", "berserker", "knight", "ranger", "huntsman", "priest"];
const lastNames: Array<string> = ["Nutcrack", "Seedsower", "McScuiri", "Rodentia", "Arbora", "Patagi"];
const classes: Array<string> = ["rogue", "berserker", "knight", "ranger", "priest"];
const lastNames: Array<string> = ["Nutcrack", "Nutmeg", "Seedsower", "McScuiri", "Rodentia", "Arbora", "Patagi"];
const COLOR: string = "#E81B47";
const newPlayerTemplate: player = {
"name": "",
"race": "",
"name": "",
"race": "",
"class": "",
"level": 1,
"nuts": 0,
"dm": false,
"dm_points": 0
"weapon": {
"weaponName": "",
"attackStat": 0,
"defenseStat": 0,
"secondStat": 0
},
"level": 1,
"nuts": 0,
"staminaMax": 0,
"stamina": 0,
"dm": false,
"dm_points": 0
}
//===Commands===
@ -42,12 +50,6 @@ const processes: any = {
args: "",
run: (msg: any, data: player, args: string[], file: any) => read(msg, data)
},
"create": {
title: "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",
run: (msg: any, data: player, args: string[], file: any) => msg.reply(`You already have a squirrel silly.`)
},
"namechange": {
title: "Namechange",
description: "Change the name of your squirrel, can only be used at level 1",
@ -65,7 +67,13 @@ const processes: any = {
description: "List all the classes",
args: "",
run: (msg: any, data: player, args: string[], file: any) => printClasses(msg)
}
},
"create": {
title: "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",
run: (msg: any, data: player, args: string[], file: any) => msg.reply(`You already have a squirrel silly.`)
},
}
//===Global editable variables===
@ -93,10 +101,9 @@ client.on('ready', () => {
//===When receiving messages
client.on('message', msg => {
//Reasons to exit
// if (msg.channel.type === "dm") return;
if (!msg.content.split(" ")[0].startsWith(info.prefix)) return;
if (!msg.content.split(" ")[0].startsWith(info.prefix)) return; // if the message doesn't start with the prefix
let messageContent: Array<string> = msg.content.split(" ");
let messageContent: Array<string> = msg.content.split(" "); // split message into an array on spaces
let command: string = messageContent[0]; // This is the command they are using
let args: Array<string> = [""]; // arguments of the message
@ -106,8 +113,7 @@ client.on('message', msg => {
let playerFile: string = `./data/playerdata/${authorId}.json`;
if (fs.existsSync(playerFile)) { // If they're file exists, they can use commands, otherwise direct them to the create command
let rawPlayerData: string = fs.readFileSync(playerFile);
let playerData: player = JSON.parse(rawPlayerData);
let playerData: player = JSON.parse(fs.readFileSync(playerFile));
Object.keys(processes).forEach(process => { // See if the command they typed is a command
if(`${info.prefix}${processes[process].title.toLowerCase()}` === command){
@ -116,7 +122,7 @@ client.on('message', msg => {
});
} else {
if(command === `${info.prefix}create`){
if(command === `${info.prefix}create`){ // if they are using the create command
console.log(`Attempting to make a squirrel for ${authorId}`);
if (create(msg, args, playerFile))
console.log(`Squirrel made succesfully for ${authorId}`);