diff --git a/commands/general/channel.js b/commands/general/channel.js index af661393..922ef0b9 100644 --- a/commands/general/channel.js +++ b/commands/general/channel.js @@ -1,106 +1,7 @@ -import process from "node:process"; -import { GuildChannel } from "oceanic.js"; import Command from "#cmd-classes/command.js"; -import { safeBigInt } from "#utils/misc.js"; class ChannelCommand extends Command { - async run() { - this.success = false; - if (!this.guild) return this.getString("guildOnly"); - if (!this.database) return this.getString("noDatabase"); - if (!this.channel) throw Error("No channel found"); - const owners = process.env.OWNER?.split(",") ?? []; - if (!this.memberPermissions.has("ADMINISTRATOR") && !owners.includes(this.author.id)) - return this.getString("commands.responses.channel.adminOnly"); - if (this.args.length === 0) return this.getString("commands.responses.channel.noCmd"); - if (this.args[0] !== "disable" && this.args[0] !== "enable") - return this.getString("commands.responses.channel.invalid"); - - const guildDB = await this.database.getGuild(this.guild.id); - - if (this.args[0].toLowerCase() === "disable") { - let channel; - if (this.args[1]?.match(/^?$/) && safeBigInt(this.args[1]) >= 21154535154122752n) { - const id = this.args[1] - .replaceAll("@", "") - .replaceAll("#", "") - .replaceAll("!", "") - .replaceAll("&", "") - .replaceAll("<", "") - .replaceAll(">", ""); - if (guildDB.disabled.includes(id)) return this.getString("commands.responses.channel.alreadyDisabled"); - channel = this.guild.channels.get(id) ?? (await this.client.rest.channels.get(id)); - } else { - if (guildDB.disabled.includes(this.channel.id)) - return this.getString("commands.responses.channel.alreadyDisabled"); - channel = this.channel; - } - if (!(channel instanceof GuildChannel) || channel.guildID !== this.guild.id) - return this.getString("commands.responses.channel.notInServer"); - - await this.database.disableChannel(channel); - this.success = true; - return this.getString("commands.responses.channel.disabled", { - params: { - prefix: guildDB.prefix, - }, - }); - } - if (this.args[0].toLowerCase() === "enable") { - let channel; - if (this.args[1]?.match(/^?$/) && safeBigInt(this.args[1]) >= 21154535154122752n) { - const id = this.args[1] - .replaceAll("@", "") - .replaceAll("#", "") - .replaceAll("!", "") - .replaceAll("&", "") - .replaceAll("<", "") - .replaceAll(">", ""); - if (!guildDB.disabled.includes(id)) return this.getString("commands.responses.channel.notDisabled"); - channel = this.guild.channels.get(id) ?? (await this.client.rest.channels.get(id)); - } else { - if (!guildDB.disabled.includes(this.channel.id)) - return this.getString("commands.responses.channel.notDisabled"); - channel = this.channel; - } - if (!(channel instanceof GuildChannel) || channel.guildID !== this.guild.id) - return this.getString("commands.responses.channel.notInServer"); - - await this.database.enableChannel(channel); - this.success = true; - return this.getString("commands.responses.channel.reEnabled"); - } - } - static description = "Enables/disables classic commands in a channel (use server settings for slash commands)"; - static flags = [ - { - name: "enable", - type: "subcommand", - description: "Enables classic commands in a channel", - options: [ - { - name: "channel", - type: "string", - description: "The channel to enable", - classic: true, - }, - ], - }, - { - name: "disable", - type: "subcommand", - description: "Disables classic commands in a channel", - options: [ - { - name: "channel", - type: "string", - description: "The channel to disable", - classic: true, - }, - ], - }, - ]; static slashAllowed = false; static directAllowed = false; static dbRequired = true; diff --git a/commands/general/channel/disable.js b/commands/general/channel/disable.js new file mode 100644 index 00000000..a68a5dbd --- /dev/null +++ b/commands/general/channel/disable.js @@ -0,0 +1,60 @@ +import { GuildChannel } from "oceanic.js"; +import Command from "#cmd-classes/command.js"; +import { safeBigInt } from "#utils/misc.js"; + +class ChannelDisableCommand extends Command { + async run() { + this.success = false; + if (!this.guild) return this.getString("guildOnly"); + if (!this.database) return this.getString("noDatabase"); + if (!this.channel) throw Error("No channel found"); + const owners = process.env.OWNER?.split(",") ?? []; + if (!this.memberPermissions.has("ADMINISTRATOR") && !owners.includes(this.author.id)) + return this.getString("commands.responses.channel.adminOnly"); + + const channelId = this.getOptionString("channel", true); + const guildDB = await this.database.getGuild(this.guild.id); + + let channel; + if (channelId?.match(/^?$/) && safeBigInt(channelId) >= 21154535154122752n) { + const id = channelId + .replaceAll("@", "") + .replaceAll("#", "") + .replaceAll("!", "") + .replaceAll("&", "") + .replaceAll("<", "") + .replaceAll(">", ""); + if (guildDB.disabled.includes(id)) return this.getString("commands.responses.channel.alreadyDisabled"); + channel = this.guild.channels.get(id) ?? (await this.client.rest.channels.get(id)); + } else { + if (guildDB.disabled.includes(this.channel.id)) + return this.getString("commands.responses.channel.alreadyDisabled"); + channel = this.channel; + } + if (!(channel instanceof GuildChannel) || channel.guildID !== this.guild.id) + return this.getString("commands.responses.channel.notInServer"); + + await this.database.disableChannel(channel); + this.success = true; + return this.getString("commands.responses.channel.disabled", { + params: { + prefix: guildDB.prefix, + }, + }); + } + + static description = "Disables classic commands in a channel"; + static flags = [ + { + name: "channel", + type: "string", + description: "The channel to disable", + classic: true, + }, + ]; + static slashAllowed = false; + static directAllowed = false; + static dbRequired = true; +} + +export default ChannelDisableCommand; diff --git a/commands/general/channel/enable.js b/commands/general/channel/enable.js new file mode 100644 index 00000000..26d4b062 --- /dev/null +++ b/commands/general/channel/enable.js @@ -0,0 +1,55 @@ +import { GuildChannel } from "oceanic.js"; +import Command from "#cmd-classes/command.js"; +import { safeBigInt } from "#utils/misc.js"; + +class ChannelEnableCommand extends Command { + async run() { + this.success = false; + if (!this.guild) return this.getString("guildOnly"); + if (!this.database) return this.getString("noDatabase"); + if (!this.channel) throw Error("No channel found"); + const owners = process.env.OWNER?.split(",") ?? []; + if (!this.memberPermissions.has("ADMINISTRATOR") && !owners.includes(this.author.id)) + return this.getString("commands.responses.channel.adminOnly"); + + const channelId = this.getOptionString("channel", true); + const guildDB = await this.database.getGuild(this.guild.id); + + let channel; + if (channelId?.match(/^?$/) && safeBigInt(channelId) >= 21154535154122752n) { + const id = channelId + .replaceAll("@", "") + .replaceAll("#", "") + .replaceAll("!", "") + .replaceAll("&", "") + .replaceAll("<", "") + .replaceAll(">", ""); + if (!guildDB.disabled.includes(id)) return this.getString("commands.responses.channel.notDisabled"); + channel = this.guild.channels.get(id) ?? (await this.client.rest.channels.get(id)); + } else { + if (!guildDB.disabled.includes(this.channel.id)) return this.getString("commands.responses.channel.notDisabled"); + channel = this.channel; + } + if (!(channel instanceof GuildChannel) || channel.guildID !== this.guild.id) + return this.getString("commands.responses.channel.notInServer"); + + await this.database.enableChannel(channel); + this.success = true; + return this.getString("commands.responses.channel.reEnabled"); + } + + static description = "Enables classic commands in a channel"; + static flags = [ + { + name: "channel", + type: "string", + description: "The channel to enable", + classic: true, + }, + ]; + static slashAllowed = false; + static directAllowed = false; + static dbRequired = true; +} + +export default ChannelEnableCommand; diff --git a/locales/en-US.json b/locales/en-US.json index 8f855d87..a9935484 100644 --- a/locales/en-US.json +++ b/locales/en-US.json @@ -756,9 +756,8 @@ "adminOnly": "You need to be an administrator to enable/disable me in this channel!", "alreadyDisabled": "I'm already disabled in this channel!", "disabled": "I have been disabled in this channel. To re-enable me, just run `{{prefix}}channel enable`.", - "invalid": "That's not a valid option!", + "invalid": "You need to provide whether you want to enable/disable me in this channel!", "notDisabled": "I'm not disabled in this channel!", - "noCmd": "You need to provide whether you want to enable/disable me in this channel!", "notInServer": "That channel isn't in this server!", "reEnabled": "I have been re-enabled in this channel." },