기존
This commit is contained in:
129
src/commands/tts.ts
Normal file
129
src/commands/tts.ts
Normal file
@@ -0,0 +1,129 @@
|
||||
import { client } from "../index";
|
||||
import { Command } from "../types/Command";
|
||||
import { DB } from "../utils/Database";
|
||||
import { Message, ChatInputApplicationCommandData, ChannelType, ApplicationCommandOptionType, ChatInputCommandInteraction, EmbedBuilder, Guild } from "discord.js";
|
||||
|
||||
/** tts 명령어 */
|
||||
export default class implements Command {
|
||||
/** 해당 명령어 설명 */
|
||||
name = "tts";
|
||||
visible = true;
|
||||
aliases: string[] = [];
|
||||
description: string = "tts 명령어";
|
||||
metaData: ChatInputApplicationCommandData = {
|
||||
name: this.name,
|
||||
description: this.description,
|
||||
options: [
|
||||
{
|
||||
type: ApplicationCommandOptionType.SubcommandGroup,
|
||||
name: "channel",
|
||||
description: "채널 관련",
|
||||
options: [
|
||||
{
|
||||
type: ApplicationCommandOptionType.Subcommand,
|
||||
name: "make",
|
||||
description: "채널 만들기",
|
||||
},
|
||||
{
|
||||
type: ApplicationCommandOptionType.Subcommand,
|
||||
name: "register",
|
||||
description: "기존 채팅채널 등록",
|
||||
options: [
|
||||
{
|
||||
type: ApplicationCommandOptionType.Channel,
|
||||
name: "channel",
|
||||
description: "등록할 채널 (선택)",
|
||||
channel_types: [ChannelType.GuildText],
|
||||
},
|
||||
{
|
||||
type: ApplicationCommandOptionType.String,
|
||||
name: "channel_id",
|
||||
description: "채널 ID 또는 #멘션 (선택)",
|
||||
},
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
]
|
||||
};
|
||||
|
||||
/** 실행되는 부분 */
|
||||
async slashRun(interaction: ChatInputCommandInteraction) {
|
||||
const group = interaction.options.getSubcommandGroup();
|
||||
const cmd = interaction.options.getSubcommand();
|
||||
if (group === "channel") {
|
||||
if (cmd === "make") {
|
||||
await interaction.editReply({ embeds: [ await this.channel_create(interaction.guild) ] });
|
||||
return;
|
||||
}
|
||||
if (cmd === "register") {
|
||||
const channel = interaction.options.getChannel("channel");
|
||||
const channelId = interaction.options.getString("channel_id");
|
||||
await interaction.editReply({ embeds: [ this.channel_register(interaction.guild, channel?.id || channelId) ] });
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
async messageRun(message: Message) {
|
||||
if (message.channel?.type !== ChannelType.GuildText) return;
|
||||
return await message.channel.send({ content: "예시 명령어" }).then(m => client.msgDelete(m, 5));
|
||||
}
|
||||
|
||||
async channel_create(guild: Guild | null): Promise<EmbedBuilder> {
|
||||
if (!guild) return client.mkembed({
|
||||
title: "guild를 가져올수 없습니다.",
|
||||
color: "DarkRed",
|
||||
});
|
||||
const channel = await guild.channels.create({
|
||||
name: "TTS채널",
|
||||
type: ChannelType.GuildText,
|
||||
topic: "채팅치면 봇이 음성채널에 와서 읽어줍니다.",
|
||||
});
|
||||
channel.send({ embeds: [ client.mkembed({
|
||||
title: "TTS 채널입니다.",
|
||||
description: [
|
||||
"**음성채널에 들어간 후",
|
||||
"이곳에 채팅을 입력하면",
|
||||
`봇 ( <@${client.user?.id}> )(이)가 음성에`,
|
||||
"들어와 채팅을 읽어줍니다.**"
|
||||
].join("\n"),
|
||||
}) ] });
|
||||
return this.channel_register(guild, channel.id);
|
||||
}
|
||||
|
||||
channel_register(guild: Guild | null, channelId: string | null): EmbedBuilder {
|
||||
if (!guild) return client.mkembed({
|
||||
title: "guild를 가져올수 없습니다.",
|
||||
color: "DarkRed",
|
||||
});
|
||||
if (!channelId) return client.mkembed({
|
||||
title: "채널 아이디 가져오기 오류",
|
||||
color: "DarkRed",
|
||||
});
|
||||
const channel = guild.channels.cache.get(channelId.replace(/\<|\#|\!|\>/g,"").trim());
|
||||
if (!channel?.id) return client.mkembed({
|
||||
title: `${channelId} 채널 가져오기 오류`,
|
||||
color: "DarkRed",
|
||||
});
|
||||
if (!DB.guild.get(guild.id) && !DB.guild.set({
|
||||
id: guild.id,
|
||||
name: guild.name,
|
||||
channel_id: "",
|
||||
})) return client.mkembed({
|
||||
title: "DB 생성 오류",
|
||||
color: "DarkRed",
|
||||
});
|
||||
if (!DB.guild.update({
|
||||
id: guild.id,
|
||||
name: guild.name,
|
||||
channel_id: channel.id,
|
||||
})) return client.mkembed({
|
||||
title: "DB 등록 오류",
|
||||
color: "DarkRed",
|
||||
});
|
||||
return client.mkembed({
|
||||
title: "채널 생성/등록 완료",
|
||||
description: `채널: <#${channel.id}>`,
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user