From fb2412963434644752abf1c7f45b780edc84541f Mon Sep 17 00:00:00 2001 From: Nix Krystik Date: Tue, 11 Aug 2026 17:54:11 +0800 Subject: [PATCH] (rewrite): Rewritten `/rename` to `/rename-general`. --- src/commands/admin/rename-channel.ts | 68 ++++++++++++++++++++++++++++ src/commands/rename.ts | 51 --------------------- src/commands/utilities/name-sync.ts | 7 +-- 3 files changed, 72 insertions(+), 54 deletions(-) create mode 100644 src/commands/admin/rename-channel.ts delete mode 100644 src/commands/rename.ts diff --git a/src/commands/admin/rename-channel.ts b/src/commands/admin/rename-channel.ts new file mode 100644 index 0000000..0b5c439 --- /dev/null +++ b/src/commands/admin/rename-channel.ts @@ -0,0 +1,68 @@ +// External Imports +import { Command, CommandBuilder, CommandClient, CommandInteraction, Constants, SlashCommand } from 'athena-prime'; + +// Internal Imports +import { Database } from '../../shared/Database'; +import { CreateDefaultEmbed, SetSeverity } from '../../utils'; + +// --------------- + +@SlashCommand( + new CommandBuilder('rename-channel', 'Rename the general channel.') + .setIntegrationTypes(Constants.ApplicationIntegrationType.GuildInstall) + .setContexts(Constants.InteractionContextType.Guild) + .setCommandType(Constants.ApplicationCommandType.ChatInput) + .setMemberPermission(Constants.PermissionFlagsBits.ManageChannels) + .addStringOption({ name: 'name', description: 'The new general chat name.', required: true }) +) +class RenameGeneralCommand extends Command { + cooldown = 360; + userPermissions = [Constants.PermissionFlagsBits.ManageChannels]; + + async handleCommand(context: CommandClient, interaction: CommandInteraction, data: any) { + if (!interaction.inGuild()) return; + interaction.defer(); + + const settings = await Database.GetOrCreateSettings(interaction.guild.id); + if (!settings.general_chat_id) { + await interaction.createMessage({ + embeds: [{ + ...CreateDefaultEmbed(context), + ...SetSeverity('warning'), + + description: 'No general channel has been configured. Please check your configuration and try again.' + }] + }); + + return; + } + + const channel = context.getChannel(settings.general_chat_id); + if (!channel || !channel.isTextBased()) { + await interaction.createMessage({ + embeds: [{ + ...CreateDefaultEmbed(context), + ...SetSeverity('error'), + + description: 'There was an issue trying to locate the configured general channel role. Please check your configuration and try again.' + }] + }); + + return; + } + + const name = interaction.getRequiredString('name'); + await context.editChannel(settings.general_chat_id, { name: name }); + + await interaction.createMessage({ + embeds: [{ + ...CreateDefaultEmbed(context), + ...SetSeverity('success'), + + description: `Successfully updated ${channel.mention}` + }] + }); + } +} + +export default new RenameGeneralCommand('name-sync'); \ No newline at end of file diff --git a/src/commands/rename.ts b/src/commands/rename.ts deleted file mode 100644 index bfb7776..0000000 --- a/src/commands/rename.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { ApplicationIntegrationType, ChatInputCommandInteraction, Client, InteractionContextType, PermissionFlagsBits, RateLimitError, SlashCommandBuilder } from 'discord.js'; -import { msToHuman } from '../utils'; -import { Database } from '../shared/Database'; - -export default { - name: 'rename', - data: new SlashCommandBuilder() - .setName('rename') - .setDescription('Rename the general channel.') - .setIntegrationTypes(ApplicationIntegrationType.GuildInstall) - .setContexts(InteractionContextType.Guild) - .setDefaultMemberPermissions(PermissionFlagsBits.BanMembers) - .addStringOption(option => - option - .setName('new-name') - .setDescription('The new name of the general channel.') - .setRequired(true) - ), - handler: async function (client: Client, interaction: ChatInputCommandInteraction) { - const guildSettings = await Database.getGuildSettings(interaction.guildId!); - - if (!guildSettings || !guildSettings.general_chat_id) { - return interaction.reply('No general chat id found.'); - } - - const name = interaction.options.getString('new-name', true); - - if (name.length > 100) { - return interaction.reply('Name must be less than 100 characters in length.'); - } - - const channel = await interaction.guild!.channels.fetch(guildSettings.general_chat_id)!; - - if (!channel) { - return interaction.reply('No general chat id found.'); - } - - try { - await channel.setName(name); - - interaction.reply(`Renamed general to ${channel.name}`); - } catch (e: any) { - if (e instanceof RateLimitError) { - return interaction.reply(`Name change limited. Try again in ${msToHuman(e.retryAfter)}`); - } - - console.error(e); - return interaction.reply('An error has occurred.'); - } - } -}; \ No newline at end of file diff --git a/src/commands/utilities/name-sync.ts b/src/commands/utilities/name-sync.ts index 042ddf9..e7531a9 100644 --- a/src/commands/utilities/name-sync.ts +++ b/src/commands/utilities/name-sync.ts @@ -1,10 +1,11 @@ +// External Imports +import { Command, CommandBuilder, CommandClient, CommandInteraction, Constants, Member, SlashCommand } from 'athena-prime'; + +// Internal Imports import { Database } from '../../shared/Database'; import { E621User } from '../../types'; import { CreateDefaultEmbed, getE621User, SetSeverity } from '../../utils'; -// External Imports -import { Command, CommandBuilder, CommandClient, CommandInteraction, Constants, Member, SlashCommand } from 'athena-prime'; - // --------------- async function fetchUser(member: Member, id: number | null): Promise {