feat: refactor and new features (#7)

* feat: refactor and new features

+ Refactored the codebase
+ OCR support in bots
+ Server sends training data every minute
+ Not using collectors for Discord feedback buttons anymore
+ Fixed grammar mistakes
+ Configs are now seperated
+ Tokens are no longer in configs
- Like feedback doesn't work for Discord yet

* feat: remove feedback button once voted

* feat: role blacklist

* feat: thread name check

* feat: error handler for training

* fix: bot crashing when a webhook msg is sent

* refactor: remove debugging lines

* feat: allow fixing mistake at votes in discord bot
This commit is contained in:
reis
2023-06-23 21:29:00 +03:00
committed by GitHub
parent f5214a6ace
commit 8b9f45dc22
60 changed files with 1962 additions and 1591 deletions

View File

@@ -0,0 +1,77 @@
import {
ActionRowBuilder,
StringSelectMenuBuilder,
ComponentType
} from 'discord.js';
export default async function trainAISelectMenu(
interaction,
config,
helper
) {
const options = [];
for (const { label } of config.responses) {
options.push({
label: label,
description: `The ${label} label.`,
value: label.toLowerCase()
});
}
const row = new ActionRowBuilder().addComponents(
new StringSelectMenuBuilder()
.setCustomId('select')
.setPlaceholder('Nothing selected')
.addOptions(options)
);
let interactedMessage;
if (!interaction.isMessageContextMenuCommand()) {
try {
const channel = await interaction.client.channels.fetch(interaction.message.reference.channelId);
const message = await channel.messages.fetch(interaction.message.reference.messageId);
interactedMessage = message.content.toLowerCase();
} catch (e) {
interaction.reply({
content: 'The message that you wanted to train the bot with was deleted.',
ephemeral: true
})
}
} else {
interactedMessage = interaction.targetMessage.content.toLowerCase()
}
const reply = await interaction.reply({
content: 'Please select the corresponding label to train the bot.',
components: [row],
ephemeral: true
});
const collector = reply.createMessageComponentCollector({
componentType: ComponentType.StringSelect,
time: 15000
});
const voteId = interaction.targetMessage ? interaction.targetMessage.id :
interaction.message.reference.messageId;
collector.on('collect', (i) => {
i.reply({ content: 'Sent training data to server.', ephemeral: true });
const existingVote = interaction.client.trainingVotes.get(voteId);
if (existingVote) clearTimeout(existingVote);
interaction.client.trainingVotes.set(voteId,
setTimeout(() => {
helper.sendTrainData(interactedMessage, i.values[0]);
if (!interaction.isMessageContextMenuCommand()) {
interaction.message.edit({ components: [] });
}
interaction.client.trainingVotes.delete(voteId);
}, 10_000)
);
});
}