feat: new suggestion system!

This commit is contained in:
2022-11-22 18:08:26 +01:00
parent 7136de6665
commit 5b4d20791a
4 changed files with 121 additions and 33 deletions

View File

@@ -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 <https://vinci.tk/k>.\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;
}
}
});
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<ButtonBuilder>()
.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,
});
},
});

View File

@@ -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<ButtonBuilder>().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()
}
})
}
})

View File

@@ -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<ButtonBuilder>().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()
}
})
}
})

7
schemas/suggestions.js Normal file
View File

@@ -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