mirror of
https://github.com/ReVanced/revanced-bots.git
synced 2026-01-29 22:21:02 +00:00
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:
72
apps/bot-discord/src/helperEvents/aiResponse.js
Normal file
72
apps/bot-discord/src/helperEvents/aiResponse.js
Normal file
@@ -0,0 +1,72 @@
|
||||
import {
|
||||
EmbedBuilder,
|
||||
ActionRowBuilder,
|
||||
ButtonBuilder,
|
||||
ButtonStyle
|
||||
} from 'discord.js';
|
||||
|
||||
export default {
|
||||
name: 'aiResponse',
|
||||
once: false,
|
||||
async execute(client, config, helper, aiRes) {
|
||||
if (!aiRes.response) return;
|
||||
if (!aiRes.response[0]) return;
|
||||
|
||||
try {
|
||||
const ids = aiRes.id.split('/');
|
||||
|
||||
const intent = aiRes.response.reduce((a, b) =>
|
||||
a.confidence > b.confidence ? a : b
|
||||
);
|
||||
|
||||
const response = config.responses.find(
|
||||
(res) => res.label === intent.name
|
||||
);
|
||||
|
||||
if (response.threshold > intent.confidence) return;
|
||||
if (!response.reply) return;
|
||||
|
||||
const embed = response.reply;
|
||||
embed.footer = { text: `Confidence: ${intent.confidence}` };
|
||||
|
||||
const feedbackRow = new ActionRowBuilder().addComponents(
|
||||
new ButtonBuilder()
|
||||
.setCustomId('fb-like')
|
||||
.setEmoji('👍')
|
||||
.setStyle(ButtonStyle.Primary),
|
||||
new ButtonBuilder()
|
||||
.setCustomId('fb-dislike')
|
||||
.setEmoji('👎')
|
||||
.setStyle(ButtonStyle.Primary)
|
||||
);
|
||||
|
||||
let channel = client.channels.cache.get(ids[0]);
|
||||
|
||||
if (!channel) {
|
||||
await client.channels.fetch(ids[0]);
|
||||
channel = client.channels.cache.get(ids[0]);
|
||||
}
|
||||
|
||||
if (!ids[1]) {
|
||||
channel.send({
|
||||
embeds: [embed],
|
||||
components: [feedbackRow]
|
||||
});
|
||||
} else {
|
||||
let message = channel.messages.cache.get(ids[1]);
|
||||
|
||||
if (!message) {
|
||||
await channel.messages.fetch(ids[1]);
|
||||
message = channel.messages.cache.get(ids[1]);
|
||||
}
|
||||
|
||||
message.reply({
|
||||
embeds: [embed],
|
||||
components: [feedbackRow]
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
31
apps/bot-discord/src/helperEvents/ocrResponse.js
Normal file
31
apps/bot-discord/src/helperEvents/ocrResponse.js
Normal file
@@ -0,0 +1,31 @@
|
||||
export default {
|
||||
name: 'ocrResponse',
|
||||
once: false,
|
||||
async execute(client, config, helper, ocrRes) {
|
||||
try {
|
||||
const ids = ocrRes.id.split('/');
|
||||
let channel = client.channels.cache.get(ids[0]);
|
||||
|
||||
if (!channel) {
|
||||
await client.channels.fetch(ids[0]);
|
||||
channel = client.channels.cache.get(ids[0]);
|
||||
}
|
||||
|
||||
let message = channel.messages.cache.get(ids[1]);
|
||||
|
||||
if (!message) {
|
||||
await channel.messages.fetch(ids[1]);
|
||||
message = channel.messages.cache.get(ids[1]);
|
||||
}
|
||||
|
||||
for (const ocrReply of config.ocrResponses) {
|
||||
if (ocrRes.ocrText.match(ocrReply.regex)) {
|
||||
message.reply({ embeds: [ocrReply.reply] });
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user