지금까지 내용 커밋

This commit is contained in:
2026-04-08 12:59:45 +09:00
commit b0dae31cb9
68 changed files with 12083 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
import { Config } from "../utils/Config";
import { client, handler, Redis } from "../index";
import { Logger } from "../utils/Logger";
import { DB } from "../utils/Database";
import { channelRegister } from "../commands/channel";
export const clientReady = async () => {
if (!client.user) return;
Logger.ready(`봇 활성화! ${client.user.username}`);
client.user.setActivity({
name: "MUSIC 봇",
});
reloadMsg();
const guildIds = client.guilds.cache.map(guild => guild.id);
Redis.pub.set("bot-guilds", JSON.stringify(guildIds));
Logger.info(`[Redis Pub] bot-guilds 설정 완료: [${guildIds.join(",")}]`);
if (!Config.dev) return;
try {
const body = Array.from(handler.commands.values().filter(cmd => cmd.visible).map(cmd => cmd.metaData));
await client.application?.commands.set(body, Config.guildId);
Logger.ready(`DEV 길드(${Config.guildId}) 슬래시 등록: ${body.length}개`);
} catch (err) {
throw err instanceof Error ? err : new Error(String(err));
}
}
async function reloadMsg() {
const guilds = DB.guild.all();
if (guilds.length === 0) return;
for (const gdb of guilds.filter(g => g.channel_id)) {
Logger.info(`${gdb.name} : 채널 재연동`);
const guild = client.guilds.cache.get(gdb.id) ?? null;
const embed = await channelRegister(guild, gdb.channel_id);
Logger.info(`${guild?.name ?? gdb.name} : ${embed.data.title ?? "오류"}`);
}
}

View File

@@ -0,0 +1,8 @@
import { client, Redis } from "../index";
import { Logger } from "../utils/Logger";
export const guildCreate = async () => {
const guildIds = client.guilds.cache.map(guild => guild.id);
Redis.pub.set("bot-guilds", JSON.stringify(guildIds));
Logger.info(`[Redis Pub] bot-guilds 수정 완료: [${guildIds.join(",")}]`);
}

View File

@@ -0,0 +1,8 @@
import { client, Redis } from "../index";
import { Logger } from "../utils/Logger";
export const guildDelete = async () => {
const guildIds = client.guilds.cache.map(guild => guild.id);
Redis.pub.set("bot-guilds", JSON.stringify(guildIds));
Logger.info(`[Redis Pub] bot-guilds 수정 완료: [${guildIds.join(",")}]`);
}

13
bot/src/events/index.ts Normal file
View File

@@ -0,0 +1,13 @@
import { clientReady } from "./clientReady";
import { guildCreate } from "./guildCreate";
import { interactionCreate } from "./interactionCreate";
import { messageCreate } from "./messageCreate";
// import { voiceStateUpdate } from "./voiceStateUpdate";
export const onEvents = {
clientReady,
guildCreate,
interactionCreate,
messageCreate,
// voiceStateUpdate,
}

View File

@@ -0,0 +1,36 @@
import { Interaction, MessageFlags } from "discord.js";
import { handler } from "../index";
import { buttonInteraction } from "../utils/music/Button";
export const interactionCreate = async (interaction: Interaction) => {
if (interaction.isStringSelectMenu()) {
await interaction.deferReply({ flags: MessageFlags.Ephemeral }).catch(() => {});
const commandName = interaction.customId;
const args = interaction.values;
const command = handler.commands.get(commandName);
if (command?.menuRun) return await command.menuRun(interaction, args);
}
if (interaction.isButton()) {
const args = interaction.customId.split("-");
if (!args || args.length === 0) return;
if (args[0] === "music") return buttonInteraction(interaction, args.slice(1));
await interaction.deferReply({ flags: MessageFlags.Ephemeral }).catch(() => {});
const key = args.shift();
if (!key) return;
const command = handler.commands.get(key);
if (command?.buttonRun) return command.buttonRun(interaction, args);
}
if (!interaction.isChatInputCommand()) return;
/**
* 명령어 친사람만 보이게 설정
* flags: MessageFlags.Ephemeral
*/
await interaction.deferReply({ flags: MessageFlags.Ephemeral }).catch(() => {});
handler.runCommand(interaction);
}

View File

@@ -0,0 +1,83 @@
import { ChannelType, Message } from "discord.js";
import { client, handler, lavalinkManager } from "../index";
import { Config } from "../utils/Config";
import { Logger } from "../utils/Logger";
import { DB } from "../utils/Database";
import { getVoiceChannel } from "../utils/music/Channel";
import { channelJoin } from "../commands/join";
const cmdErr = (message: Message, commandName: string | undefined | null): void => {
if (!commandName) return;
if (message.channel.type !== ChannelType.GuildText) return;
message.channel.send({ embeds: [ client.mkembed({
description: `\` ${commandName} \` 이라는 명령어를 찾을 수 없습니다.`,
footer: { text: `${Config.prefix}help를 입력해 명령어를 확인해주세요.` },
color: "DarkRed",
}) ] }).then(m => client.msgDelete(m, 1));
}
export const messageCreate = async (message: Message): Promise<void> => {
if (message.author.bot || message.channel.type === ChannelType.DM) return;
if (!message.content.startsWith(client.prefix)) {
handleMessage(message);
return;
}
const content = message.content.slice(client.prefix.length).trim();
const args = content.split(/ +/g);
const commandName = args.shift()?.toLocaleLowerCase() || "";
const command = handler.commands.get(commandName) || handler.commands.find((cmd) => cmd.aliases.includes(commandName));
try {
if (!command || !command.messageRun) {
if (!commandName || commandName.replace(/\;| +/g,"").length === 0) return;
cmdErr(message, commandName);
return client.msgDelete(message, 0, true);
}
command.messageRun(message, args);
client.msgDelete(message, 0, true);
} catch(err: any) {
if (Config.debug) Logger.error(err);
cmdErr(message, commandName);
return client.msgDelete(message, 0, true);
}
}
async function handleMessage(message: Message): Promise<void> {
if (!message.guild?.id) return;
if (!message.member?.user?.id) return;
if (message.channel.type !== ChannelType.GuildText) return;
const gdb = DB.guild.get(message.guild.id);
if (!gdb?.channel_id) return;
if (gdb.channel_id !== message.channel.id) return;
let player = lavalinkManager.getPlayer(message.guild.id);
const voiceChannel = getVoiceChannel(message.member);
if (!player) {
if (!voiceChannel) {
message.channel.send({ embeds: [ client.mkembed({
author: {
name: message.member.nickname ?? message.member.user.displayName,
iconURL: message.member.displayAvatarURL({}) ?? undefined,
},
title: "음성채널을 찾을수 없습니다.",
description: "음성채널에 들어가서 사용해주세요.",
color: "DarkRed",
}) ] }).then(m => client.msgDelete(m, 1));
return client.msgDelete(message, 100, true);
}
player = (await channelJoin(message.guild, voiceChannel.id)).player;
}
if (!player) {
message.channel.send({ embeds: [ client.mkembed({
author: {
name: message.member.nickname ?? message.member.user.displayName,
iconURL: message.member.displayAvatarURL({}) ?? undefined,
},
title: "세션을 찾을수 없습니다.",
description: "다시 시도해주세요.",
color: "DarkRed",
}) ] }).then(m => client.msgDelete(m, 1));
return client.msgDelete(message, 100, true);
}
lavalinkManager.search(message.guild.id, message.content.trim(), message.member.user.id, player);
return client.msgDelete(message, 100, true);
}

View File

@@ -0,0 +1,5 @@
import { VoiceState } from "discord.js";
import { client } from "../index";
export const voiceStateUpdate = async (oldState: VoiceState, newState: VoiceState): Promise<void> => {
}