feat: training and replies changed

This commit is contained in:
GramingFoxTeam
2023-03-20 21:28:52 +03:00
parent 1909e2c421
commit 715aa918cf
16 changed files with 187 additions and 106 deletions

View File

@@ -27,7 +27,10 @@
{
"label": "DOWNLOAD",
"threshold": 0.85,
"text": "the download?"
"reply": {
"title": "download??",
"desc": "the download?"
}
}
]
}

View File

@@ -5,6 +5,9 @@ export default {
once: false,
execute(helper, _, msg) {
if (!msg.content || msg.author.bot) return;
helper.scanText(msg.content.toLowerCase().replace(/<.*?>/g, ''), `${msg.channelId}/${msg.id}`);
helper.scanText(
msg.content.toLowerCase().replace(/<.*?>/g, ''),
`${msg.channelId}/${msg.id}`
);
}
};

View File

@@ -23,19 +23,26 @@ export default {
message = channel.messages.cache.get(ids[1]);
}
const intent = aiRes.response.reduce((a, b) => a.confidence > b.confidence ? a : b);
const response = config.responses.find((res) => res.label === intent.name);
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;
const embed = new EmbedBuilder()
.setTitle('You have asked a Frequently Asked Question')
.setDescription(response.text)
.setFooter({ text: `Confidence: ${intent.confidence}` });
if (!response.reply) return;
message.reply({ embeds: [embed]});
const embed = new EmbedBuilder()
.setTitle(response.reply.title)
.setDescription(response.reply.desc)
.setColor(14908858)
.setFooter({ text: `Confidence: ${intent.confidence}` });
message.reply({ embeds: [embed] });
return;
} catch (e) {console.log(e)}
} catch (e) {
console.log(e);
}
}
};

View File

@@ -8,75 +8,78 @@ const __dirname = dirname(__filename);
import HelperClient from '../../client/index.js';
export default async () => {
const config = JSON.parse(readFileSync('./config.json', 'utf-8'));
const config = JSON.parse(readFileSync('./config.json', 'utf-8'));
const helper = new HelperClient(config);
const helper = new HelperClient(config);
helper.connect();
helper.connect();
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
]
});
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
]
});
client.commands = new Collection();
client.commands = new Collection();
const commandsPath = join(__dirname, 'commands');
const commandFiles = readdirSync(commandsPath).filter((file) =>
file.endsWith('.js')
);
const commandsPath = join(__dirname, 'commands');
const commandFiles = readdirSync(commandsPath).filter((file) =>
file.endsWith('.js')
);
for (const file of commandFiles) {
const filePath = join(commandsPath, file);
const command = (await import(`file://${filePath}`)).default;
if ('data' in command && 'execute' in command) {
client.commands.set(command.data.name, command);
} else {
console.log(
`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`
);
for (const file of commandFiles) {
const filePath = join(commandsPath, file);
const command = (await import(`file://${filePath}`)).default;
if ('data' in command && 'execute' in command) {
client.commands.set(command.data.name, command);
} else {
console.log(
`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`
);
}
}
}
const discordEventsPath = join(__dirname, 'events/discord');
const discordEventFiles = readdirSync(discordEventsPath).filter((file) =>
file.endsWith('.js')
);
const discordEventsPath = join(__dirname, 'events/discord');
const discordEventFiles = readdirSync(discordEventsPath).filter((file) =>
file.endsWith('.js')
);
for (const file of discordEventFiles) {
const filePath = join(discordEventsPath, file);
const event = (await import(`file://${filePath}`)).default;
if (event.once) {
client.once(event.name, (...args) =>
event.execute(helper, config, ...args)
);
} else {
client.on(event.name, (...args) => event.execute(helper, config, ...args));
for (const file of discordEventFiles) {
const filePath = join(discordEventsPath, file);
const event = (await import(`file://${filePath}`)).default;
if (event.once) {
client.once(event.name, (...args) =>
event.execute(helper, config, ...args)
);
} else {
client.on(event.name, (...args) =>
event.execute(helper, config, ...args)
);
}
}
}
// The ReVanced Helper events.
// The ReVanced Helper events.
const helperEventsPath = join(__dirname, 'events/helper');
const helperEventFiles = readdirSync(helperEventsPath).filter((file) =>
file.endsWith('.js')
);
const helperEventsPath = join(__dirname, 'events/helper');
const helperEventFiles = readdirSync(helperEventsPath).filter((file) =>
file.endsWith('.js')
);
for (const file of helperEventFiles) {
const filePath = join(helperEventsPath, file);
const event = (await import(`file://${filePath}`)).default;
if (event.once) {
helper.once(event.name, (...args) =>
event.execute(client, config, ...args)
);
} else {
helper.on(event.name, (...args) => event.execute(client, config, ...args));
for (const file of helperEventFiles) {
const filePath = join(helperEventsPath, file);
const event = (await import(`file://${filePath}`)).default;
if (event.once) {
helper.once(event.name, (...args) =>
event.execute(client, config, ...args)
);
} else {
helper.on(event.name, (...args) =>
event.execute(client, config, ...args)
);
}
}
}
client.login(config.discord.token);
}
client.login(config.discord.token);
};

View File

@@ -1,13 +1,13 @@
import { readdirSync } from 'node:fs';
const botFolders = readdirSync('./', { withFileTypes: true })
.filter(dirent => dirent.isDirectory())
.map(dirent => dirent.name);
.filter((dirent) => dirent.isDirectory())
.map((dirent) => dirent.name);
const runBotOnly = process.argv[2] ? process.argv[2] : null;
for (const botFolder of botFolders) {
if (botFolder === 'node_modules') continue;
if (runBotOnly && runBotOnly !== botFolder) continue;
const botIndex = await import(`./${botFolder}/index.js`);
botIndex.default();
}
if (botFolder === 'node_modules') continue;
if (runBotOnly && runBotOnly !== botFolder) continue;
const botIndex = await import(`./${botFolder}/index.js`);
botIndex.default();
}

View File

@@ -6,23 +6,33 @@ export default {
if (!aiRes.response[0]) return;
const ids = aiRes.id.split('/');
const intent = aiRes.response.reduce((a, b) => a.confidence > b.confidence ? a : b);
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;
switch (ids[0]) {
case 'comment': {
client.getComment(ids[1]).reply(`${response.text}\n\n*Confidence: ${intent.confidence}*`);
break;
}
case 'comment': {
client
.getComment(ids[1])
.reply(
`## ${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.`
);
break;
}
case 'post': {
client.getSubmission(ids[1]).reply(`${response.text}\n\n*Confidence: ${intent.confidence}*`);
break;
}
case 'post': {
client
.getSubmission(ids[1])
.reply(
`## ${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.`
);
break;
}
}
return;
}
};

View File

@@ -97,7 +97,9 @@ export default async () => {
event.execute(client, config, ...args)
);
} else {
helper.on(event.name, (...args) => event.execute(client, config, ...args));
helper.on(event.name, (...args) =>
event.execute(client, config, ...args)
);
}
}
}
};

View File

@@ -9,7 +9,7 @@ export default {
message_thread_id: msg.message_thread_id,
reply_to_message_id: msg.message_id
});
if (msg.reply_to_message.message_id === msg.message_thread_id)
return bot.sendMessage(msg.chat.id, 'Please reply to a message!', {
message_thread_id: msg.message_thread_id,

View File

@@ -5,15 +5,22 @@ export default {
if (!aiRes.response) return;
if (!aiRes.response[0]) return;
const ids = aiRes.id.split('/');
const intent = aiRes.response.reduce((a, b) => a.confidence > b.confidence ? a : b);
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;
bot.sendMessage(ids[0], `${response.text}\n\n*Confidence: ${intent.confidence}*`, {
message_thread_id: ids[1],
reply_to_message_id: ids[2],
parse_mode: 'HTML'
});
bot.sendMessage(
ids[0],
`## ${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],
reply_to_message_id: ids[2],
parse_mode: 'Markdown'
}
);
return;
}

View File

@@ -66,4 +66,4 @@ export default async () => {
helper.on(event.name, (...args) => event.execute(bot, config, ...args));
}
}
}
};