From 47a60f911a8386890a48dc77c5c0e30993239b62 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Tue, 9 Apr 2024 22:54:22 -0400 Subject: [PATCH] Yeah, sorry, not a fan --- .env.example | 2 -- README.md | 2 -- Xiao.js | 7 ----- framework/Client.js | 24 ---------------- framework/slash/SlashCommand.js | 18 ------------ framework/slash/SlashRegistry.js | 47 -------------------------------- package.json | 2 +- slash-commands/lenny.js | 14 ---------- structures/Client.js | 7 +---- 9 files changed, 2 insertions(+), 121 deletions(-) delete mode 100644 framework/slash/SlashCommand.js delete mode 100644 framework/slash/SlashRegistry.js delete mode 100644 slash-commands/lenny.js diff --git a/.env.example b/.env.example index 643c55aa..0344c9fd 100644 --- a/.env.example +++ b/.env.example @@ -5,10 +5,8 @@ OWNERS= LOVER_USER_ID= XIAO_PREFIX= INVITE= -TEST_GUILD_ID= REPORT_CHANNEL_ID= JOIN_LEAVE_CHANNEL_ID= -COMMAND_CHANNEL_ID= # Redis info REDIS_HOST= diff --git a/README.md b/README.md index 2f127e96..89f8ceb1 100644 --- a/README.md +++ b/README.md @@ -11,10 +11,8 @@ Just read `LICENSE.md`. Give credit if you use any part of this monster, thanks. * `LOVER_USER_ID` is the Discord user ID of your significant other. This rigs certain commands, like `ship`. Optional for loners. * `XIAO_PREFIX` is the prefix the bot should have. * `INVITE` is an invite link for the bot's support server. Optional. -* `TEST_GUILD_ID` is a guild ID for the server you want to deploy test slash commands to. * `REPORT_CHANNEL_ID` is a channel ID for the bot to send reports to. Optional, by default it'll send the owners a DM. * `JOIN_LEAVE_CHANNEL_ID` is a channel ID for the bot to send server join/leave information to. Optional. -* `COMMAND_CHANNEL_ID` is a channel ID for the bot to send command usage data to. Optional. #### Redis info * `REDIS_HOST` is the hostname of your Redis server. If unsure, it's probably `localhost`. diff --git a/Xiao.js b/Xiao.js index 3975fde4..21982f4d 100644 --- a/Xiao.js +++ b/Xiao.js @@ -64,8 +64,6 @@ client.registry ]) .registerCommandsIn(path.join(__dirname, 'commands')); -client.slashRegistry.registerCommandsIn(path.join(__dirname, 'slash-commands')); - client.on('ready', async () => { client.logger.info(`[READY] Logged in as ${client.user.tag}! ID: ${client.user.id}`); @@ -329,11 +327,6 @@ client.on('warn', warn => client.logger.warn(warn)); client.on('commandRun', async command => { if (command.unknown) return; client.logger.info(`[COMMAND] ${command.name} was used.`); - if (command.ownerOnly) return; - const channel = await client.fetchCommandChannel(); - if (!channel) return; - channel.send(`\`${command.name}\` was used! It has now been used **${formatNumber(command.uses)}** times!`) - .catch(() => null); }); client.on('commandError', (command, err) => client.logger.error(`[COMMAND:${command.name}]\n${err.stack}`)); diff --git a/framework/Client.js b/framework/Client.js index 239f58e7..89cce100 100644 --- a/framework/Client.js +++ b/framework/Client.js @@ -4,7 +4,6 @@ const fs = require('fs'); const path = require('path'); const { stripIndents } = require('common-tags'); const Registry = require('./Registry'); -const SlashRegistry = require('./slash/SlashRegistry'); const Dispatcher = require('./Dispatcher'); require('./Extensions'); @@ -17,7 +16,6 @@ module.exports = class CommandClient extends Client { this.owner = typeof options.owner === 'string' ? [options.owner] : options.owner; this.invite = options.invite || null; this.registry = new Registry(this); - this.slashRegistry = new SlashRegistry(this); this.dispatcher = new Dispatcher(this); this.games = new Collection(); this.blacklist = { user: [], guild: [] }; @@ -25,7 +23,6 @@ module.exports = class CommandClient extends Client { this.once('ready', this.onceReady); this.on('messageCreate', this.onMessage); - this.on('interactionCreate', this.onInteractionCreate); } isOwner(user) { @@ -152,27 +149,6 @@ module.exports = class CommandClient extends Client { } } - async onInteractionCreate(interaction) { - if (!interaction.isChatInputCommand()) return; - - const { command } = this.slashRegistry.commands.get(interaction.commandName); - if (!command) return; - - try { - const result = await command.run(interaction); - command.uses++; - command.lastRun = new Date(); - this.emit('commandRun', command, result, interaction); - } catch (err) { - this.emit('commandError', interaction, err); - if (interaction.replied || interaction.deferred) { - await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true }); - } else { - await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true }); - } - } - } - importBlacklist() { const read = fs.readFileSync(path.join(__dirname, '..', 'blacklist.json'), { encoding: 'utf8' }); const file = JSON.parse(read); diff --git a/framework/slash/SlashCommand.js b/framework/slash/SlashCommand.js deleted file mode 100644 index 312de080..00000000 --- a/framework/slash/SlashCommand.js +++ /dev/null @@ -1,18 +0,0 @@ -module.exports = class SlashCommand { - constructor(client, options) { - Object.defineProperty(this, 'client', { value: client }); - - this.name = options.name.toLowerCase(); - this.description = options.description; - this.nsfw = options.nsfw || false; - this.guildOnly = options.guildOnly || false; - this.credit = options.credit || []; - this.credit.push({ - name: 'Dragon Fire', - url: 'https://github.com/dragonfire535', - reason: 'Code' - }); - this.uses = 0; - this.lastRun = null; - } -}; diff --git a/framework/slash/SlashRegistry.js b/framework/slash/SlashRegistry.js deleted file mode 100644 index 6df7dd56..00000000 --- a/framework/slash/SlashRegistry.js +++ /dev/null @@ -1,47 +0,0 @@ -const { SlashCommandBuilder, Routes } = require('discord.js'); -const { Collection } = require('@discordjs/collection'); -const fs = require('fs'); -const path = require('path'); -const { TEST_GUILD_ID } = process.env; - -module.exports = class SlashRegistry { - constructor(client) { - Object.defineProperty(this, 'client', { value: client }); - - this.commands = new Collection(); - } - - registerCommand(command) { - const slashCmd = new SlashCommandBuilder() - .setName(command.name) - .setDescription(command.description); - if (command.guildOnly) slashCmd.setDMPermission(false); - if (command.nsfw) slashCmd.setNSFW(true); - this.commands.set(command.name, { command, data: slashCmd }); - return this; - } - - registerCommandsIn(dir) { - const commands = fs.readdirSync(dir); - for (const command of commands) { - if (!command.endsWith('.js')) continue; - const Required = require(path.join(dir, command)); - this.registerCommand(new Required(this.client)); - } - return this; - } - - uploadTestCommands() { - return this.client.rest.put( - Routes.applicationGuildCommands(this.client.user.id, TEST_GUILD_ID), - { body: this.commands.map(cmd => cmd.data.toJSON()) } - ); - } - - uploadGlobalCommands() { - return this.client.rest.put( - Routes.applicationCommands(this.client.user.id), - { body: this.commands.map(cmd => cmd.data.toJSON()) } - ); - } -}; diff --git a/package.json b/package.json index 476fc287..fcb7bf22 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "144.0.0", + "version": "145.0.0", "description": "Your personal server companion.", "main": "Xiao.js", "private": true, diff --git a/slash-commands/lenny.js b/slash-commands/lenny.js deleted file mode 100644 index 76ae8913..00000000 --- a/slash-commands/lenny.js +++ /dev/null @@ -1,14 +0,0 @@ -const SlashCommand = require('../framework/slash/SlashCommand'); - -module.exports = class LennyCommand extends SlashCommand { - constructor(client) { - super(client, { - name: 'lenny', - description: 'Responds with a lenny face.' - }); - } - - run(interaction) { - return interaction.reply('( ͡° ͜ʖ ͡°)'); - } -}; diff --git a/structures/Client.js b/structures/Client.js index 81d5f2cf..a1cd3a9c 100644 --- a/structures/Client.js +++ b/structures/Client.js @@ -17,7 +17,7 @@ const PhoneManager = require('./phone/PhoneManager'); const TimerManager = require('./remind/TimerManager'); const PokemonStore = require('./pokemon/PokemonStore'); const activities = require('./activity'); -const { REPORT_CHANNEL_ID, JOIN_LEAVE_CHANNEL_ID, COMMAND_CHANNEL_ID } = process.env; +const { REPORT_CHANNEL_ID, JOIN_LEAVE_CHANNEL_ID } = process.env; module.exports = class XiaoClient extends CommandClient { constructor(options) { @@ -110,9 +110,4 @@ module.exports = class XiaoClient extends CommandClient { if (!JOIN_LEAVE_CHANNEL_ID) return null; return this.channels.fetch(JOIN_LEAVE_CHANNEL_ID); } - - fetchCommandChannel() { - if (!COMMAND_CHANNEL_ID) return null; - return this.channels.fetch(COMMAND_CHANNEL_ID); - } };