2023-01-21 14:58:32 +00:00
|
|
|
const { SlashCommandBuilder } = require('discord.js');
|
|
|
|
const fn = require('../modules/functions.js');
|
2023-01-24 02:29:12 +00:00
|
|
|
const strings = require('../data/strings.json');
|
2023-01-25 08:07:41 +00:00
|
|
|
const dbfn = require('../modules/dbfn.js');
|
2023-01-21 14:58:32 +00:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
data: new SlashCommandBuilder()
|
|
|
|
.setName('setup')
|
|
|
|
.setDescription('Attempt automatic configuration of the bot.'),
|
|
|
|
execute(interaction) {
|
2023-01-24 02:50:30 +00:00
|
|
|
interaction.deferReply({ ephemeral: true }).then(function () {
|
2023-01-25 08:07:41 +00:00
|
|
|
/*const guildInfo = { "guildId": "123",
|
|
|
|
"treeName": "name",
|
|
|
|
"treeHeight": 123,
|
|
|
|
"treeMessageId": "123",
|
|
|
|
"treeChannelId": "123",
|
|
|
|
"leaderboardMessageId": "123",
|
|
|
|
"leaderboardChannelId": "123"
|
|
|
|
};*/
|
|
|
|
const guildInfo = { "guildId": interaction.guildId,
|
|
|
|
"treeName": "name",
|
|
|
|
"treeHeight": 123,
|
|
|
|
"treeMessageId": "123",
|
|
|
|
"treeChannelId": "123",
|
|
|
|
"leaderboardMessageId": "123",
|
|
|
|
"leaderboardChannelId": "123"
|
|
|
|
};
|
2023-01-24 02:50:30 +00:00
|
|
|
interaction.channel.messages.fetch({ limit: 20 }).then(function (msgs) {
|
|
|
|
let treeFound = false;
|
2023-01-25 08:07:41 +00:00
|
|
|
let leaderboardFound = false;
|
2023-01-24 02:50:30 +00:00
|
|
|
msgs.reverse().forEach(msg => {
|
|
|
|
if (msg.embeds.length > 0) {
|
|
|
|
if (msg.embeds[0].data.description.includes("Your tree is")) {
|
|
|
|
treeFound = true;
|
2023-01-25 08:07:41 +00:00
|
|
|
guildInfo.treeName = msg.embeds[0].title;
|
|
|
|
guildInfo.treeChannelId = msg.channelId;
|
|
|
|
guildInfo.treeMessageId = msg.id;
|
2023-01-24 02:50:30 +00:00
|
|
|
} else if (msg.embeds[0].data.title == "Tallest Trees") {
|
2023-01-25 08:07:41 +00:00
|
|
|
leaderboardFound = true;
|
|
|
|
guildInfo.leaderboardChannelId = msg.channelId;
|
|
|
|
guildInfo.leaderboardMessageId = msg.id;
|
2023-01-24 02:50:30 +00:00
|
|
|
}
|
2023-01-21 14:58:32 +00:00
|
|
|
}
|
2023-01-24 02:50:30 +00:00
|
|
|
});
|
2023-01-25 08:07:41 +00:00
|
|
|
if (treeFound && !(leaderboardFound)) {
|
|
|
|
dbfn.setTreeInfo(guildInfo).then(res => {
|
|
|
|
interaction.editReply(fn.builders.embed(strings.status.treeNoLeaderboard));
|
|
|
|
}).catch(err => {
|
|
|
|
console.error(err);
|
|
|
|
});
|
|
|
|
} else if (!(treeFound) && leaderboardFound) {
|
|
|
|
dbfn.setLeaderboardInfo(guildInfo).then(res => {
|
|
|
|
interaction.editReply(fn.builders.embed(strings.status.leaderboardNoTree));
|
|
|
|
}).catch(err => {
|
|
|
|
console.error(err);
|
|
|
|
});
|
|
|
|
} else if (treeFound && leaderboardFound) {
|
|
|
|
dbfn.setGuildInfo(guildInfo).then(res => {
|
|
|
|
interaction.editReply(fn.builders.embed(strings.status.treeAndLeaderboard));
|
|
|
|
}).catch(err => {
|
|
|
|
console.error(err);
|
|
|
|
});
|
2023-01-21 14:58:32 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|