mirror of
https://github.com/kirameki-cafe/Yumi.git
synced 2026-09-13 10:49:20 +00:00
Added queue shuffle
This commit is contained in:
@@ -78,6 +78,12 @@ const EMBEDS = {
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
QUEUE_SHUFFLED: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
return makeSuccessEmbed({
|
||||
title: locale.__('musicplayer_queue.shuffled'),
|
||||
user: data.getUser()
|
||||
});
|
||||
},
|
||||
NO_MUSIC_PLAYING: (data: HybridInteractionMessage, locale: I18n) => {
|
||||
return makeErrorEmbed({
|
||||
title: locale.__('musicplayer.no_music_playing'),
|
||||
@@ -124,10 +130,13 @@ export default class QueueCommand extends DiscordModule {
|
||||
}
|
||||
|
||||
if (!query) return;
|
||||
if (query.toLowerCase() !== 'clear') return;
|
||||
|
||||
instance.clearQueue();
|
||||
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.QUEUE_CLEARED(data, locale)] });
|
||||
switch (query.toLowerCase()) {
|
||||
case 'clear':
|
||||
instance.clearQueue();
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.QUEUE_CLEARED(data, locale)] });
|
||||
case 'shuffle':
|
||||
instance.shuffleQueue();
|
||||
return await sendHybridInteractionMessageResponse(data, { embeds: [EMBEDS.QUEUE_SHUFFLED(data, locale)] });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -343,6 +343,24 @@ export class DiscordMusicPlayerInstance {
|
||||
this.queue.track = [this.queue.track[0]];
|
||||
}
|
||||
|
||||
public shuffleQueue() {
|
||||
if (!this.voiceConnection) throw new Error('No voice connection');
|
||||
|
||||
const shuffleFixedFirst = (queue: ValidTracks[]) => {
|
||||
if(queue.length <= 2) return queue;
|
||||
|
||||
const fixedFirst = queue.shift();
|
||||
if(!fixedFirst) return queue;
|
||||
|
||||
queue.sort(() => Math.random() - 0.5);
|
||||
queue.unshift(fixedFirst);
|
||||
return queue;
|
||||
}
|
||||
|
||||
if(!this.queue.track || this.queue.track.length === 0) return;
|
||||
this.queue.track = shuffleFixedFirst(this.queue.track);
|
||||
}
|
||||
|
||||
public setLoopMode(mode: DiscordMusicPlayerLoopMode) {
|
||||
this.loopMode = mode;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user