112 lines
4.0 KiB
TypeScript
112 lines
4.0 KiB
TypeScript
import { SlashCommandBuilder, PermissionFlagsBits, ChatInputCommandInteraction, ChannelType } from 'discord.js';
|
|
import { prisma } from '../database';
|
|
import { SupportedLocale } from '../i18n';
|
|
import { t } from '../i18n';
|
|
|
|
export default {
|
|
data: new SlashCommandBuilder()
|
|
.setName('voice-setup')
|
|
.setDescription('Setup a generator voice channel for temporary channels.')
|
|
.setDescriptionLocalizations({
|
|
ko: '임시 음성 채널을 위한 생성기 채널을 설정합니다.',
|
|
})
|
|
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator)
|
|
.addSubcommand(subcommand =>
|
|
subcommand
|
|
.setName('set')
|
|
.setDescription('Set an existing voice channel as a Generator')
|
|
.setDescriptionLocalizations({
|
|
ko: '기존 음성 채널을 생성기로 설정합니다',
|
|
})
|
|
.addChannelOption(option =>
|
|
option.setName('channel')
|
|
.setDescription('The voice channel to act as the Generator')
|
|
.setDescriptionLocalizations({
|
|
ko: '생성기로 사용할 음성 채널',
|
|
})
|
|
.setRequired(true)
|
|
.addChannelTypes(ChannelType.GuildVoice)
|
|
)
|
|
.addChannelOption(option =>
|
|
option.setName('category')
|
|
.setDescription('(Optional) The category where temp channels will be created')
|
|
.setDescriptionLocalizations({
|
|
ko: '(선택) 임시 채널이 생성될 카테고리',
|
|
})
|
|
.setRequired(false)
|
|
.addChannelTypes(ChannelType.GuildCategory)
|
|
)
|
|
)
|
|
.addSubcommand(subcommand =>
|
|
subcommand
|
|
.setName('create')
|
|
.setDescription('Create a new voice channel and set it as a Generator')
|
|
.setDescriptionLocalizations({
|
|
ko: '새 음성 채널을 만들고 생성기로 설정합니다',
|
|
})
|
|
.addStringOption(option =>
|
|
option.setName('name')
|
|
.setDescription('The name of the new generator voice channel')
|
|
.setDescriptionLocalizations({
|
|
ko: '새 생성기 음성 채널의 이름',
|
|
})
|
|
.setRequired(true)
|
|
)
|
|
.addChannelOption(option =>
|
|
option.setName('category')
|
|
.setDescription('(Optional) The category where the new channel will be created')
|
|
.setDescriptionLocalizations({
|
|
ko: '(선택) 새 채널이 생성될 카테고리',
|
|
})
|
|
.setRequired(false)
|
|
.addChannelTypes(ChannelType.GuildCategory)
|
|
)
|
|
),
|
|
|
|
async execute(interaction: ChatInputCommandInteraction, locale: SupportedLocale) {
|
|
const subcommand = interaction.options.getSubcommand();
|
|
const category = interaction.options.getChannel('category');
|
|
|
|
if (subcommand === 'set') {
|
|
const channel = interaction.options.getChannel('channel', true);
|
|
|
|
await prisma.voiceGenerator.upsert({
|
|
where: { channelId: channel.id },
|
|
update: { categoryId: category?.id || null, guildId: interaction.guildId! },
|
|
create: {
|
|
channelId: channel.id,
|
|
guildId: interaction.guildId!,
|
|
categoryId: category?.id || null,
|
|
}
|
|
});
|
|
|
|
await interaction.reply({
|
|
content: t(locale, 'commands.voiceSetup.setSuccess', { channel: `${channel}` }),
|
|
ephemeral: true
|
|
});
|
|
} else if (subcommand === 'create') {
|
|
const name = interaction.options.getString('name', true);
|
|
const guild = interaction.guild!;
|
|
|
|
const newChannel = await guild.channels.create({
|
|
name: name,
|
|
type: ChannelType.GuildVoice,
|
|
parent: category?.id || null,
|
|
});
|
|
|
|
await prisma.voiceGenerator.create({
|
|
data: {
|
|
channelId: newChannel.id,
|
|
guildId: guild.id,
|
|
categoryId: category?.id || null,
|
|
}
|
|
});
|
|
|
|
await interaction.reply({
|
|
content: t(locale, 'commands.voiceSetup.createSuccess', { channel: `${newChannel}` }),
|
|
ephemeral: true
|
|
});
|
|
}
|
|
},
|
|
};
|