From d61107aedd5a7108cd3dc1eb6a542ed38f551e00 Mon Sep 17 00:00:00 2001 From: Max Isom Date: Fri, 30 Apr 2021 12:05:45 -0400 Subject: [PATCH] Add play immediate feature --- src/commands/play.ts | 12 ++++++++---- src/commands/queue.ts | 6 +++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/commands/play.ts b/src/commands/play.ts index d4f8ba2..c301fe9 100644 --- a/src/commands/play.ts +++ b/src/commands/play.ts @@ -21,7 +21,9 @@ export default class implements Command { ['play https://www.youtube.com/watch?list=PLi9drqWffJ9FWBo7ZVOiaVy0UQQEm4IbP', 'adds the playlist to the queue'], ['play https://open.spotify.com/track/3ebXMykcMXOcLeJ9xZ17XH?si=tioqSuyMRBWxhThhAW51Ig', 'plays a song from Spotify'], ['play https://open.spotify.com/album/5dv1oLETxdsYOkS2Sic00z?si=bDa7PaloRx6bMIfKdnvYQw', 'adds all songs from album to the queue'], - ['play https://open.spotify.com/playlist/37i9dQZF1DX94qaYRnkufr?si=r2fOVL_QQjGxFM5MWb84Xw', 'adds all songs from playlist to the queue'] + ['play https://open.spotify.com/playlist/37i9dQZF1DX94qaYRnkufr?si=r2fOVL_QQjGxFM5MWb84Xw', 'adds all songs from playlist to the queue'], + ['play cool music immediate', 'adds the first search result for "cool music" to the front of the queue'], + ['play cool music i', 'adds the first search result for "cool music" to the front of the queue'] ]; public requiresVC = true; @@ -64,6 +66,8 @@ export default class implements Command { return; } + const addToFrontOfQueue = args[args.length - 1] === 'i' || args[args.length - 1] === 'immediate'; + const newSongs: QueuedSong[] = []; let extraMsg = ''; @@ -112,7 +116,7 @@ export default class implements Command { } } catch (_: unknown) { // Not a URL, must search YouTube - const query = args.join(' '); + const query = addToFrontOfQueue ? args.slice(0, args.length - 1).join(' ') : args.join(' '); const song = await this.getSongs.youtubeVideoSearch(query); @@ -129,7 +133,7 @@ export default class implements Command { return; } - newSongs.forEach(song => player.add(song)); + newSongs.forEach(song => player.add(song, {immediate: addToFrontOfQueue})); const firstSong = newSongs[0]; @@ -138,7 +142,7 @@ export default class implements Command { } if (newSongs.length === 1) { - await res.stop(`u betcha, **${firstSong.title}** added to the queue${extraMsg}`); + await res.stop(`u betcha, **${firstSong.title}** added to the${addToFrontOfQueue ? ' front of the' : ''} queue${extraMsg}`); } else { await res.stop(`u betcha, **${firstSong.title}** and ${newSongs.length - 1} other songs were added to the queue${extraMsg}`); } diff --git a/src/commands/queue.ts b/src/commands/queue.ts index 8bfe155..0abc63c 100644 --- a/src/commands/queue.ts +++ b/src/commands/queue.ts @@ -35,7 +35,9 @@ export default class implements Command { const queueSize = player.queueSize(); const queuePage = args[0] ? parseInt(args[0], 10) : 1; - if (queuePage * PAGE_SIZE > queueSize && queuePage > Math.ceil((queueSize + 1) / PAGE_SIZE)) { + const maxQueuePage = Math.ceil((queueSize + 1) / PAGE_SIZE); + + if (queuePage > maxQueuePage) { await msg.channel.send(errorMsg('the queue isn\'t that big')); return; } @@ -70,6 +72,8 @@ export default class implements Command { embed.addField(`${(i + 1 + queuePageBegin).toString()}/${queueSize.toString()}`, song.title, false); }); + embed.addField('Page', `${queuePage} out of ${maxQueuePage}`, false); + await msg.channel.send(embed); } else { await msg.channel.send('queue empty');