Reorganizing

This commit is contained in:
Skylar Grant 2023-01-19 12:44:49 -05:00
parent fded597bff
commit ae544369aa
14 changed files with 47 additions and 47 deletions

View File

@ -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', () => {

View File

@ -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);

View File

@ -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());
}

View File

@ -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 != "") {

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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);
}
}

View File

@ -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()

View File

@ -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()