fix: dislike button not working properly

This commit is contained in:
GramingFoxTeam
2023-03-21 19:57:22 +03:00
parent a9ff00394a
commit 85eba55424
4 changed files with 63 additions and 48 deletions

View File

@@ -1,7 +1,4 @@
import { import { ContextMenuCommandBuilder, ApplicationCommandType } from 'discord.js';
ContextMenuCommandBuilder,
ApplicationCommandType
} from 'discord.js';
import trainAISelectMenu from '../utils/trainAISelectMenu.js'; import trainAISelectMenu from '../utils/trainAISelectMenu.js';
export default { export default {
@@ -13,7 +10,8 @@ export default {
interaction.member.roles.highest.comparePositionTo( interaction.member.roles.highest.comparePositionTo(
interaction.member.guild.roles.cache.get(config.discord.trainRole) interaction.member.guild.roles.cache.get(config.discord.trainRole)
) < 0 ) < 0
) return interaction.reply({ )
return interaction.reply({
content: 'You don\'t have the permission to do this.', content: 'You don\'t have the permission to do this.',
ephemeral: true ephemeral: true
}); });

View File

@@ -1,4 +1,9 @@
import { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } from 'discord.js'; import {
EmbedBuilder,
ActionRowBuilder,
ButtonBuilder,
ButtonStyle
} from 'discord.js';
import trainAISelectMenu from '../../utils/trainAISelectMenu.js'; import trainAISelectMenu from '../../utils/trainAISelectMenu.js';
export default { export default {
@@ -52,12 +57,19 @@ export default {
.setStyle(ButtonStyle.Danger) .setStyle(ButtonStyle.Danger)
); );
const reply = await message.reply({ embeds: [embed], components: [feedbackRow] }); const reply = await message.reply({
const filter = (i) => i.member.roles.highest.comparePositionTo( embeds: [embed],
components: [feedbackRow]
});
const filter = (i) =>
i.member.roles.highest.comparePositionTo(
i.member.guild.roles.cache.get(config.discord.trainRole) i.member.guild.roles.cache.get(config.discord.trainRole)
) > 0 ) > 0;
const collector = reply.createMessageComponentCollector({ filter, time: 15_000 }); const collector = reply.createMessageComponentCollector({
filter,
time: 15_000
});
collector.on('collect', (i) => { collector.on('collect', (i) => {
if (i.customId == 'fb-like') { if (i.customId == 'fb-like') {
// We train it using the label the AI gave. // We train it using the label the AI gave.
@@ -65,9 +77,9 @@ export default {
i.reply({ ephemeral: true, content: 'Sent train data to server.' }); i.reply({ ephemeral: true, content: 'Sent train data to server.' });
} else { } else {
// We ask the trainer to train it using the select menu. // We ask the trainer to train it using the select menu.
trainAISelectMenu(i, config, helper); trainAISelectMenu(i, config, helper, message);
} }
}) });
return; return;
} catch (e) { } catch (e) {
console.log(e); console.log(e);

View File

@@ -4,7 +4,12 @@ import {
ComponentType ComponentType
} from 'discord.js'; } from 'discord.js';
export default async function trainAISelectMenu(interaction, config, helper) { export default async function trainAISelectMenu(
interaction,
config,
helper,
message
) {
const options = []; const options = [];
for (const { label } of config.responses) { for (const { label } of config.responses) {
@@ -32,11 +37,11 @@ export default async function trainAISelectMenu(interaction, config, helper) {
time: 15000 time: 15000
}); });
const interactedMessage = message
? message.content
: interaction.targetMessage.content.toLowerCase();
collector.on('collect', (i) => { collector.on('collect', (i) => {
helper.sendTrainData( helper.sendTrainData(interactedMessage, i.values[0]);
interaction.targetMessage.content.toLowerCase(),
i.values[0].toUpperCase()
);
i.reply({ content: 'Sent train data to server.', ephemeral: true }); i.reply({ content: 'Sent train data to server.', ephemeral: true });
}); });

View File

@@ -19,7 +19,7 @@ export default {
`## ${response.reply.title}\n\n${response.reply.desc}\n\n_Confidence: ${intent.confidence}_\n\nThis bot is currently being tested in production. Ignore it, if it's wrong.`, `## ${response.reply.title}\n\n${response.reply.desc}\n\n_Confidence: ${intent.confidence}_\n\nThis bot is currently being tested in production. Ignore it, if it's wrong.`,
{ {
message_thread_id: ids[1], message_thread_id: ids[1],
reply_to_message_id: ids[2], reply_to_message_id: ids[2]
} }
); );