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).
## [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
### Fixed

View file

@ -1,6 +1,7 @@
import {TextChannel, Message} from 'discord.js';
import {URL} from 'url';
import {Except} from 'type-fest';
import shuffle from 'array-shuffle';
import {TYPES} from '../types.js';
import {inject, injectable} from 'inversify';
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 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 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;
@ -78,8 +81,9 @@ export default class implements Command {
}
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 = '';
// Test if it's a complete URL
@ -150,6 +154,10 @@ export default class implements Command {
return;
}
if (shuffleAdditions) {
newSongs = shuffle(newSongs);
}
newSongs.forEach(song => {
player.add({...song, addedInChannelId: msg.channel.id}, {immediate: addToFrontOfQueue});
});