Adds comments, and prepares for channel integration
Also bolds argument names, and adds a message if you fail to use the "create" command correctly
This commit is contained in:
parent
d3b57984c1
commit
72ffbe1888
2 changed files with 82 additions and 46 deletions
53
main.js
53
main.js
|
|
@ -1,13 +1,16 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
// Created by Julia Lange
|
// Created by Julia Lange
|
||||||
exports.__esModule = true;
|
exports.__esModule = true;
|
||||||
|
//===Requirements===
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var Discord = require('discord.js');
|
var Discord = require('discord.js');
|
||||||
var client = new Discord.Client();
|
var client = new Discord.Client();
|
||||||
var info = JSON.parse(fs.readFileSync("./data/info.json"));
|
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 races = ["tree", "ground", "chipmunk"];
|
||||||
var classes = ["rogue", "berserker", "knight", "ranger", "huntsman", "priest"];
|
var classes = ["rogue", "berserker", "knight", "ranger", "huntsman", "priest"];
|
||||||
var lastNames = ["Nutcrack", "Seedsower", "McScuiri", "Rodentia", "Arbora", "Patagi"];
|
var lastNames = ["Nutcrack", "Seedsower", "McScuiri", "Rodentia", "Arbora", "Patagi"];
|
||||||
|
var COLOR = "#E81B47";
|
||||||
var newPlayerTemplate = {
|
var newPlayerTemplate = {
|
||||||
"name": "",
|
"name": "",
|
||||||
"race": "",
|
"race": "",
|
||||||
|
|
@ -17,11 +20,12 @@ var newPlayerTemplate = {
|
||||||
"dm": false,
|
"dm": false,
|
||||||
"dm_points": 0
|
"dm_points": 0
|
||||||
};
|
};
|
||||||
|
//===Commands===
|
||||||
var processes = {
|
var processes = {
|
||||||
"help": {
|
"help": {
|
||||||
title: "Help",
|
title: "Help",
|
||||||
description: "Show a description of a command",
|
description: "Show a description of a command",
|
||||||
args: "command - the command you'd like to know more about\n",
|
args: "**command** - the command you'd like to know more about",
|
||||||
run: function (msg, data, args, file) { return help(msg, args); }
|
run: function (msg, data, args, file) { return help(msg, args); }
|
||||||
},
|
},
|
||||||
"list": {
|
"list": {
|
||||||
|
|
@ -39,13 +43,13 @@ 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\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."); }
|
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 at level 1",
|
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, args, file); }
|
run: function (msg, data, args, file) { return nameChange(msg, data, args, file); }
|
||||||
},
|
},
|
||||||
"races": {
|
"races": {
|
||||||
|
|
@ -61,12 +65,19 @@ var processes = {
|
||||||
run: function (msg, data, args, file) { return printClasses(msg); }
|
run: function (msg, data, args, file) { return printClasses(msg); }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var COLOR = "#E81B47";
|
//===Global editable variables===
|
||||||
|
var encounterChannel;
|
||||||
|
var preparingChannel;
|
||||||
|
var generalChannel;
|
||||||
|
var barChannel;
|
||||||
// let encounterInProgress: boolean;
|
// let encounterInProgress: boolean;
|
||||||
|
//===Initalization===
|
||||||
client.on('ready', function () {
|
client.on('ready', function () {
|
||||||
console.log("Logged in as " + client.user.tag + "!");
|
console.log("Logged in as " + client.user.tag + "!");
|
||||||
var encounterChannel = client.channels.find(function (ch) { return ch.name === 'the-wild'; });
|
encounterChannel = client.channels.find(function (ch) { return ch.name === 'the-wild'; });
|
||||||
var preparingChannel = client.channels.find(function (ch) { return ch.name === 'preparing-for-expedition'; });
|
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);
|
// const preparingCollector = new Discord.MessageCollector(preparingChannel);
|
||||||
// preparingCollector.on('collect', msg => {
|
// preparingCollector.on('collect', msg => {
|
||||||
// console.log(msg.content);
|
// console.log(msg.content);
|
||||||
|
|
@ -74,19 +85,20 @@ client.on('ready', function () {
|
||||||
// setInterval( function() { encounter(encounterChannel); }, 300000 );
|
// setInterval( function() { encounter(encounterChannel); }, 300000 );
|
||||||
// encounter(encounterChannel);
|
// encounter(encounterChannel);
|
||||||
});
|
});
|
||||||
|
//===When receiving messages
|
||||||
client.on('message', function (msg) {
|
client.on('message', function (msg) {
|
||||||
if (msg.channel.type === "dm")
|
//Reasons to exit
|
||||||
|
// if (msg.channel.type === "dm") return;
|
||||||
|
if (!msg.content.split(" ")[0].startsWith(info.prefix))
|
||||||
return;
|
return;
|
||||||
var messageContent = msg.content.split(" ");
|
var messageContent = msg.content.split(" ");
|
||||||
var command = messageContent[0];
|
var command = messageContent[0]; // This is the command they are using
|
||||||
if (!command.startsWith(info.prefix))
|
var args = [""]; // arguments of the message
|
||||||
return;
|
|
||||||
var args = [""];
|
|
||||||
if (messageContent.length > 1)
|
if (messageContent.length > 1)
|
||||||
args = messageContent.slice(1);
|
args = messageContent.slice(1);
|
||||||
var authorId = msg.author.id;
|
var authorId = msg.author.id; // Message Author
|
||||||
var playerFile = "./data/playerdata/" + authorId + ".json";
|
var playerFile = "./data/playerdata/" + authorId + ".json";
|
||||||
if (fs.existsSync(playerFile)) {
|
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 rawPlayerData = fs.readFileSync(playerFile);
|
||||||
var playerData_1 = JSON.parse(rawPlayerData);
|
var playerData_1 = JSON.parse(rawPlayerData);
|
||||||
Object.keys(processes).forEach(function (process) {
|
Object.keys(processes).forEach(function (process) {
|
||||||
|
|
@ -95,15 +107,22 @@ client.on('message', function (msg) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if (command === info.prefix + "create") {
|
else {
|
||||||
|
if (command === info.prefix + "create") {
|
||||||
console.log("Attempting to make a squirrel for " + authorId);
|
console.log("Attempting to make a squirrel for " + authorId);
|
||||||
if (create(msg, args, playerFile))
|
if (create(msg, args, playerFile))
|
||||||
console.log("Squirrel made succesfully for " + authorId);
|
console.log("Squirrel made succesfully for " + authorId);
|
||||||
else
|
else
|
||||||
console.log("Failed to create quirrel for " + authorId);
|
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);
|
client.login(info.key);
|
||||||
|
//===FUNCTIONS===
|
||||||
/*
|
/*
|
||||||
function encounter(encounterChannel: any): void {
|
function encounter(encounterChannel: any): void {
|
||||||
if (!encounterInProgress) { // randomInt(1,60) === 60 &&
|
if (!encounterInProgress) { // randomInt(1,60) === 60 &&
|
||||||
|
|
@ -137,11 +156,11 @@ function raceText(race) {
|
||||||
function capitalize(toCaps) {
|
function capitalize(toCaps) {
|
||||||
return toCaps.charAt(0).toUpperCase() + toCaps.slice(1).toLowerCase();
|
return toCaps.charAt(0).toUpperCase() + toCaps.slice(1).toLowerCase();
|
||||||
}
|
}
|
||||||
// Commands:
|
//===COMMAND FUNCTIONS==
|
||||||
function help(msg, args) {
|
function help(msg, args) {
|
||||||
var argument = args[0].toLowerCase();
|
var argument = args[0].toLowerCase();
|
||||||
if (argument === "") {
|
if (argument === "") {
|
||||||
msg.reply("Please provide a command, like \"!help help\", or \"!help races\"");
|
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)) {
|
else if (processes.hasOwnProperty(argument)) {
|
||||||
var embed = new Discord.RichEmbed()
|
var embed = new Discord.RichEmbed()
|
||||||
|
|
|
||||||
59
main.ts
59
main.ts
|
|
@ -1,15 +1,17 @@
|
||||||
// Created by Julia Lange
|
// Created by Julia Lange
|
||||||
|
|
||||||
|
//===Requirements===
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const Discord = require('discord.js');
|
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";
|
|
||||||
|
|
||||||
|
//===Data stored for use, such as class, race, and last names===
|
||||||
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"];
|
||||||
const lastNames: Array<string> = ["Nutcrack", "Seedsower", "McScuiri", "Rodentia", "Arbora", "Patagi"];
|
const lastNames: Array<string> = ["Nutcrack", "Seedsower", "McScuiri", "Rodentia", "Arbora", "Patagi"];
|
||||||
|
const COLOR: string = "#E81B47";
|
||||||
const newPlayerTemplate: player = {
|
const newPlayerTemplate: player = {
|
||||||
"name": "",
|
"name": "",
|
||||||
"race": "",
|
"race": "",
|
||||||
|
|
@ -19,11 +21,13 @@ const newPlayerTemplate: player = {
|
||||||
"dm": false,
|
"dm": false,
|
||||||
"dm_points": 0
|
"dm_points": 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//===Commands===
|
||||||
const processes: any = {
|
const processes: any = {
|
||||||
"help": {
|
"help": {
|
||||||
title: "Help",
|
title: "Help",
|
||||||
description: "Show a description of a command",
|
description: "Show a description of a command",
|
||||||
args: "command - the command you'd like to know more about\n",
|
args: "**command** - the command you'd like to know more about",
|
||||||
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": {
|
"list": {
|
||||||
|
|
@ -41,13 +45,13 @@ 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\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.`)
|
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 at level 1",
|
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, args, file)
|
run: (msg: any, data: player, args: string[], file: any) => nameChange(msg, data, args, file)
|
||||||
},
|
},
|
||||||
"races": {
|
"races": {
|
||||||
|
|
@ -63,14 +67,21 @@ const processes: any = {
|
||||||
run: (msg: any, data: player, args: string[], file: any) => printClasses(msg)
|
run: (msg: any, data: player, args: string[], file: any) => printClasses(msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const COLOR: string = "#E81B47";
|
|
||||||
|
|
||||||
|
//===Global editable variables===
|
||||||
|
let encounterChannel;
|
||||||
|
let preparingChannel;
|
||||||
|
let generalChannel;
|
||||||
|
let barChannel;
|
||||||
// let encounterInProgress: boolean;
|
// let encounterInProgress: boolean;
|
||||||
|
|
||||||
|
//===Initalization===
|
||||||
client.on('ready', () => {
|
client.on('ready', () => {
|
||||||
console.log(`Logged in as ${client.user.tag}!`);
|
console.log(`Logged in as ${client.user.tag}!`);
|
||||||
const encounterChannel = client.channels.find(ch => ch.name === 'the-wild');
|
encounterChannel = client.channels.find(ch => ch.name === 'the-wild');
|
||||||
const preparingChannel = client.channels.find(ch => ch.name === 'preparing-for-expedition');
|
preparingChannel = client.channels.find(ch => ch.name === 'preparing-for-expedition');
|
||||||
|
generalChannel = client.channels.find(ch => ch.name === 'general-table');
|
||||||
|
barChannel = client.channels.find(ch => ch.name === 'the-bar');
|
||||||
// const preparingCollector = new Discord.MessageCollector(preparingChannel);
|
// const preparingCollector = new Discord.MessageCollector(preparingChannel);
|
||||||
// preparingCollector.on('collect', msg => {
|
// preparingCollector.on('collect', msg => {
|
||||||
// console.log(msg.content);
|
// console.log(msg.content);
|
||||||
|
|
@ -79,42 +90,48 @@ client.on('ready', () => {
|
||||||
// encounter(encounterChannel);
|
// encounter(encounterChannel);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//===When receiving messages
|
||||||
client.on('message', msg => {
|
client.on('message', msg => {
|
||||||
|
//Reasons to exit
|
||||||
if (msg.channel.type === "dm") return;
|
// if (msg.channel.type === "dm") return;
|
||||||
|
if (!msg.content.split(" ")[0].startsWith(info.prefix)) return;
|
||||||
|
|
||||||
let messageContent: Array<string> = msg.content.split(" ");
|
let messageContent: Array<string> = msg.content.split(" ");
|
||||||
let command: string = messageContent[0];
|
let command: string = messageContent[0]; // This is the command they are using
|
||||||
|
|
||||||
if (!command.startsWith(info.prefix)) return;
|
let args: Array<string> = [""]; // arguments of the message
|
||||||
|
|
||||||
let args: Array<string> = [""];
|
|
||||||
if (messageContent.length > 1) args = messageContent.slice(1);
|
if (messageContent.length > 1) args = messageContent.slice(1);
|
||||||
|
|
||||||
let authorId: number = msg.author.id;
|
let authorId: number = msg.author.id; // Message Author
|
||||||
let playerFile: string = `./data/playerdata/${authorId}.json`;
|
let playerFile: string = `./data/playerdata/${authorId}.json`;
|
||||||
|
|
||||||
if (fs.existsSync(playerFile)) {
|
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 rawPlayerData: string = fs.readFileSync(playerFile);
|
||||||
let playerData: player = JSON.parse(rawPlayerData);
|
let playerData: player = JSON.parse(rawPlayerData);
|
||||||
|
|
||||||
Object.keys(processes).forEach(process => {
|
Object.keys(processes).forEach(process => { // See if the command they typed is a command
|
||||||
if(`${info.prefix}${processes[process].title.toLowerCase()}` === command){
|
if(`${info.prefix}${processes[process].title.toLowerCase()}` === command){
|
||||||
processes[process].run(msg, playerData, args, playerFile);
|
processes[process].run(msg, playerData, args, playerFile);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
} else if (command === `${info.prefix}create`) {
|
} else {
|
||||||
|
if(command === `${info.prefix}create`){
|
||||||
console.log(`Attempting to make a squirrel for ${authorId}`);
|
console.log(`Attempting to make a squirrel for ${authorId}`);
|
||||||
if (create(msg, args, playerFile))
|
if (create(msg, args, playerFile))
|
||||||
console.log(`Squirrel made succesfully for ${authorId}`);
|
console.log(`Squirrel made succesfully for ${authorId}`);
|
||||||
else
|
else
|
||||||
console.log(`Failed to create quirrel for ${authorId}`);
|
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);
|
client.login(info.key);
|
||||||
|
|
||||||
|
//===FUNCTIONS===
|
||||||
/*
|
/*
|
||||||
function encounter(encounterChannel: any): void {
|
function encounter(encounterChannel: any): void {
|
||||||
if (!encounterInProgress) { // randomInt(1,60) === 60 &&
|
if (!encounterInProgress) { // randomInt(1,60) === 60 &&
|
||||||
|
|
@ -149,12 +166,12 @@ function capitalize(toCaps: string): string {
|
||||||
return toCaps.charAt(0).toUpperCase() + toCaps.slice(1).toLowerCase();
|
return toCaps.charAt(0).toUpperCase() + toCaps.slice(1).toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Commands:
|
//===COMMAND FUNCTIONS==
|
||||||
|
|
||||||
function help(msg: any, args: string[]): void {
|
function help(msg: any, args: string[]): void {
|
||||||
let argument: string = args[0].toLowerCase();
|
let argument: string = args[0].toLowerCase();
|
||||||
if(argument === "") {
|
if(argument === "") {
|
||||||
msg.reply(`Please provide a command, like "!help help", or "!help races"`);
|
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)){
|
} else if(processes.hasOwnProperty(argument)){
|
||||||
let embed = new Discord.RichEmbed()
|
let embed = new Discord.RichEmbed()
|
||||||
.setTitle(processes[argument].title)
|
.setTitle(processes[argument].title)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue