feat: check who upvoted or downvoted

This commit is contained in:
2022-11-25 21:58:52 +01:00
parent ee2b169843
commit 47bd46827f
6 changed files with 79 additions and 6 deletions

View File

@@ -25,7 +25,7 @@ export default commandModule({
iconURL: `${modal.user.displayAvatarURL()}`,
})
.setDescription(value);
const buttons = new ActionRowBuilder<ButtonBuilder>()
const row = new ActionRowBuilder<ButtonBuilder>()
.addComponents(
new ButtonBuilder()
.setCustomId('suggestions-yes')
@@ -38,9 +38,23 @@ export default commandModule({
.setLabel('0')
.setStyle(ButtonStyle.Danger),
)
const row2 = new ActionRowBuilder<ButtonBuilder>()
.addComponents(
new ButtonBuilder()
.setCustomId('suggestions-yes-who')
.setEmoji('✅')
.setLabel('Quién')
.setStyle(ButtonStyle.Secondary),
new ButtonBuilder()
.setCustomId('suggestions-no-who')
.setEmoji('❎')
.setLabel('Quién')
.setStyle(ButtonStyle.Secondary),
)
const message1 = await (await modal.client.guilds.fetch(process.env.GUILDID!))
.channels.fetch(process.env.SUGGESTIONS_CHANNEL!) as TextChannel;
const message2 = await message1.send({ embeds: [embed], components: [buttons] });
const message2 = await message1.send({ embeds: [embed], components: [row, row2] });
message2.startThread({
name: `Sugerencia de ${modal.user.username}`,
autoArchiveDuration: ThreadAutoArchiveDuration.ThreeDays,

View File

@@ -0,0 +1,24 @@
import { commandModule, CommandType } from "@sern/handler";
import db from "../../schemas/suggestions.js";
export default commandModule({
type: CommandType.Button,
async execute(interaction) {
let finalarray
await interaction.deferReply({ephemeral: true})
const findeverything = await db.find({msgid: interaction.message.id, upordown: -1})
const array = findeverything.filter(message => message.msgid)
const fetchedids = await Promise.all(array.map(async (user) => {
return interaction.client.users.fetch(user.userid)
}))
if (fetchedids.length === 0) {
finalarray = 'Nadie, de momento'
} else {
finalarray = fetchedids.join(', ')
}
await interaction.editReply({
content: `Gente que ha hecho downvote:\n${finalarray}`,
allowedMentions: {repliedUser: false}
})
}
})

View File

@@ -14,6 +14,10 @@ export default commandModule({
.setLabel((convertToNumber + 1).toString())
.setStyle(ButtonStyle.Danger),
)
const row2 = new ActionRowBuilder<ButtonBuilder>().setComponents(
new ButtonBuilder(interaction.message!.components[1].components[0].data),
new ButtonBuilder(interaction.message!.components[1].components[1].data)
)
await db.exists({msgid: interaction.message.id, userid: interaction.user.id}, async (err, doc) => {
if (err) throw err
if (doc) {
@@ -25,7 +29,7 @@ export default commandModule({
upordown: -1
})
await addToDB.save()
await interaction.message.edit({components: [downvotebuttons]})
await interaction.message.edit({components: [downvotebuttons, row2]})
await interaction.deferUpdate()
}
})

View File

@@ -0,0 +1,25 @@
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) {
let finalarray
await interaction.deferReply({ephemeral: true})
const findeverything = await db.find({msgid: interaction.message.id, upordown: 1})
const array = findeverything.filter(message => message.msgid)
const fetchedids = await Promise.all(array.map(async (user) => {
return interaction.client.users.fetch(user.userid)
}))
if (fetchedids.length === 0) {
finalarray = 'Nadie, de momento'
} else {
finalarray = fetchedids.join(', ')
}
await interaction.editReply({
content: `Gente que ha hecho upvote:\n${finalarray}`,
allowedMentions: {repliedUser: false}
})
}
})

View File

@@ -14,6 +14,10 @@ export default commandModule({
.setStyle(ButtonStyle.Success),
new ButtonBuilder(interaction.message!.components[0].components[1].data)
)
const row2 = new ActionRowBuilder<ButtonBuilder>().setComponents(
new ButtonBuilder(interaction.message!.components[1].components[0].data),
new ButtonBuilder(interaction.message!.components[1].components[1].data)
)
await db.exists({msgid: interaction.message.id, userid: interaction.user.id}, async (err, doc) => {
if (err) throw err
if (doc) {
@@ -25,7 +29,7 @@ export default commandModule({
upordown: 1
})
await addToDB.save()
await interaction.message.edit({components: [upvotebuttons]})
await interaction.message.edit({components: [upvotebuttons, row2]})
await interaction.deferUpdate()
}
})

View File

@@ -2,13 +2,15 @@
"name": "vinci",
"version": "1.0.0",
"description": "Vinci Discord Bot for Mara Turing",
"main": "index.ts",
"main": "dist/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "tsc-watch --onSuccess \"node ./dist/index.js --dev\"",
"compile": "tsc --build",
"build": "tsc --build",
"web": "node webserver.js"
"web": "node webserver.js",
"watch": "tsc --watch",
"start": "nodemon dist/index.js"
},
"repository": {
"type": "git",