From 5b4d20791a172a2abc438f468d5494e6d6037c79 Mon Sep 17 00:00:00 2001 From: SrIzan10 <66965250+SrIzan10@users.noreply.github.com> Date: Tue, 22 Nov 2022 18:08:26 +0100 Subject: [PATCH] feat: new suggestion system! --- commands/handlers/sugerencias.ts | 83 +++++++++++++++++----------- commands/handlers/suggestions-no.ts | 32 +++++++++++ commands/handlers/suggestions-yes.ts | 32 +++++++++++ schemas/suggestions.js | 7 +++ 4 files changed, 121 insertions(+), 33 deletions(-) create mode 100644 commands/handlers/suggestions-no.ts create mode 100644 commands/handlers/suggestions-yes.ts create mode 100644 schemas/suggestions.js diff --git a/commands/handlers/sugerencias.ts b/commands/handlers/sugerencias.ts index 1442115..069742e 100644 --- a/commands/handlers/sugerencias.ts +++ b/commands/handlers/sugerencias.ts @@ -1,38 +1,55 @@ -// import everything -import { commandModule, CommandType } from '@sern/handler' -import { EmbedBuilder } from 'discord.js'; -import { publish } from "../../src/plugins/publish.js"; -import { ownerOnly } from "../../src/plugins/ownerOnly.js" -import { TextChannel, ThreadAutoArchiveDuration, ThreadManager } from "discord.js"; +import { commandModule, CommandType } from '@sern/handler'; +import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder } from 'discord.js'; +import { + TextChannel, + ThreadAutoArchiveDuration, +} from 'discord.js'; export default commandModule({ type: CommandType.Modal, - //alias : [], - async execute (modal) { - // first we get the value + async execute(modal) { const value = modal.fields.getTextInputValue('sugerenciasInput'); - function onlySpaces(str: string) {return str.trim().length === 0} - if (onlySpaces(value) === true) { - modal.reply({content: 'Buen intento enviando un mensaje vacío >:D', ephemeral: true}) - } else if (value.indexOf('**') >= 0 || value.indexOf('*') >= 0 || value.indexOf('**') >= 0 || value.indexOf('__') >= 0 || value.indexOf('***') >= 0 || value.indexOf('_') >= 0) { - modal.reply({content: 'Debido a varios problemas, el formatting de Discord ha sido desactivado.\nPara más info, visita .\nSiento las molestias!', ephemeral: true}) - } else if (value.indexOf('sugerencia') >= 0 || value.indexOf('sugerencias') >= 0 || value.indexOf('Sugerencia') >= 0 || value.indexOf('Sugerencias') >= 0) { - modal.reply({content: 'No puedes enviar una sugerencia con la palabra sugerencia(s).'}) - } else { - // we create the embed which will be sent when the thing is sent - const modalEmbed = new EmbedBuilder() - .setColor("Random") - .setTitle('Sugerencia') - .setAuthor({name: `${modal.user.username}`, iconURL: `${modal.user.displayAvatarURL()}`}) - .setDescription(value); - // finally send the message to the text channel - const message1 = modal.client.guilds.cache.get('928018226330337280')!.channels.cache.get('1007269448140476436') as TextChannel - const message2 = (await message1.send({embeds: [modalEmbed]})) - message2.startThread({name: `Sugerencia de ${modal.user.username}`, autoArchiveDuration: ThreadAutoArchiveDuration.ThreeDays, reason: 'AUTOMATIZADO: Hilo para discutir sobre la sugerencia.'}) - message2.react("✅") - message2.react("❎") - // and return the user that it worked - modal.reply({content: '¡Enviado!\nRECUERDA QUE NO ESTÁ PERMITIDO ENVIAR MENSAJES VACÍOS.', ephemeral: true}) + function onlySpaces(str: string) { + return str.trim().length === 0; } - } -}); \ No newline at end of file + if (onlySpaces(value) === true) + return await modal.reply({ + content: 'Buen intento enviando un mensaje vacío >:D', + ephemeral: true, + }); + const embed = new EmbedBuilder() + .setColor('Random') + .setTitle('Sugerencia') + .setAuthor({ + name: `${modal.user.username}`, + iconURL: `${modal.user.displayAvatarURL()}`, + }) + .setDescription(value); + const buttons = new ActionRowBuilder() + .addComponents( + new ButtonBuilder() + .setCustomId('suggestions-yes') + .setEmoji('✅') + .setLabel('0') + .setStyle(ButtonStyle.Success), + new ButtonBuilder() + .setCustomId('suggestions-no') + .setEmoji('❎') + .setLabel('0') + .setStyle(ButtonStyle.Danger), + ) + const message1 = await (await modal.client.guilds.fetch('928018226330337280')) + .channels.fetch('1007269448140476436') as TextChannel; + const message2 = await message1.send({ embeds: [embed], components: [buttons] }); + message2.startThread({ + name: `Sugerencia de ${modal.user.username}`, + autoArchiveDuration: ThreadAutoArchiveDuration.ThreeDays, + reason: 'AUTOMATIZADO: Hilo para discutir sobre la sugerencia.', + }); + modal.reply({ + content: + '¡Enviado!\nRECUERDA QUE NO ESTÁ PERMITIDO ENVIAR MENSAJES VACÍOS.', + ephemeral: true, + }); + }, +}); diff --git a/commands/handlers/suggestions-no.ts b/commands/handlers/suggestions-no.ts new file mode 100644 index 0000000..059a542 --- /dev/null +++ b/commands/handlers/suggestions-no.ts @@ -0,0 +1,32 @@ +import { commandModule, CommandType } from "@sern/handler"; +import { ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, ComponentType } from "discord.js"; +import db from "../../schemas/suggestions.js"; + +export default commandModule({ + type: CommandType.Button, + async execute(interaction) { + const convertToNumber = Number(interaction.component.label!) + const upvotebuttons = new ActionRowBuilder().setComponents( + new ButtonBuilder(interaction.message!.components[0].components[0].data), + new ButtonBuilder() + .setCustomId('suggestions-no') + .setEmoji('❎') + .setLabel((convertToNumber + 1).toString()) + .setStyle(ButtonStyle.Danger), + ) + await db.exists({msgid: interaction.message.id, userid: interaction.user.id}, async (err, doc) => { + if (err) throw err + if (doc) { + await interaction.reply({content: 'Ya has hecho upvote/downvote, no puedes hacerlo de nuevo.', ephemeral: true}) + } else { + const addToDB = new db({ + msgid: interaction.message.id, + userid: interaction.user.id + }) + await addToDB.save() + await interaction.message.edit({components: [upvotebuttons]}) + await interaction.deferUpdate() + } + }) + } +}) \ No newline at end of file diff --git a/commands/handlers/suggestions-yes.ts b/commands/handlers/suggestions-yes.ts new file mode 100644 index 0000000..3c2feed --- /dev/null +++ b/commands/handlers/suggestions-yes.ts @@ -0,0 +1,32 @@ +import { commandModule, CommandType } from "@sern/handler"; +import { ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, ComponentType } from "discord.js"; +import db from "../../schemas/suggestions.js"; + +export default commandModule({ + type: CommandType.Button, + async execute(interaction) { + const convertToNumber = Number(interaction.component.label!) + const upvotebuttons = new ActionRowBuilder().setComponents( + new ButtonBuilder() + .setCustomId('suggestions-yes') + .setEmoji('✅') + .setLabel((convertToNumber + 1).toString()) + .setStyle(ButtonStyle.Success), + new ButtonBuilder(interaction.message!.components[0].components[1].data) + ) + await db.exists({msgid: interaction.message.id, userid: interaction.user.id}, async (err, doc) => { + if (err) throw err + if (doc) { + await interaction.reply({content: 'Ya has hecho upvote/downvote, no puedes hacerlo de nuevo.', ephemeral: true}) + } else { + const addToDB = new db({ + msgid: interaction.message.id, + userid: interaction.user.id + }) + await addToDB.save() + await interaction.message.edit({components: [upvotebuttons]}) + await interaction.deferUpdate() + } + }) + } +}) \ No newline at end of file diff --git a/schemas/suggestions.js b/schemas/suggestions.js new file mode 100644 index 0000000..cec7458 --- /dev/null +++ b/schemas/suggestions.js @@ -0,0 +1,7 @@ +import mongoose from 'mongoose' +const schema = new mongoose.Schema({ + msgid: {type: String, required: true}, + userid: {type: String, required: true}, +}); +const db = mongoose.model('suggestions', schema, 'suggestions'); +export default db \ No newline at end of file