Reorganizing
This commit is contained in:
parent
fded597bff
commit
ae544369aa
4
main.js
4
main.js
@ -22,8 +22,8 @@ const client = new Client({
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Various imports
|
// Various imports
|
||||||
const fn = require('./functions.js');
|
const fn = require('./modules/functions.js');
|
||||||
const strings = require('./strings.json');
|
const strings = require('./data/strings.json');
|
||||||
const isDev = process.env.isDev;
|
const isDev = process.env.isDev;
|
||||||
|
|
||||||
client.once('ready', () => {
|
client.once('ready', () => {
|
||||||
|
@ -5,7 +5,7 @@ dotenv.config();
|
|||||||
const { REST } = require('@discordjs/rest');
|
const { REST } = require('@discordjs/rest');
|
||||||
const { Routes } = require('discord-api-types/v9');
|
const { Routes } = require('discord-api-types/v9');
|
||||||
const clientId = process.env.clientId;
|
const clientId = process.env.clientId;
|
||||||
const { guildId } = require('../config.json');
|
const { guildId } = require('../data/config.json');
|
||||||
const token = process.env.TOKEN;
|
const token = process.env.TOKEN;
|
||||||
|
|
||||||
const rest = new REST({ version: '9' }).setToken(token);
|
const rest = new REST({ version: '9' }).setToken(token);
|
@ -3,16 +3,16 @@ const dotenv = require('dotenv');
|
|||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
const { REST, Routes } = require('discord.js');
|
const { REST, Routes } = require('discord.js');
|
||||||
const { guildId } = require('./config.json');
|
const { guildId } = require('../data/config.json');
|
||||||
const clientId = process.env.clientId;
|
const clientId = process.env.clientId;
|
||||||
const token = process.env.TOKEN;
|
const token = process.env.TOKEN;
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
const commands = [];
|
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) {
|
for (const file of commandFiles) {
|
||||||
const command = require(`./slash-commands/${file}`);
|
const command = require(`../slash-commands/${file}`);
|
||||||
if (command.data != undefined) {
|
if (command.data != undefined) {
|
||||||
commands.push(command.data.toJSON());
|
commands.push(command.data.toJSON());
|
||||||
}
|
}
|
@ -12,9 +12,9 @@ const Discord = require('discord.js');
|
|||||||
const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = Discord;
|
const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = Discord;
|
||||||
|
|
||||||
// Various imports from other files
|
// Various imports from other files
|
||||||
const config = require('./config.json');
|
const config = require('../data/config.json');
|
||||||
let messageIds = require('./messageIds.json');
|
let guildInfo = require('../data/guildInfo.json');
|
||||||
const strings = require('./strings.json');
|
const strings = require('../data/strings.json');
|
||||||
const slashCommandFiles = fs.readdirSync('./slash-commands/').filter(file => file.endsWith('.js'));
|
const slashCommandFiles = fs.readdirSync('./slash-commands/').filter(file => file.endsWith('.js'));
|
||||||
|
|
||||||
const functions = {
|
const functions = {
|
||||||
@ -25,7 +25,7 @@ const functions = {
|
|||||||
if (!client.slashCommands) client.slashCommands = new Discord.Collection();
|
if (!client.slashCommands) client.slashCommands = new Discord.Collection();
|
||||||
client.slashCommands.clear();
|
client.slashCommands.clear();
|
||||||
for (const file of slashCommandFiles) {
|
for (const file of slashCommandFiles) {
|
||||||
const slashCommand = require(`./slash-commands/${file}`);
|
const slashCommand = require(`../slash-commands/${file}`);
|
||||||
if (slashCommand.data != undefined) {
|
if (slashCommand.data != undefined) {
|
||||||
client.slashCommands.set(slashCommand.data.name, slashCommand);
|
client.slashCommands.set(slashCommand.data.name, slashCommand);
|
||||||
}
|
}
|
||||||
@ -89,13 +89,13 @@ const functions = {
|
|||||||
rankings: {
|
rankings: {
|
||||||
parse(interaction) {
|
parse(interaction) {
|
||||||
return new Promise ((resolve, reject) => {
|
return new Promise ((resolve, reject) => {
|
||||||
if (messageIds[interaction.guildId] == undefined) {
|
if (guildInfo[interaction.guildId] == undefined) {
|
||||||
reject("The guild entry hasn't been created yet.");
|
reject("The guild entry hasn't been created yet.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (messageIds[interaction.guildId].rankMessageId != undefined) {
|
if (guildInfo[interaction.guildId].rankMessageId != undefined) {
|
||||||
interaction.guild.channels.fetch(messageIds[interaction.guildId].rankChannelId).then(c => {
|
interaction.guild.channels.fetch(guildInfo[interaction.guildId].rankChannelId).then(c => {
|
||||||
c.messages.fetch(messageIds[interaction.guildId].rankMessageId).then(rankMessage => {
|
c.messages.fetch(guildInfo[interaction.guildId].rankMessageId).then(rankMessage => {
|
||||||
if ((rankMessage.embeds.length == 0) || (rankMessage.embeds[0].data.title != 'Tallest Trees' )) {
|
if ((rankMessage.embeds.length == 0) || (rankMessage.embeds[0].data.title != 'Tallest Trees' )) {
|
||||||
reject("This doesn't appear to be a valid ``/top trees`` message.");
|
reject("This doesn't appear to be a valid ``/top trees`` message.");
|
||||||
return;
|
return;
|
||||||
@ -126,9 +126,9 @@ const functions = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
messageIds[interaction.guildId].rankings = rankings;
|
guildInfo[interaction.guildId].rankings = rankings;
|
||||||
fs.writeFileSync('./messageIds.json', JSON.stringify(messageIds));
|
fs.writeFileSync('../data/guildInfo.json', JSON.stringify(guildInfo));
|
||||||
messageIds = require('./messageIds.json');
|
guildInfo = require('../data/guildInfo.json');
|
||||||
resolve(rankings);
|
resolve(rankings);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -140,13 +140,13 @@ const functions = {
|
|||||||
|
|
||||||
},
|
},
|
||||||
compare(interaction) {
|
compare(interaction) {
|
||||||
if (messageIds[interaction.guildId] == undefined) {
|
if (guildInfo[interaction.guildId] == undefined) {
|
||||||
return `Please reset the reference messages! (${interaction.guildId})`;
|
return `Please reset the reference messages! (${interaction.guildId})`;
|
||||||
}
|
}
|
||||||
let treeHeight = parseFloat(messageIds[interaction.guildId].treeHeight).toFixed(1);
|
let treeHeight = parseFloat(guildInfo[interaction.guildId].treeHeight).toFixed(1);
|
||||||
if ((messageIds[interaction.guildId].rankings.length > 0) && (treeHeight > 0)) {
|
if ((guildInfo[interaction.guildId].rankings.length > 0) && (treeHeight > 0)) {
|
||||||
let replyString = 'Current Tree Height: ' + treeHeight + 'ft\n\n';
|
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;
|
let difference = parseFloat(e.height).toFixed(1) - treeHeight;
|
||||||
const absDifference = parseFloat(Math.abs(difference)).toFixed(1);
|
const absDifference = parseFloat(Math.abs(difference)).toFixed(1);
|
||||||
if (difference > 0) {
|
if (difference > 0) {
|
||||||
@ -159,7 +159,7 @@ const functions = {
|
|||||||
});
|
});
|
||||||
return 'Here\'s how your tree compares: \n' + replyString;
|
return 'Here\'s how your tree compares: \n' + replyString;
|
||||||
} else {
|
} 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';
|
return 'Not configured correctly';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -168,22 +168,22 @@ const functions = {
|
|||||||
parse(interaction) {
|
parse(interaction) {
|
||||||
let input;
|
let input;
|
||||||
return new Promise((resolve, reject) => {
|
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}]`);
|
reject(`The guild entry hasn't been created yet. [${interaction.guildId || interaction.commandGuildId}]`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (messageIds[interaction.guildId].treeMessageId != "") {
|
if (guildInfo[interaction.guildId].treeMessageId != "") {
|
||||||
interaction.guild.channels.fetch(messageIds[interaction.guildId].treeChannelId).then(c => {
|
interaction.guild.channels.fetch(guildInfo[interaction.guildId].treeChannelId).then(c => {
|
||||||
c.messages.fetch(messageIds[interaction.guildId].treeMessageId).then(m => {
|
c.messages.fetch(guildInfo[interaction.guildId].treeMessageId).then(m => {
|
||||||
if ( (m.embeds.length == 0) || !(m.embeds[0].data.description.includes('Your tree is')) ) {
|
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.");
|
reject("This doesn't appear to be a valid ``/tree`` message.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
input = m.embeds[0].data.description;
|
input = m.embeds[0].data.description;
|
||||||
let lines = input.split('\n');
|
let lines = input.split('\n');
|
||||||
messageIds[interaction.guildId].treeHeight = parseFloat(lines[0].slice(lines[0].indexOf('is') + 3, lines[0].indexOf('ft'))).toFixed(1);
|
guildInfo[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));
|
fs.writeFileSync('../data/guildInfo.json', JSON.stringify(guildInfo));
|
||||||
messageIds = require('./messageIds.json');
|
guildInfo = require('../data/guildInfo.json');
|
||||||
resolve("The reference tree message has been saved/updated.");
|
resolve("The reference tree message has been saved/updated.");
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
@ -208,13 +208,13 @@ const functions = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
reset(guildId) {
|
reset(guildId) {
|
||||||
delete messageIds[guildId];
|
delete guildInfo[guildId];
|
||||||
fs.writeFileSync('./messageIds.json', JSON.stringify(messageIds));
|
fs.writeFileSync('../data/guildInfo.json', JSON.stringify(guildInfo));
|
||||||
messageIds = require('./messageIds.json');
|
guildInfo = require('../data/guildInfo.json');
|
||||||
return;
|
return;
|
||||||
},
|
},
|
||||||
getInfo(guildId) {
|
getInfo(guildId) {
|
||||||
const guildInfo = messageIds[guildId];
|
const guildInfo = guildInfo[guildId];
|
||||||
if (guildInfo != undefined) {
|
if (guildInfo != undefined) {
|
||||||
let guildInfoString = "";
|
let guildInfoString = "";
|
||||||
if (guildInfo.treeMessageId != "") {
|
if (guildInfo.treeMessageId != "") {
|
@ -1,5 +1,5 @@
|
|||||||
const { SlashCommandBuilder } = require('discord.js');
|
const { SlashCommandBuilder } = require('discord.js');
|
||||||
const fn = require('../functions.js');
|
const fn = require('../modules/functions.js');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
const { SlashCommandBuilder, messageLink } = require('discord.js');
|
const { SlashCommandBuilder, messageLink } = require('discord.js');
|
||||||
const fn = require('../functions.js');
|
const fn = require('../modules/functions.js');
|
||||||
const strings = require('../strings.json');
|
const strings = require('../data/strings.json');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
const { SlashCommandBuilder } = require('discord.js');
|
const { SlashCommandBuilder } = require('discord.js');
|
||||||
const fn = require('../functions.js');
|
const fn = require('../modules/functions.js');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
const { SlashCommandBuilder } = require('discord.js');
|
const { SlashCommandBuilder } = require('discord.js');
|
||||||
const fn = require('../functions.js');
|
const fn = require('../modules/functions.js');
|
||||||
const messageIds = require('../messageIds.json');
|
const guildInfo = require('../data/guildInfo.json');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
.setName('setup')
|
.setName('setup')
|
||||||
.setDescription('Attempt automatic configuration of the bot.'),
|
.setDescription('Attempt automatic configuration of the bot.'),
|
||||||
execute(interaction) {
|
execute(interaction) {
|
||||||
if (messageIds[interaction.guildId] == undefined) {
|
if (guildInfo[interaction.guildId] == undefined) {
|
||||||
messageIds[interaction.guildId] = {
|
guildInfo[interaction.guildId] = {
|
||||||
"treeMessageId": "",
|
"treeMessageId": "",
|
||||||
"treeChannelId": "",
|
"treeChannelId": "",
|
||||||
"rankMessageId": "",
|
"rankMessageId": "",
|
||||||
@ -24,13 +24,13 @@ module.exports = {
|
|||||||
if (msg.embeds.length > 0) {
|
if (msg.embeds.length > 0) {
|
||||||
if (msg.embeds[0].data.description.includes("Your tree is")) {
|
if (msg.embeds[0].data.description.includes("Your tree is")) {
|
||||||
treeFound = true;
|
treeFound = true;
|
||||||
messageIds[interaction.guildId].treeChannelId = msg.channelId;
|
guildInfo[interaction.guildId].treeChannelId = msg.channelId;
|
||||||
messageIds[interaction.guildId].treeMessageId = msg.id;
|
guildInfo[interaction.guildId].treeMessageId = msg.id;
|
||||||
fn.tree.parse(msg);
|
fn.tree.parse(msg);
|
||||||
} else if (msg.embeds[0].data.title == "Tallest Trees") {
|
} else if (msg.embeds[0].data.title == "Tallest Trees") {
|
||||||
rankFound = true;
|
rankFound = true;
|
||||||
messageIds[interaction.guildId].rankChannelId = msg.channelId;
|
guildInfo[interaction.guildId].rankChannelId = msg.channelId;
|
||||||
messageIds[interaction.guildId].rankMessageId = msg.id;
|
guildInfo[interaction.guildId].rankMessageId = msg.id;
|
||||||
fn.rankings.parse(msg);
|
fn.rankings.parse(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
const { SlashCommandBuilder } = require('discord.js');
|
const { SlashCommandBuilder } = require('discord.js');
|
||||||
const fn = require('../functions.js');
|
const fn = require('../modules/functions.js');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
const { SlashCommandBuilder } = require('discord.js');
|
const { SlashCommandBuilder } = require('discord.js');
|
||||||
const fn = require('../functions.js');
|
const fn = require('../modules/functions.js');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
data: new SlashCommandBuilder()
|
data: new SlashCommandBuilder()
|
||||||
|
Loading…
Reference in New Issue
Block a user