111 lines
No EOL
3.4 KiB
JavaScript
111 lines
No EOL
3.4 KiB
JavaScript
const { ticket_settings, review_channelID, review_products } = require("../config");
|
|
const {
|
|
SlashCommandBuilder,
|
|
EmbedBuilder,
|
|
ModalBuilder,
|
|
TextInputBuilder,
|
|
TextInputStyle,
|
|
ActionRowBuilder
|
|
} = require("discord.js");
|
|
|
|
const fiveStars = { name: '⭐⭐⭐⭐⭐', value: '⭐⭐⭐⭐⭐' };
|
|
const fourStars = { name: '⭐⭐⭐⭐', value: '⭐⭐⭐⭐' };
|
|
const threeStars = { name: '⭐⭐⭐', value: '⭐⭐⭐' };
|
|
const twoStars = { name: '⭐⭐', value: '⭐⭐' };
|
|
const oneStar = { name: '⭐', value: '⭐' };
|
|
|
|
module.exports = {
|
|
data: new SlashCommandBuilder()
|
|
.setName('review')
|
|
.setDescription("Review a product")
|
|
.addStringOption(option =>
|
|
option
|
|
.setRequired(true)
|
|
.setName('product')
|
|
.setDescription("Select the product")
|
|
.addChoices(...review_products.map(product => ({
|
|
name: product.name,
|
|
value: product.value
|
|
})))
|
|
)
|
|
.addStringOption(option =>
|
|
option
|
|
.setRequired(true)
|
|
.setName("rating")
|
|
.addChoices(fiveStars, fourStars, threeStars, twoStars, oneStar)
|
|
.setDescription("Select the rating")
|
|
),
|
|
|
|
async run(interaction) {
|
|
let { options } = interaction;
|
|
let rating = options.getString('rating');
|
|
let selectedProduct = options.getString('product');
|
|
|
|
let product = review_products.filter(p => selectedProduct === p.value);
|
|
if (product.length === 0) {
|
|
return;
|
|
}
|
|
|
|
let reviewModal = new ModalBuilder()
|
|
.setTitle('Review')
|
|
.setCustomId(`modalReview-${interaction.id}`);
|
|
|
|
let reviewInput = new TextInputBuilder()
|
|
.setRequired(true)
|
|
.setCustomId("review")
|
|
.setLabel("Write a review")
|
|
.setStyle(TextInputStyle.Paragraph);
|
|
|
|
let actionRow = new ActionRowBuilder().addComponents(reviewInput);
|
|
reviewModal.addComponents(actionRow);
|
|
|
|
await interaction.showModal(reviewModal);
|
|
|
|
let filter = i => i.customId === `modalReview-${interaction.id}` && i.user.id === interaction.user.id;
|
|
const modalOptions = { filter, time: 900000 };
|
|
|
|
interaction.awaitModalSubmit(modalOptions)
|
|
.then(async modalInteraction => {
|
|
let reviewText = modalInteraction.fields.getTextInputValue("review");
|
|
let reviewChannel = await interaction.guild.channels.fetch(review_channelID).catch(() => {});
|
|
|
|
const footerText = { text: "Reviewed At" };
|
|
const reviewField = {
|
|
name: "Review",
|
|
value: '```' + reviewText + '```',
|
|
inline: false
|
|
};
|
|
const productField = {
|
|
name: "Product",
|
|
value: '```' + product[0].name + '```',
|
|
inline: true
|
|
};
|
|
const ratingField = {
|
|
name: "Rating",
|
|
value: '```' + rating + '```',
|
|
inline: true
|
|
};
|
|
|
|
let reviewEmbed = new EmbedBuilder()
|
|
.setTimestamp()
|
|
.setColor(ticket_settings.embed_color)
|
|
.setFooter(footerText)
|
|
.addFields(reviewField, productField, ratingField)
|
|
.setAuthor({
|
|
name: `${interaction.member.displayName} has reviewed!`,
|
|
iconURL: interaction.member.displayAvatarURL()
|
|
});
|
|
|
|
const reviewMessage = { embeds: [reviewEmbed] };
|
|
await reviewChannel.send(reviewMessage);
|
|
|
|
const replyOptions = {
|
|
content: "Your review will be posted shortly.",
|
|
ephemeral: true
|
|
};
|
|
|
|
return modalInteraction.reply(replyOptions).catch(() => {});
|
|
})
|
|
.catch(() => {});
|
|
}
|
|
}; |