수정
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Connectors, LoadType, Shoukaku } from "shoukaku";
|
||||
import { Connectors, LoadType, Shoukaku, Track } from "shoukaku";
|
||||
import { Client } from "discord.js";
|
||||
import { GuildPlayer } from "./GuildPlayer";
|
||||
import { Config } from "../utils/Config";
|
||||
@@ -80,4 +80,14 @@ export class LavalinkManager {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public async youtubeSearch(query: string): Promise<Track[]> {
|
||||
const node = this.shoukaku.options.nodeResolver(this.shoukaku.nodes);
|
||||
if (!node) throw new ReferenceError(`[LavalinkManager] lavalink node is missing`);
|
||||
const result = await node.rest.resolve(`ytsearch:${query.trim()}`);
|
||||
// if (!result || result.loadType === LoadType.EMPTY || result.loadType === LoadType.ERROR) return [];
|
||||
if (result?.loadType === LoadType.TRACK) return [ result.data ];
|
||||
if (result?.loadType === LoadType.SEARCH) return result.data;
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import { getGuildById, getVoiceChannelById } from "../utils/music/Channel";
|
||||
import { channelJoin } from "../commands/join";
|
||||
import { GuildPlayer } from "./GuildPlayer";
|
||||
import { Guild, VoiceChannel } from "discord.js";
|
||||
import { SongItem } from "../types/Track";
|
||||
|
||||
type SubAction =
|
||||
"search" |
|
||||
@@ -47,8 +48,17 @@ export class RedisClient {
|
||||
|
||||
if (data.action === "search") {
|
||||
const resultKey = `search:${data.requestId}`;
|
||||
const results = await Spotify.getSearchFull(data.query) ?? await YoutubeMusic.getSearchFull(data.query) ?? [];
|
||||
await this.pub.setex(resultKey, 60, JSON.stringify(results));
|
||||
const spotify: SongItem[] = (await Spotify.getSearchFull(data.query) ?? []).slice(0,10);
|
||||
const youtubeMusic: SongItem[] = (await YoutubeMusic.getSearchFull(data.query) ?? []).slice(0,10);
|
||||
const youtubeVideo: SongItem[] = (await lavalinkManager.youtubeSearch(data.query) ?? []).slice(0,10).map((video) => ({
|
||||
videoId: video.info.identifier,
|
||||
url: `https://www.youtube.com/watch?v=${video.info.identifier}`,
|
||||
title: video.info.title,
|
||||
artist: video.info.author,
|
||||
thumbnail: video.info.artworkUrl ?? "",
|
||||
duration: video.info.length,
|
||||
}));
|
||||
await this.pub.setex(resultKey, 60, JSON.stringify({ spotify, youtubeMusic, youtubeVideo }));
|
||||
Logger.log(`[Redis Pub] [setex] 결과 저장: (${resultKey})`);
|
||||
}
|
||||
if (data.action === "player_play") {
|
||||
|
||||
Reference in New Issue
Block a user