From 5393e38e40b09ab6788b7385bc1f76281ba37775 Mon Sep 17 00:00:00 2001 From: Dalton Date: Sun, 10 Nov 2019 21:11:34 -0800 Subject: [PATCH] remove js files, update readme, updated player template --- .gitignore | 1 + README.md | 6 +- data/enums/playerdata.js | 3 - data/enums/playerdata.ts | 11 -- enums.ts | 19 +++ main.js | 288 --------------------------------------- main.ts | 50 ++++--- 7 files changed, 52 insertions(+), 326 deletions(-) delete mode 100644 data/enums/playerdata.js delete mode 100644 data/enums/playerdata.ts create mode 100644 enums.ts delete mode 100644 main.js diff --git a/.gitignore b/.gitignore index 1252713..2f4b981 100644 --- a/.gitignore +++ b/.gitignore @@ -75,3 +75,4 @@ typings/ # FuseBox cache .fusebox/ *.json +*.js diff --git a/README.md b/README.md index a27c471..675acc4 100644 --- a/README.md +++ b/README.md @@ -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": "!" diff --git a/data/enums/playerdata.js b/data/enums/playerdata.js deleted file mode 100644 index 06fad7f..0000000 --- a/data/enums/playerdata.js +++ /dev/null @@ -1,3 +0,0 @@ -"use strict"; -// Generated by https://quicktype.io -exports.__esModule = true; diff --git a/data/enums/playerdata.ts b/data/enums/playerdata.ts deleted file mode 100644 index c7d757f..0000000 --- a/data/enums/playerdata.ts +++ /dev/null @@ -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; -} diff --git a/enums.ts b/enums.ts new file mode 100644 index 0000000..87b7964 --- /dev/null +++ b/enums.ts @@ -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; +} diff --git a/main.js b/main.js deleted file mode 100644 index 9a9dc36..0000000 --- a/main.js +++ /dev/null @@ -1,288 +0,0 @@ -"use strict"; -// Created by Dalton 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); -} diff --git a/main.ts b/main.ts index 33db555..6cf54bf 100644 --- a/main.ts +++ b/main.ts @@ -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 = ["tree", "ground", "chipmunk"]; -const classes: Array = ["rogue", "berserker", "knight", "ranger", "huntsman", "priest"]; -const lastNames: Array = ["Nutcrack", "Seedsower", "McScuiri", "Rodentia", "Arbora", "Patagi"]; +const classes: Array = ["rogue", "berserker", "knight", "ranger", "priest"]; +const lastNames: Array = ["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 = msg.content.split(" "); + let messageContent: Array = 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 = [""]; // 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}`);