Compare commits
4 Commits
e8c63a2118
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5a81ce7416 | ||
|
|
d335287e7e | ||
|
|
67ff52227d | ||
|
|
09684b2070 |
@@ -279,6 +279,9 @@ export class GuildPlayer {
|
||||
const author = this.lastPlayedTrack.info.author;
|
||||
let result;
|
||||
let usedYtFallback = false;
|
||||
// 중복 제거 기준 ID. 기본은 lastPlayed의 identifier, 다만 Spotify→YouTube 폴백 시에는
|
||||
// RD 믹스의 시드(YouTube videoId)와 비교해야 첫 곡(=방금 끝난 곡의 YouTube 버전)을 제거할 수 있음.
|
||||
let dedupId = trackId;
|
||||
|
||||
if (source === "spotify") {
|
||||
const sprecUri = `sprec:seed_tracks=${trackId}&limit=11`;
|
||||
@@ -302,7 +305,9 @@ export class GuildPlayer {
|
||||
} else {
|
||||
Logger.warn(`[autoPlay] sprec 결과 없음. YouTube으로 폴백합니다.`);
|
||||
}
|
||||
result = await this.youtubeMixFromSpotifyTrack(author, title);
|
||||
const fallback = await this.youtubeMixFromSpotifyTrack(author, title);
|
||||
result = fallback?.result;
|
||||
if (fallback?.seedYtId) dedupId = fallback.seedYtId;
|
||||
usedYtFallback = true;
|
||||
}
|
||||
} else {
|
||||
@@ -327,7 +332,7 @@ export class GuildPlayer {
|
||||
this.end();
|
||||
return;
|
||||
}
|
||||
if (tracks.length > 0 && tracks[0].info.identifier === trackId) tracks = tracks.slice(1);
|
||||
if (tracks.length > 0 && tracks[0].info.identifier === dedupId) tracks = tracks.slice(1);
|
||||
if (tracks.length === 0) {
|
||||
this.end();
|
||||
return;
|
||||
@@ -339,6 +344,7 @@ export class GuildPlayer {
|
||||
* Spotify 트랙 메타데이터로 YouTube 검색 후 매칭된 곡의 RD 믹스를 가져옴.
|
||||
* (현재 Lavalink에서 `ytmsearch:`는 EMPTY를 자주 반환하므로 `ytsearch:` 사용)
|
||||
* 각 단계가 실패하면 다음 단계로 진행하지 않고 undefined 반환.
|
||||
* 호출 측에서 RD 믹스 첫 곡(=시드 자체)을 중복 제거할 수 있도록 seed videoId도 같이 반환.
|
||||
*/
|
||||
private async youtubeMixFromSpotifyTrack(author: string, title: string) {
|
||||
const cleanAuthor = author.replace(" - Topic", "");
|
||||
@@ -358,10 +364,11 @@ export class GuildPlayer {
|
||||
Logger.warn(`[autoPlay] YouTube 폴백 검색 결과 없음 (query="${cleanAuthor} ${title}", loadType=${searchResult?.loadType ?? "(null)"})`);
|
||||
return undefined;
|
||||
}
|
||||
const ytId = searchResult.data[0].info.identifier;
|
||||
Logger.info(`[autoPlay] YouTube 폴백 매칭: videoId=${ytId}`);
|
||||
const seedYtId = searchResult.data[0].info.identifier;
|
||||
Logger.info(`[autoPlay] YouTube 폴백 매칭: videoId=${seedYtId}`);
|
||||
try {
|
||||
return await this.player.node.rest.resolve(`https://music.youtube.com/watch?v=${ytId}&list=RD${ytId}`);
|
||||
const result = await this.player.node.rest.resolve(`https://music.youtube.com/watch?v=${seedYtId}&list=RD${seedYtId}`);
|
||||
return { result, seedYtId };
|
||||
} catch (err) {
|
||||
Logger.warn(`[autoPlay] YouTube 폴백 RD 믹스 resolve throw: ${String(err)}`);
|
||||
return undefined;
|
||||
|
||||
@@ -31,6 +31,11 @@ export class LavalinkManager {
|
||||
});
|
||||
}
|
||||
|
||||
/** 연결 가능한(CONNECTED 상태) Lavalink 노드가 하나라도 있는지 확인 */
|
||||
hasReadyNode(): boolean {
|
||||
return !!this.shoukaku.options.nodeResolver(this.shoukaku.nodes);
|
||||
}
|
||||
|
||||
getPlayer(guildId: string) {
|
||||
return this.players.get(guildId);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { client, lavalinkManager } from "../index";
|
||||
import { Command } from "../types/Command";
|
||||
import { GuildPlayer } from "../classes/GuildPlayer";
|
||||
import { getTextChannelAndMsg } from "../utils/music/Channel";
|
||||
import { Logger } from "../utils/Logger";
|
||||
|
||||
/** join 명령어 */
|
||||
export default class implements Command {
|
||||
@@ -73,15 +74,38 @@ export async function channelJoin(guild: Guild | null, voiceChannelId: string |
|
||||
|
||||
let player = lavalinkManager.getPlayer(guild.id);
|
||||
if (player) return { embed: client.mkembed({ title: `이미 <#${player.voiceChannelId}> 참가중입니다.` }), player };
|
||||
player = new GuildPlayer(
|
||||
guild,
|
||||
await lavalinkManager.shoukaku.joinVoiceChannel({
|
||||
|
||||
// 연결 가능한 Lavalink 노드가 없으면 joinVoiceChannel이 throw 되어 unhandledRejection으로 번짐.
|
||||
// 노드 미연결 시 사용자에게 안내만 하고 종료.
|
||||
if (!lavalinkManager.hasReadyNode()) {
|
||||
return { embed: client.mkembed({
|
||||
title: "음악 서버에 연결할 수 없습니다.",
|
||||
description: "잠시 후 다시 시도해주세요.",
|
||||
color: "DarkRed",
|
||||
}) };
|
||||
}
|
||||
|
||||
let voicePlayer;
|
||||
try {
|
||||
voicePlayer = await lavalinkManager.shoukaku.joinVoiceChannel({
|
||||
guildId: guild.id,
|
||||
channelId: voiceChannel.id,
|
||||
shardId: guild.shardId,
|
||||
deaf: true,
|
||||
mute: false,
|
||||
}),
|
||||
});
|
||||
} catch (err) {
|
||||
Logger.error(`[channelJoin] 음성채널 참가 실패: ${String(err)}`);
|
||||
return { embed: client.mkembed({
|
||||
title: "음성채널 참가에 실패했습니다.",
|
||||
description: "잠시 후 다시 시도해주세요.",
|
||||
color: "DarkRed",
|
||||
}) };
|
||||
}
|
||||
|
||||
player = new GuildPlayer(
|
||||
guild,
|
||||
voicePlayer,
|
||||
voiceChannel.id,
|
||||
channel,
|
||||
msg,
|
||||
|
||||
@@ -19,7 +19,9 @@ const cmdErr = (message: Message, commandName: string | undefined | null): void
|
||||
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);
|
||||
handleMessage(message).catch((err) => {
|
||||
Logger.error(`[messageCreate] handleMessage 처리 중 에러: ${String(err)}`);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -33,7 +35,7 @@ export const messageCreate = async (message: Message): Promise<void> => {
|
||||
cmdErr(message, commandName);
|
||||
return client.msgDelete(message, 0, true);
|
||||
}
|
||||
command.messageRun(message, args);
|
||||
await command.messageRun(message, args);
|
||||
client.msgDelete(message, 0, true);
|
||||
} catch(err: any) {
|
||||
if (Config.debug) Logger.error(err);
|
||||
@@ -78,6 +80,6 @@ async function handleMessage(message: Message): Promise<void> {
|
||||
}) ] }).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);
|
||||
await lavalinkManager.search(message.guild.id, message.content.trim(), message.member.user.id, player);
|
||||
return client.msgDelete(message, 100, true);
|
||||
}
|
||||
Reference in New Issue
Block a user