diff --git a/commands/reddit.js b/commands/fun/reddit.js similarity index 100% rename from commands/reddit.js rename to commands/fun/reddit.js diff --git a/commands/download.js b/commands/utility/download.js similarity index 99% rename from commands/download.js rename to commands/utility/download.js index 128e8ff..857d9d3 100644 --- a/commands/download.js +++ b/commands/utility/download.js @@ -3,7 +3,7 @@ import { MessageEmbed, MessageActionRow, MessageSelectMenu } from 'discord.js'; import { exec } from 'node:child_process'; import fs from 'node:fs'; import os from 'node:os'; -import utils from '../utils/videos.js'; +import utils from '../../utils/videos.js'; export default { data: new SlashCommandBuilder() diff --git a/commands/ping.js b/commands/utility/ping.js similarity index 70% rename from commands/ping.js rename to commands/utility/ping.js index 2f6847c..07bdb90 100644 --- a/commands/ping.js +++ b/commands/utility/ping.js @@ -5,6 +5,6 @@ export default { .setName('ping') .setDescription('Replies with Pong!'), async execute(interaction) { - await interaction.reply('Pong!'); + await interaction.reply(`Pong! \`${Math.round(interaction.client.ws.ping)} ms\``); }, }; diff --git a/commands/vid2gif.js b/commands/utility/vid2gif.js similarity index 95% rename from commands/vid2gif.js rename to commands/utility/vid2gif.js index b8cb766..b43cc4b 100644 --- a/commands/vid2gif.js +++ b/commands/utility/vid2gif.js @@ -1,5 +1,5 @@ import { SlashCommandBuilder } from '@discordjs/builders'; -import utils from '../utils/videos.js'; +import utils from '../../utils/videos.js'; import fs from 'node:fs'; import os from 'node:os'; import path from 'node:path'; @@ -55,7 +55,7 @@ export default { async function gifski(output, input) { return await new Promise((resolve, reject) => { - exec(`gifski -o ${output} ${input}`, (err, stdout, stderr) => { + exec(`gifski --quality 70 -o ${output} ${input}`, (err, stdout, stderr) => { if (err) { reject(stderr); } diff --git a/index.js b/index.js index f017e05..3c3bdd3 100644 --- a/index.js +++ b/index.js @@ -11,49 +11,43 @@ const __dirname = path.dirname(__filename); const client = new Client({ intents: [Intents.FLAGS.GUILDS] }); -// Load commands from the commands folder +// Load commands client.commands = new Collection(); -const commandsPath = path.join(__dirname, 'commands'); -const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js')); +await loadCommandFromDir('fun'); +await loadCommandFromDir('utility'); -for (const file of commandFiles) { - const filePath = path.join(commandsPath, file); - let command = await import(filePath); - command = command.default; +// Load events +loadEventFromDir('client', client); +loadEventFromDir('process', process); - client.commands.set(command.data.name, command); -} +client.login(token); -// Load client events from the events folder -const clientEventsPath = path.join(__dirname, 'events/client'); -const clientEventFiles = fs.readdirSync(clientEventsPath).filter(file => file.endsWith('.js')); +async function loadCommandFromDir(dir) { + const commandsPath = path.join(`${__dirname}/commands`, dir); + const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js')); -for (const file of clientEventFiles) { - const filePath = path.join(clientEventsPath, file); - let event = await import(filePath); - event = event.default; - if (event.once) { - client.once(event.name, (...args) => event.execute(...args)); - } - else { - client.on(event.name, (...args) => event.execute(...args)); - } -} + for (const file of commandFiles) { + const filePath = path.join(commandsPath, file); + let command = await import(filePath); + command = command.default; -// Load process events from the events folder -const processEventsPath = path.join(__dirname, 'events/process'); -const processEventFiles = fs.readdirSync(processEventsPath).filter(file => file.endsWith('.js')); - -for (const file of processEventFiles) { - const filePath = path.join(processEventsPath, file); - let event = await import(filePath); - event = event.default; - if (event.once) { - process.once(event.name, (...args) => event.execute(...args)); - } - else { - process.on(event.name, (...args) => event.execute(...args)); + client.commands.set(command.data.name, command); } } -client.login(token); +async function loadEventFromDir(dir, listener) { + const eventsPath = path.join(`${__dirname}/events`, dir); + const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js')); + + for (const file of eventFiles) { + const filePath = path.join(eventsPath, file); + let event = await import(filePath); + event = event.default; + if (event.once) { + listener.once(event.name, (...args) => event.execute(...args)); + } + else { + listener.on(event.name, (...args) => event.execute(...args)); + } + } +} \ No newline at end of file diff --git a/prereq.js b/prereq.cjs similarity index 100% rename from prereq.js rename to prereq.cjs