From ae544369aa67960a87ca940a73d8e6e5a075f180 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Thu, 19 Jan 2023 12:44:49 -0500 Subject: [PATCH] Reorganizing --- config.json => data/config.json | 0 messageIds.json => data/guildInfo.json | 0 strings.json => data/strings.json | 0 main.js | 4 +- .../_clear-commands.js | 2 +- .../_deploy-commands.js | 6 +-- .../_deploy-global.js | 0 functions.js => modules/functions.js | 54 +++++++++---------- slash-commands/compare.js | 2 +- slash-commands/help.js | 4 +- slash-commands/reset.js | 2 +- slash-commands/setup.js | 16 +++--- slash-commands/setupinfo.js | 2 +- slash-commands/template | 2 +- 14 files changed, 47 insertions(+), 47 deletions(-) rename config.json => data/config.json (100%) rename messageIds.json => data/guildInfo.json (100%) rename strings.json => data/strings.json (100%) rename _clear-commands.js => modules/_clear-commands.js (91%) rename _deploy-commands.js => modules/_deploy-commands.js (79%) rename _deploy-global.js => modules/_deploy-global.js (100%) rename functions.js => modules/functions.js (79%) diff --git a/config.json b/data/config.json similarity index 100% rename from config.json rename to data/config.json diff --git a/messageIds.json b/data/guildInfo.json similarity index 100% rename from messageIds.json rename to data/guildInfo.json diff --git a/strings.json b/data/strings.json similarity index 100% rename from strings.json rename to data/strings.json diff --git a/main.js b/main.js index 13a41b1..f1ab4d0 100644 --- a/main.js +++ b/main.js @@ -22,8 +22,8 @@ const client = new Client({ }); // Various imports -const fn = require('./functions.js'); -const strings = require('./strings.json'); +const fn = require('./modules/functions.js'); +const strings = require('./data/strings.json'); const isDev = process.env.isDev; client.once('ready', () => { diff --git a/_clear-commands.js b/modules/_clear-commands.js similarity index 91% rename from _clear-commands.js rename to modules/_clear-commands.js index 869c90d..57b7d64 100644 --- a/_clear-commands.js +++ b/modules/_clear-commands.js @@ -5,7 +5,7 @@ dotenv.config(); const { REST } = require('@discordjs/rest'); const { Routes } = require('discord-api-types/v9'); const clientId = process.env.clientId; -const { guildId } = require('../config.json'); +const { guildId } = require('../data/config.json'); const token = process.env.TOKEN; const rest = new REST({ version: '9' }).setToken(token); diff --git a/_deploy-commands.js b/modules/_deploy-commands.js similarity index 79% rename from _deploy-commands.js rename to modules/_deploy-commands.js index 4621f7b..933b61f 100644 --- a/_deploy-commands.js +++ b/modules/_deploy-commands.js @@ -3,16 +3,16 @@ const dotenv = require('dotenv'); dotenv.config(); const { REST, Routes } = require('discord.js'); -const { guildId } = require('./config.json'); +const { guildId } = require('../data/config.json'); const clientId = process.env.clientId; const token = process.env.TOKEN; const fs = require('fs'); const commands = []; -const commandFiles = fs.readdirSync('./slash-commands').filter(file => file.endsWith('.js')); +const commandFiles = fs.readdirSync('../slash-commands').filter(file => file.endsWith('.js')); for (const file of commandFiles) { - const command = require(`./slash-commands/${file}`); + const command = require(`../slash-commands/${file}`); if (command.data != undefined) { commands.push(command.data.toJSON()); } diff --git a/_deploy-global.js b/modules/_deploy-global.js similarity index 100% rename from _deploy-global.js rename to modules/_deploy-global.js diff --git a/functions.js b/modules/functions.js similarity index 79% rename from functions.js rename to modules/functions.js index ef537b2..8761aaa 100644 --- a/functions.js +++ b/modules/functions.js @@ -12,9 +12,9 @@ const Discord = require('discord.js'); const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = Discord; // Various imports from other files -const config = require('./config.json'); -let messageIds = require('./messageIds.json'); -const strings = require('./strings.json'); +const config = require('../data/config.json'); +let guildInfo = require('../data/guildInfo.json'); +const strings = require('../data/strings.json'); const slashCommandFiles = fs.readdirSync('./slash-commands/').filter(file => file.endsWith('.js')); const functions = { @@ -25,7 +25,7 @@ const functions = { if (!client.slashCommands) client.slashCommands = new Discord.Collection(); client.slashCommands.clear(); for (const file of slashCommandFiles) { - const slashCommand = require(`./slash-commands/${file}`); + const slashCommand = require(`../slash-commands/${file}`); if (slashCommand.data != undefined) { client.slashCommands.set(slashCommand.data.name, slashCommand); } @@ -89,13 +89,13 @@ const functions = { rankings: { parse(interaction) { return new Promise ((resolve, reject) => { - if (messageIds[interaction.guildId] == undefined) { + if (guildInfo[interaction.guildId] == undefined) { reject("The guild entry hasn't been created yet."); return; } - if (messageIds[interaction.guildId].rankMessageId != undefined) { - interaction.guild.channels.fetch(messageIds[interaction.guildId].rankChannelId).then(c => { - c.messages.fetch(messageIds[interaction.guildId].rankMessageId).then(rankMessage => { + if (guildInfo[interaction.guildId].rankMessageId != undefined) { + interaction.guild.channels.fetch(guildInfo[interaction.guildId].rankChannelId).then(c => { + c.messages.fetch(guildInfo[interaction.guildId].rankMessageId).then(rankMessage => { if ((rankMessage.embeds.length == 0) || (rankMessage.embeds[0].data.title != 'Tallest Trees' )) { reject("This doesn't appear to be a valid ``/top trees`` message."); return; @@ -126,9 +126,9 @@ const functions = { }); } - messageIds[interaction.guildId].rankings = rankings; - fs.writeFileSync('./messageIds.json', JSON.stringify(messageIds)); - messageIds = require('./messageIds.json'); + guildInfo[interaction.guildId].rankings = rankings; + fs.writeFileSync('../data/guildInfo.json', JSON.stringify(guildInfo)); + guildInfo = require('../data/guildInfo.json'); resolve(rankings); }); }); @@ -140,13 +140,13 @@ const functions = { }, compare(interaction) { - if (messageIds[interaction.guildId] == undefined) { + if (guildInfo[interaction.guildId] == undefined) { return `Please reset the reference messages! (${interaction.guildId})`; } - let treeHeight = parseFloat(messageIds[interaction.guildId].treeHeight).toFixed(1); - if ((messageIds[interaction.guildId].rankings.length > 0) && (treeHeight > 0)) { + let treeHeight = parseFloat(guildInfo[interaction.guildId].treeHeight).toFixed(1); + if ((guildInfo[interaction.guildId].rankings.length > 0) && (treeHeight > 0)) { let replyString = 'Current Tree Height: ' + treeHeight + 'ft\n\n'; - messageIds[interaction.guildId].rankings.forEach(e => { + guildInfo[interaction.guildId].rankings.forEach(e => { let difference = parseFloat(e.height).toFixed(1) - treeHeight; const absDifference = parseFloat(Math.abs(difference)).toFixed(1); if (difference > 0) { @@ -159,7 +159,7 @@ const functions = { }); return 'Here\'s how your tree compares: \n' + replyString; } else { - console.error('Not configured correctly\n' + 'Guild ID: ' + interaction.guildId + '\nGuild Info: ' + JSON.stringify(messageIds[interaction.guildId])); + console.error('Not configured correctly\n' + 'Guild ID: ' + interaction.guildId + '\nGuild Info: ' + JSON.stringify(guildInfo[interaction.guildId])); return 'Not configured correctly'; } } @@ -168,22 +168,22 @@ const functions = { parse(interaction) { let input; return new Promise((resolve, reject) => { - if (messageIds[interaction.guildId] == undefined) { + if (guildInfo[interaction.guildId] == undefined) { reject(`The guild entry hasn't been created yet. [${interaction.guildId || interaction.commandGuildId}]`); return; } - if (messageIds[interaction.guildId].treeMessageId != "") { - interaction.guild.channels.fetch(messageIds[interaction.guildId].treeChannelId).then(c => { - c.messages.fetch(messageIds[interaction.guildId].treeMessageId).then(m => { + if (guildInfo[interaction.guildId].treeMessageId != "") { + interaction.guild.channels.fetch(guildInfo[interaction.guildId].treeChannelId).then(c => { + c.messages.fetch(guildInfo[interaction.guildId].treeMessageId).then(m => { if ( (m.embeds.length == 0) || !(m.embeds[0].data.description.includes('Your tree is')) ) { reject("This doesn't appear to be a valid ``/tree`` message."); return; } input = m.embeds[0].data.description; let lines = input.split('\n'); - messageIds[interaction.guildId].treeHeight = parseFloat(lines[0].slice(lines[0].indexOf('is') + 3, lines[0].indexOf('ft'))).toFixed(1); - fs.writeFileSync('./messageIds.json', JSON.stringify(messageIds)); - messageIds = require('./messageIds.json'); + guildInfo[interaction.guildId].treeHeight = parseFloat(lines[0].slice(lines[0].indexOf('is') + 3, lines[0].indexOf('ft'))).toFixed(1); + fs.writeFileSync('../data/guildInfo.json', JSON.stringify(guildInfo)); + guildInfo = require('../data/guildInfo.json'); resolve("The reference tree message has been saved/updated."); }); }) @@ -208,13 +208,13 @@ const functions = { }); }, reset(guildId) { - delete messageIds[guildId]; - fs.writeFileSync('./messageIds.json', JSON.stringify(messageIds)); - messageIds = require('./messageIds.json'); + delete guildInfo[guildId]; + fs.writeFileSync('../data/guildInfo.json', JSON.stringify(guildInfo)); + guildInfo = require('../data/guildInfo.json'); return; }, getInfo(guildId) { - const guildInfo = messageIds[guildId]; + const guildInfo = guildInfo[guildId]; if (guildInfo != undefined) { let guildInfoString = ""; if (guildInfo.treeMessageId != "") { diff --git a/slash-commands/compare.js b/slash-commands/compare.js index b85c7fb..cf0ba38 100644 --- a/slash-commands/compare.js +++ b/slash-commands/compare.js @@ -1,5 +1,5 @@ const { SlashCommandBuilder } = require('discord.js'); -const fn = require('../functions.js'); +const fn = require('../modules/functions.js'); module.exports = { data: new SlashCommandBuilder() diff --git a/slash-commands/help.js b/slash-commands/help.js index 4f4388f..3ad4e16 100644 --- a/slash-commands/help.js +++ b/slash-commands/help.js @@ -1,6 +1,6 @@ const { SlashCommandBuilder, messageLink } = require('discord.js'); -const fn = require('../functions.js'); -const strings = require('../strings.json'); +const fn = require('../modules/functions.js'); +const strings = require('../data/strings.json'); module.exports = { data: new SlashCommandBuilder() diff --git a/slash-commands/reset.js b/slash-commands/reset.js index 569e36c..cecb3cd 100644 --- a/slash-commands/reset.js +++ b/slash-commands/reset.js @@ -1,5 +1,5 @@ const { SlashCommandBuilder } = require('discord.js'); -const fn = require('../functions.js'); +const fn = require('../modules/functions.js'); module.exports = { data: new SlashCommandBuilder() diff --git a/slash-commands/setup.js b/slash-commands/setup.js index 8281e26..05e327d 100644 --- a/slash-commands/setup.js +++ b/slash-commands/setup.js @@ -1,14 +1,14 @@ const { SlashCommandBuilder } = require('discord.js'); -const fn = require('../functions.js'); -const messageIds = require('../messageIds.json'); +const fn = require('../modules/functions.js'); +const guildInfo = require('../data/guildInfo.json'); module.exports = { data: new SlashCommandBuilder() .setName('setup') .setDescription('Attempt automatic configuration of the bot.'), execute(interaction) { - if (messageIds[interaction.guildId] == undefined) { - messageIds[interaction.guildId] = { + if (guildInfo[interaction.guildId] == undefined) { + guildInfo[interaction.guildId] = { "treeMessageId": "", "treeChannelId": "", "rankMessageId": "", @@ -24,13 +24,13 @@ module.exports = { if (msg.embeds.length > 0) { if (msg.embeds[0].data.description.includes("Your tree is")) { treeFound = true; - messageIds[interaction.guildId].treeChannelId = msg.channelId; - messageIds[interaction.guildId].treeMessageId = msg.id; + guildInfo[interaction.guildId].treeChannelId = msg.channelId; + guildInfo[interaction.guildId].treeMessageId = msg.id; fn.tree.parse(msg); } else if (msg.embeds[0].data.title == "Tallest Trees") { rankFound = true; - messageIds[interaction.guildId].rankChannelId = msg.channelId; - messageIds[interaction.guildId].rankMessageId = msg.id; + guildInfo[interaction.guildId].rankChannelId = msg.channelId; + guildInfo[interaction.guildId].rankMessageId = msg.id; fn.rankings.parse(msg); } } diff --git a/slash-commands/setupinfo.js b/slash-commands/setupinfo.js index 8eef847..b30871a 100644 --- a/slash-commands/setupinfo.js +++ b/slash-commands/setupinfo.js @@ -1,5 +1,5 @@ const { SlashCommandBuilder } = require('discord.js'); -const fn = require('../functions.js'); +const fn = require('../modules/functions.js'); module.exports = { data: new SlashCommandBuilder() diff --git a/slash-commands/template b/slash-commands/template index 383beac..774cf03 100644 --- a/slash-commands/template +++ b/slash-commands/template @@ -1,5 +1,5 @@ const { SlashCommandBuilder } = require('discord.js'); -const fn = require('../functions.js'); +const fn = require('../modules/functions.js'); module.exports = { data: new SlashCommandBuilder()