mirror of
https://github.com/kirameki-cafe/Yumi.git
synced 2026-09-14 03:09:59 +00:00
Music player embed for Spotify
This commit is contained in:
@@ -14,7 +14,7 @@ import { I18n } from 'i18n';
|
||||
import { joinVoiceChannelProcedure } from './Join';
|
||||
|
||||
import DiscordProvider from '../../providers/Discord';
|
||||
import DiscordMusicPlayer, { ValidTracks } from '../../providers/DiscordMusicPlayer';
|
||||
import DiscordMusicPlayer, { TrackUtils, ValidTracks } from '../../providers/DiscordMusicPlayer';
|
||||
import Locale from '../../services/Locale';
|
||||
|
||||
import DiscordModule, { HybridInteractionMessage } from '../../utils/DiscordModule';
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
sendHybridInteractionMessageResponse,
|
||||
makeInfoEmbed
|
||||
} from '../../utils/DiscordMessage';
|
||||
import { SpotifyTrack, YouTubeVideo } from 'play-dl';
|
||||
|
||||
const EMBEDS = {
|
||||
PLAY_INFO: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
@@ -33,24 +34,25 @@ const EMBEDS = {
|
||||
fields: [
|
||||
{
|
||||
name: locale.__('common.available_args'),
|
||||
value: locale.__('musicplayer_play.valid_args'),
|
||||
value: locale.__('musicplayer_play.valid_args')
|
||||
}
|
||||
],
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
ADDED_QUEUE: (data: HybridInteractionMessage, locale: I18n, track: ValidTracks) => {
|
||||
ADDED_QUEUE: async (data: HybridInteractionMessage, locale: I18n, track: ValidTracks) => {
|
||||
|
||||
const title = TrackUtils.getTitle(track);
|
||||
const thumbnails = await TrackUtils.getThumbnails(track);
|
||||
|
||||
let embed = makeSuccessEmbed({
|
||||
title: locale.__('musicplayer_play.queue_added_song'),
|
||||
description: track.title,
|
||||
description: title,
|
||||
user: data.getUser()
|
||||
});
|
||||
|
||||
const highestResolutionThumbnail = track.thumbnails.reduce((prev, current) =>
|
||||
prev.height * prev.width > current.height * current.width ? prev : current
|
||||
);
|
||||
|
||||
if (highestResolutionThumbnail) embed.setImage(highestResolutionThumbnail.url);
|
||||
if (TrackUtils.getHighestResolutionThumbnail(thumbnails))
|
||||
embed.setImage(TrackUtils.getHighestResolutionThumbnail(thumbnails).url);
|
||||
|
||||
return embed;
|
||||
},
|
||||
@@ -158,7 +160,7 @@ export default class Play extends DiscordModule {
|
||||
await joinVoiceChannelProcedure(new HybridInteractionMessage(interaction), null, voiceChannel);
|
||||
|
||||
let instance = DiscordMusicPlayer.getGuildInstance(guild.id);
|
||||
if(!instance) return;
|
||||
if (!instance) return;
|
||||
|
||||
if (instance!.voiceChannel.id !== member.voice.channel.id)
|
||||
return await sendHybridInteractionMessageResponse(
|
||||
@@ -223,7 +225,8 @@ export default class Play extends DiscordModule {
|
||||
const voiceChannel = DiscordProvider.client.guilds.cache.get(guild.id)?.channels.cache.get(payload.d.v);
|
||||
//let member = DiscordProvider.client.guilds.cache.get(guild.id)?.members.cache.get(user.id);
|
||||
|
||||
if (!voiceChannel || !(voiceChannel instanceof VoiceChannel || voiceChannel instanceof StageChannel)) return;
|
||||
if (!voiceChannel || !(voiceChannel instanceof VoiceChannel || voiceChannel instanceof StageChannel))
|
||||
return;
|
||||
|
||||
if (!member.voice.channel)
|
||||
return await sendHybridInteractionMessageResponse(
|
||||
@@ -236,12 +239,16 @@ export default class Play extends DiscordModule {
|
||||
await joinVoiceChannelProcedure(new HybridInteractionMessage(interaction), null, voiceChannel);
|
||||
|
||||
let instance = DiscordMusicPlayer.getGuildInstance(guild.id);
|
||||
if(!instance) return;
|
||||
if (!instance) return;
|
||||
|
||||
if (instance!.voiceChannel.id !== member.voice.channel.id)
|
||||
return await sendHybridInteractionMessageResponse(
|
||||
hybridData,
|
||||
{ embeds: [EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(new HybridInteractionMessage(interaction), locale)] },
|
||||
{
|
||||
embeds: [
|
||||
EMBEDS.USER_NOT_IN_SAME_VOICECHANNEL(new HybridInteractionMessage(interaction), locale)
|
||||
]
|
||||
},
|
||||
true
|
||||
);
|
||||
|
||||
@@ -267,7 +274,7 @@ export default class Play extends DiscordModule {
|
||||
instance.addTrackToQueue(result);
|
||||
return await sendHybridInteractionMessageResponse(
|
||||
hybridData,
|
||||
{ embeds: [EMBEDS.ADDED_QUEUE(new HybridInteractionMessage(interaction), locale, result)] },
|
||||
{ embeds: [await EMBEDS.ADDED_QUEUE(new HybridInteractionMessage(interaction), locale, result)] },
|
||||
true
|
||||
);
|
||||
}
|
||||
@@ -306,7 +313,7 @@ export default class Play extends DiscordModule {
|
||||
}
|
||||
|
||||
let instance = DiscordMusicPlayer.getGuildInstance(guild.id);
|
||||
if(!instance) return;
|
||||
if (!instance) return;
|
||||
|
||||
if (instance!.voiceChannel.id !== member.voice.channel.id)
|
||||
return await sendHybridInteractionMessageResponse(
|
||||
@@ -368,13 +375,55 @@ export default class Play extends DiscordModule {
|
||||
);
|
||||
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.ADDED_QUEUE(data, locale, result)],
|
||||
embeds: [await EMBEDS.ADDED_QUEUE(data, locale, result)],
|
||||
components: [row]
|
||||
});
|
||||
} else
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.ADDED_QUEUE(data, locale, result)]
|
||||
embeds: [await EMBEDS.ADDED_QUEUE(data, locale, result)]
|
||||
});
|
||||
} else if (DiscordMusicPlayer.isSpotifyLink(query)) {
|
||||
let linkData = DiscordMusicPlayer.parseSpotifyLink(query);
|
||||
|
||||
if (linkData.type === 'playlist' || linkData.type === 'album') {
|
||||
let playlist = await DiscordMusicPlayer.getSpotifySongsInPlayList(query);
|
||||
const songs = await playlist.all_tracks();
|
||||
|
||||
for (const song of songs) {
|
||||
instance.addTrackToQueue(song);
|
||||
}
|
||||
|
||||
return await sendHybridInteractionMessageResponse(
|
||||
data,
|
||||
{ embeds: [EMBEDS.ADDED_SONGS_QUEUE(data, locale, songs)] },
|
||||
true
|
||||
);
|
||||
} else if (false) {
|
||||
sendHybridInteractionMessageResponse(
|
||||
data,
|
||||
{ embeds: [EMBEDS.LOOKUP_ERROR(data, locale, new Error('Album not supported for now'))] },
|
||||
true
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
let result = await DiscordMusicPlayer.searchSpotifyBySpotifyLink(linkData).catch((err) => {
|
||||
sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.LOOKUP_ERROR(data, locale, err)] }, true);
|
||||
return null;
|
||||
});
|
||||
|
||||
if (!result) return;
|
||||
|
||||
if (data.isMessage() && data.getMessage().embeds.length > 0) {
|
||||
data.getMessage().suppressEmbeds(true);
|
||||
}
|
||||
|
||||
instance.addTrackToQueue(result);
|
||||
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [await EMBEDS.ADDED_QUEUE(data, locale, result)]
|
||||
});
|
||||
|
||||
} else {
|
||||
let result = await DiscordMusicPlayer.searchYouTubeByQuery(query);
|
||||
|
||||
@@ -407,13 +456,13 @@ export default class Play extends DiscordModule {
|
||||
);
|
||||
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.ADDED_QUEUE(data, locale, result[0])],
|
||||
embeds: [await EMBEDS.ADDED_QUEUE(data, locale, result[0])],
|
||||
components: [row]
|
||||
});
|
||||
}
|
||||
|
||||
return await sendHybridInteractionMessageResponse(data, {
|
||||
embeds: [EMBEDS.ADDED_QUEUE(data, locale, result[0])]
|
||||
embeds: [await EMBEDS.ADDED_QUEUE(data, locale, result[0])]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user