feat: prettier and eslint

This commit is contained in:
GramingFoxTeam
2022-11-16 13:59:55 +03:00
parent 0ad5ece085
commit 1c27ccb17c
22 changed files with 2359 additions and 324 deletions

View File

@@ -1,19 +1,19 @@
{
"discord": {
"token": "YOUR-BOT-TOKEN-HERE",
"id": "1038762591805247518"
},
"server": {
"port": 3000,
"host": "192.168.1.6"
},
"discord": {
"token": "YOUR-BOT-TOKEN-HERE",
"id": "1038762591805247518"
},
"responses": [
{
"label": "DOWNLOAD",
"threshold": 0.85,
"text": "you wanted peevanced"
}
]
}
"server": {
"port": 3000,
"host": "192.168.1.6"
},
"responses": [
{
"label": "DOWNLOAD",
"threshold": 0.85,
"text": "you wanted peevanced"
}
]
}

View File

@@ -1,35 +1,49 @@
import { ContextMenuCommandBuilder, ApplicationCommandType, ActionRowBuilder, SelectMenuBuilder, ComponentType } from 'discord.js';
import {
ContextMenuCommandBuilder,
ApplicationCommandType,
ActionRowBuilder,
SelectMenuBuilder,
ComponentType
} from 'discord.js';
export default {
data: new ContextMenuCommandBuilder()
.setName('Train Message')
.setType(ApplicationCommandType.Message),
async execute(interaction) {
const options = [];
data: new ContextMenuCommandBuilder()
.setName('Train Message')
.setType(ApplicationCommandType.Message),
async execute(interaction) {
const options = [];
for (const { label } of global.config.responses) {
options.push({
label: label,
description: `The ${label} label.`,
value: label.toLowerCase()
});
};
for (const { label } of global.config.responses) {
options.push({
label: label,
description: `The ${label} label.`,
value: label.toLowerCase()
});
}
const row = new ActionRowBuilder()
.addComponents(
new SelectMenuBuilder()
.setCustomId('select')
.setPlaceholder('Nothing selected')
.addOptions(options),
);
const reply = await interaction.reply({ content: 'Please select the corresponding label to train the bot.', components: [row], ephemeral: true });
const row = new ActionRowBuilder().addComponents(
new SelectMenuBuilder()
.setCustomId('select')
.setPlaceholder('Nothing selected')
.addOptions(options)
);
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 collector = reply.createMessageComponentCollector({
componentType: ComponentType.StringSelect,
time: 15000
});
collector.on('collect', i => {
i.client.helper.sendTrainData(interaction.targetMessage.content, i.values[0].toUpperCase());
collector.on('collect', (i) => {
i.client.helper.sendTrainData(
interaction.targetMessage.content,
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

@@ -1,23 +1,28 @@
import { Events } from 'discord.js';
export default {
name: Events.InteractionCreate,
once: false,
async execute(interaction) {
if (!interaction.isMessageContextMenuCommand()) return;
name: Events.InteractionCreate,
once: false,
async execute(interaction) {
if (!interaction.isMessageContextMenuCommand()) return;
const command = interaction.client.commands.get(interaction.commandName);
const command = interaction.client.commands.get(interaction.commandName);
if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}
if (!command) {
console.error(
`No command matching ${interaction.commandName} was found.`
);
return;
}
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
}
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({
content: 'There was an error while executing this command!',
ephemeral: true
});
}
}
};

View File

@@ -1,9 +1,9 @@
import { Events } from 'discord.js';
export default {
name: Events.MessageCreate,
once: false,
execute(msg) {
msg.client.helper.scanText(msg.content, `${msg.channelId}/${msg.id}`);
}
}
name: Events.MessageCreate,
once: false,
execute(msg) {
msg.client.helper.scanText(msg.content, `${msg.channelId}/${msg.id}`);
}
};

View File

@@ -1,30 +1,31 @@
export default {
name: 'aiResponse',
once: false,
async execute(aiRes) {
console.log(aiRes);
const response = config.responses.find(res => res.label === aiRes.predictions[0].label);
if (!response) return;
name: 'aiResponse',
once: false,
async execute(aiRes) {
const response = global.config.responses.find(
(res) => res.label === aiRes.predictions[0].label
);
if (!response) return;
if (Number(aiRes.predictions[0].score) >= response.threshold) {
const ids = aiRes.id.split('/');
let channel = client.channels.cache.get(ids[0]);
if (Number(aiRes.predictions[0].score) >= response.threshold) {
const ids = aiRes.id.split('/');
let channel = global.client.channels.cache.get(ids[0]);
if (!channel) {
await client.channels.fetch(ids[0]);
channel = client.channels.cache.get(ids[0]);
}
if (!channel) {
await global.client.channels.fetch(ids[0]);
channel = global.client.channels.cache.get(ids[0]);
}
let message = channel.messages.cache.get(ids[1]);
let message = channel.messages.cache.get(ids[1]);
if (!message) {
await channel.messages.fetch(ids[1]);
message = channel.messages.cache.get(ids[1]);
}
if (!message) {
await channel.messages.fetch(ids[1]);
message = channel.messages.cache.get(ids[1]);
}
message.reply(response.text);
message.reply(response.text);
return;
}
}
}
return;
}
}
};

View File

@@ -1,7 +1,7 @@
export default {
name: 'ocrResponse',
once: false,
execute(client, ocrRes) {
// TODO
}
}
name: 'ocrResponse',
once: false,
execute() {
// TODO
}
};

View File

@@ -1,4 +1,4 @@
import { Client, Events, GatewayIntentBits, Collection } from 'discord.js';
import { Client, GatewayIntentBits, Collection } from 'discord.js';
import { readFileSync, readdirSync } from 'node:fs';
// Fix __dirname not being defined in ES modules. (https://stackoverflow.com/a/64383997)
import { fileURLToPath } from 'node:url';
@@ -11,45 +11,59 @@ import HelperClient from '../../client/index.js';
const configJSON = readFileSync('../config.json', 'utf-8');
global.config = JSON.parse(configJSON);
const helper = new HelperClient(config);
const helper = new HelperClient(global.config);
helper.connect();
global.client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });
global.client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
]
});
client.commands = new Collection();
client.helper = helper;
global.client.commands = new Collection();
global.client.helper = helper;
const commandsPath = join(__dirname, 'commands');
const commandFiles = readdirSync(commandsPath).filter(file => file.endsWith('.js'));
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);
global.client.commands.set(command.data.name, command);
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
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 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(...args));
global.client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
global.client.on(event.name, (...args) => event.execute(...args));
}
}
// The ReVanced Helper events.
const helperEventsPath = join(__dirname, 'events/helper');
const helperEventFiles = readdirSync(helperEventsPath).filter(file => file.endsWith('.js'));
const helperEventFiles = readdirSync(helperEventsPath).filter((file) =>
file.endsWith('.js')
);
for (const file of helperEventFiles) {
const filePath = join(helperEventsPath, file);
@@ -61,4 +75,4 @@ for (const file of helperEventFiles) {
}
}
client.login(config.discord.token);
global.client.login(global.config.discord.token);

View File

@@ -5,7 +5,9 @@ const config = JSON.parse(configJSON);
const commands = [];
// Grab all the command files from the commands directory you created earlier
const commandFiles = readdirSync('./commands').filter(file => file.endsWith('.js'));
const commandFiles = readdirSync('./commands').filter((file) =>
file.endsWith('.js')
);
// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
for (const file of commandFiles) {
@@ -17,16 +19,17 @@ for (const file of commandFiles) {
const rest = new REST({ version: '10' }).setToken(config.discord.token);
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);
console.log(
`Started refreshing ${commands.length} application (/) commands.`
);
// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(
Routes.applicationCommands(config.discord.id),
{ body: commands },
);
// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(Routes.applicationCommands(config.discord.id), {
body: commands
});
console.log(`Successfully reloaded ${data.length} application (/) commands.`);
console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
// And of course, make sure you catch and log any errors!
console.error(error);
}
// And of course, make sure you catch and log any errors!
console.error(error);
}