diff --git a/locales/en.json b/locales/en.json index d051317..7f8b1b9 100644 --- a/locales/en.json +++ b/locales/en.json @@ -115,13 +115,14 @@ }, "musicplayer_queue": { "title": "Queue", - "valid_args": "``clear``", + "valid_args": "``clear`` ``shuffle``", "empty": "The queue is empty! (っ˘ω˘ς )", "now_playing": "Now playing", "upcoming_song": "Upcoming song", "looping_current": "(Looping current)", "song_x_in_queue": "There are {{COUNT}} song in the queue!", - "cleared": "Queue cleared~ (。•ˇ‸ˇ•。)" + "cleared": "Queue cleared~ (。•ˇ‸ˇ•。)", + "shuffled": "Queue shuffled" }, "musicplayer_search": { "title": "Search", diff --git a/locales/jp.json b/locales/jp.json index 34d749d..bfe83ad 100644 --- a/locales/jp.json +++ b/locales/jp.json @@ -115,13 +115,14 @@ }, "musicplayer_queue": { "title": "キュー", - "valid_args": "``clear``", + "valid_args": "``clear`` ``shuffle``", "empty": "キューは空です! (っ˘ω˘ς )", "now_playing": "再生中", "upcoming_song": "次の曲", "looping_current": "(この曲の繰り返し)", "song_x_in_queue": "{{COUNT}}曲も並んでいますよ。", - "cleared": "キューがクリアされました (。•ˇ‸ˇ•。)" + "cleared": "キューがクリアされました (。•ˇ‸ˇ•。)", + "shuffled": "キューがシャッフルされました" }, "musicplayer_search": { "title": "検索", diff --git a/locales/th.json b/locales/th.json index 653db6b..adc7b06 100644 --- a/locales/th.json +++ b/locales/th.json @@ -115,13 +115,14 @@ }, "musicplayer_queue": { "title": "คิวเพลง", - "valid_args": "``clear``", + "valid_args": "``clear`` ``shuffle``", "empty": "ตอนนี้คิวว่างนะ (っ˘ω˘ς )", "now_playing": "กำลังเล่น", "upcoming_song": "เพลงต่อไป", "looping_current": "(กำลังวนซ้ำเพลงนี้)", "song_x_in_queue": "ตอนนี้มี {{COUNT}} เพลงอยู่ในคิว!", - "cleared": "เคลียร์คิวเรียบร้อยละ~ (。•ˇ‸ˇ•。)" + "cleared": "เคลียร์คิวเรียบร้อยละ~ (。•ˇ‸ˇ•。)", + "shuffled": "สุ่มคิวเรียบร้อยละ" }, "musicplayer_search": { "title": "ค้นหา", diff --git a/src/discord/MusicPlayer/Queue.ts b/src/discord/MusicPlayer/Queue.ts index d8b7d79..0a98aad 100644 --- a/src/discord/MusicPlayer/Queue.ts +++ b/src/discord/MusicPlayer/Queue.ts @@ -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)] }); + } } } diff --git a/src/providers/DiscordMusicPlayer.ts b/src/providers/DiscordMusicPlayer.ts index a6e3971..cdcb861 100644 --- a/src/providers/DiscordMusicPlayer.ts +++ b/src/providers/DiscordMusicPlayer.ts @@ -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; }