2021-10-25 23:18:28 +01:00
|
|
|
const fs = require("fs");
|
|
|
|
|
const Discord = require("discord.js");
|
|
|
|
|
const yaml = require("js-yaml");
|
2022-08-12 01:35:36 +01:00
|
|
|
|
2024-06-12 12:54:31 +01:00
|
|
|
// Load configurations
|
|
|
|
|
const supportbot = yaml.load(fs.readFileSync("./Configs/supportbot.yml", "utf8"));
|
|
|
|
|
const cmdconfig = yaml.load(fs.readFileSync("./Configs/commands.yml", "utf8"));
|
|
|
|
|
const msgconfig = yaml.load(fs.readFileSync("./Configs/messages.yml", "utf8"));
|
2021-10-25 23:18:28 +01:00
|
|
|
|
|
|
|
|
const Command = require("../Structures/Command.js");
|
2024-06-12 12:54:31 +01:00
|
|
|
|
|
|
|
|
// Ensure suggestions file exists and is correctly loaded
|
|
|
|
|
let suggestions;
|
|
|
|
|
try {
|
|
|
|
|
suggestions = require("../Data/SuggestionData.json");
|
|
|
|
|
} catch (error) {
|
|
|
|
|
suggestions = {};
|
|
|
|
|
}
|
2021-10-25 23:18:28 +01:00
|
|
|
|
|
|
|
|
module.exports = new Command({
|
2022-07-23 07:50:12 +01:00
|
|
|
name: cmdconfig.Suggestion.Command,
|
|
|
|
|
description: cmdconfig.Suggestion.Description,
|
2022-07-22 13:19:05 +01:00
|
|
|
type: Discord.ApplicationCommandType.ChatInput,
|
2021-12-18 18:57:26 -06:00
|
|
|
options: [
|
2021-10-25 23:18:28 +01:00
|
|
|
{
|
2021-10-27 19:20:10 -05:00
|
|
|
name: "suggestion",
|
|
|
|
|
description: "Create a Suggestion",
|
2022-07-22 13:19:05 +01:00
|
|
|
type: Discord.ApplicationCommandOptionType.String,
|
2021-12-28 19:06:35 -06:00
|
|
|
required: true,
|
2021-10-27 19:20:10 -05:00
|
|
|
},
|
2021-10-25 23:18:28 +01:00
|
|
|
],
|
2022-07-23 07:50:12 +01:00
|
|
|
permissions: cmdconfig.Suggestion.Permission,
|
2021-10-25 23:18:28 +01:00
|
|
|
|
|
|
|
|
async run(interaction) {
|
2022-01-30 00:07:04 -06:00
|
|
|
const { getChannel } = interaction.client;
|
2022-08-11 19:19:29 +01:00
|
|
|
|
2021-12-15 00:19:40 -06:00
|
|
|
const suggestChannel = await getChannel(
|
2022-08-12 01:35:36 +01:00
|
|
|
supportbot.Suggestions.Channel,
|
2021-12-15 00:19:40 -06:00
|
|
|
interaction.guild
|
2021-11-21 18:42:18 -06:00
|
|
|
);
|
2021-10-25 23:18:28 +01:00
|
|
|
|
2022-07-22 13:19:05 +01:00
|
|
|
const NoChannel = new Discord.EmbedBuilder()
|
2021-10-25 23:18:28 +01:00
|
|
|
.setTitle("Missing Channel!")
|
2022-08-12 01:35:36 +01:00
|
|
|
.setDescription(msgconfig.Error.InvalidChannel)
|
|
|
|
|
.setColor(supportbot.Embed.Colours.Error);
|
2021-10-25 23:18:28 +01:00
|
|
|
|
|
|
|
|
if (!suggestChannel) return interaction.reply({ embeds: [NoChannel] });
|
|
|
|
|
|
2021-10-27 19:20:10 -05:00
|
|
|
let suggestion = interaction.options.getString("suggestion");
|
2021-10-25 23:18:28 +01:00
|
|
|
|
2022-07-22 13:19:05 +01:00
|
|
|
const SuggestEmbed = new Discord.EmbedBuilder()
|
2022-08-11 19:19:29 +01:00
|
|
|
.addFields(
|
2024-06-12 12:54:31 +01:00
|
|
|
{ name: "Suggestion", value: suggestion, inline: true },
|
|
|
|
|
{ name: "From", value: `<@${interaction.user.id}>` },
|
|
|
|
|
{ name: `${supportbot.Suggestions.UpvoteEmoji} ${supportbot.Suggestions.UpvoteTitle}`, value: "0", inline: true },
|
|
|
|
|
{ name: `${supportbot.Suggestions.DownvoteEmoji} ${supportbot.Suggestions.DownvoteTitle}`, value: "0", inline: true }
|
2022-08-11 19:19:29 +01:00
|
|
|
)
|
2021-10-27 19:20:10 -05:00
|
|
|
.setThumbnail(interaction.user.displayAvatarURL())
|
2022-02-25 21:55:33 -06:00
|
|
|
.setFooter({
|
2022-08-12 01:35:36 +01:00
|
|
|
text: supportbot.Embed.Footer,
|
2022-02-25 21:55:33 -06:00
|
|
|
iconURL: interaction.user.displayAvatarURL(),
|
|
|
|
|
})
|
2022-08-12 01:35:36 +01:00
|
|
|
.setColor(supportbot.Embed.Colours.General);
|
2021-10-25 23:18:28 +01:00
|
|
|
|
2024-06-12 12:54:31 +01:00
|
|
|
const UpvoteButton = new Discord.ButtonBuilder()
|
|
|
|
|
.setCustomId("upvote")
|
|
|
|
|
.setEmoji(supportbot.Suggestions.UpvoteEmoji)
|
|
|
|
|
.setStyle(supportbot.Suggestions.Buttons.Upvote);
|
|
|
|
|
|
|
|
|
|
const DownvoteButton = new Discord.ButtonBuilder()
|
|
|
|
|
.setCustomId("downvote")
|
|
|
|
|
.setEmoji(supportbot.Suggestions.DownvoteEmoji)
|
|
|
|
|
.setStyle(supportbot.Suggestions.Buttons.Downvote);
|
|
|
|
|
|
|
|
|
|
const RemoveVoteButton = new Discord.ButtonBuilder()
|
|
|
|
|
.setCustomId("removevote")
|
|
|
|
|
.setLabel(supportbot.Suggestions.Buttons.RemoveVote_Title)
|
|
|
|
|
.setStyle(supportbot.Suggestions.Buttons.RemoveVote); // Red button
|
|
|
|
|
|
|
|
|
|
const row = new Discord.ActionRowBuilder().addComponents(UpvoteButton, DownvoteButton, RemoveVoteButton);
|
|
|
|
|
|
|
|
|
|
const suggestionMsg = await suggestChannel.send({ embeds: [SuggestEmbed], components: [row] });
|
|
|
|
|
|
|
|
|
|
suggestions[suggestionMsg.id] = {
|
|
|
|
|
suggestion: suggestion,
|
|
|
|
|
author: interaction.user.id,
|
|
|
|
|
upvotes: [],
|
|
|
|
|
downvotes: []
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
fs.writeFileSync("./Data/SuggestionData.json", JSON.stringify(suggestions, null, 2));
|
|
|
|
|
|
|
|
|
|
if (supportbot.Suggestions.Threads.Enabled) {
|
|
|
|
|
await suggestionMsg.startThread({
|
|
|
|
|
name: supportbot.Suggestions.Threads.Title,
|
|
|
|
|
autoArchiveDuration: 60,
|
|
|
|
|
type: Discord.ChannelType.PublicThread,
|
|
|
|
|
reason: supportbot.Suggestions.Threads.Reason,
|
|
|
|
|
});
|
2021-10-28 19:08:06 -05:00
|
|
|
}
|
2021-10-25 23:18:28 +01:00
|
|
|
|
2022-07-22 13:19:05 +01:00
|
|
|
const Submitted = new Discord.EmbedBuilder()
|
2024-06-12 12:54:31 +01:00
|
|
|
.setTitle(`${msgconfig.Suggestions.Sent_Title}`)
|
|
|
|
|
.setDescription(`${msgconfig.Suggestions.Sent}`)
|
2022-08-11 19:19:29 +01:00
|
|
|
.addFields(
|
2024-06-12 12:54:31 +01:00
|
|
|
{ name: "Sent to:", value: `<#${suggestChannel.id}>` },
|
2021-10-27 19:20:10 -05:00
|
|
|
)
|
2022-08-12 01:35:36 +01:00
|
|
|
.setColor(supportbot.Embed.Colours.Success);
|
2021-10-25 23:18:28 +01:00
|
|
|
|
2024-06-12 12:54:31 +01:00
|
|
|
await interaction.reply({
|
2022-06-21 01:38:22 +01:00
|
|
|
ephemeral: true,
|
|
|
|
|
embeds: [Submitted]
|
2024-06-12 12:54:31 +01:00
|
|
|
});
|
2021-10-25 23:18:28 +01:00
|
|
|
},
|
|
|
|
|
});
|