(rewrite): Rewritten /rename to /rename-general.
This commit is contained in:
@@ -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<CommandClient> {
|
||||
cooldown = 360;
|
||||
userPermissions = [Constants.PermissionFlagsBits.ManageChannels];
|
||||
|
||||
async handleCommand(context: CommandClient<any, any>, 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');
|
||||
@@ -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.');
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -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<E621User | null> {
|
||||
|
||||
Reference in New Issue
Block a user