Add option to shuffle newly added playlist (#473)

Co-authored-by: Max Isom <codetheweb@users.noreply.github.com>
This commit is contained in:
Koopa 2022-01-17 14:17:31 -05:00 committed by GitHub
parent c22722ea0e
commit 7090ed2a52
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View file

@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased] ## [Unreleased]
### Added
- Playlists can now be shuffled as they are added to the queue, using the `shuffle` option to `play`.
## [0.3.2] - 2022-01-17 ## [0.3.2] - 2022-01-17
### Fixed ### Fixed

View file

@ -1,6 +1,7 @@
import {TextChannel, Message} from 'discord.js'; import {TextChannel, Message} from 'discord.js';
import {URL} from 'url'; import {URL} from 'url';
import {Except} from 'type-fest'; import {Except} from 'type-fest';
import shuffle from 'array-shuffle';
import {TYPES} from '../types.js'; import {TYPES} from '../types.js';
import {inject, injectable} from 'inversify'; import {inject, injectable} from 'inversify';
import {QueuedSong, STATUS} from '../services/player.js'; import {QueuedSong, STATUS} from '../services/player.js';
@ -26,6 +27,8 @@ export default class implements Command {
['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 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'], ['play cool music i', 'adds the first search result for "cool music" to the front of the queue'],
['play https://www.youtube.com/watch?list=PLi9drqWffJ9FWBo7ZVOiaVy0UQQEm4IbP shuffle', 'adds the shuffled playlist to the queue'],
['play https://www.youtube.com/watch?list=PLi9drqWffJ9FWBo7ZVOiaVy0UQQEm4IbP s', 'adds the shuffled playlist to the queue'],
]; ];
public requiresVC = true; public requiresVC = true;
@ -78,8 +81,9 @@ export default class implements Command {
} }
const addToFrontOfQueue = args[args.length - 1] === 'i' || args[args.length - 1] === 'immediate'; const addToFrontOfQueue = args[args.length - 1] === 'i' || args[args.length - 1] === 'immediate';
const shuffleAdditions = args[args.length - 1] === 's' || args[args.length - 1] === 'shuffle';
const newSongs: Array<Except<QueuedSong, 'addedInChannelId'>> = []; let newSongs: Array<Except<QueuedSong, 'addedInChannelId'>> = [];
let extraMsg = ''; let extraMsg = '';
// Test if it's a complete URL // Test if it's a complete URL
@ -150,6 +154,10 @@ export default class implements Command {
return; return;
} }
if (shuffleAdditions) {
newSongs = shuffle(newSongs);
}
newSongs.forEach(song => { newSongs.forEach(song => {
player.add({...song, addedInChannelId: msg.channel.id}, {immediate: addToFrontOfQueue}); player.add({...song, addedInChannelId: msg.channel.id}, {immediate: addToFrontOfQueue});
}); });