aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md2
-rw-r--r--src/commands/play.ts10
2 files changed, 11 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cf07781..b3f1971 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/src/commands/play.ts b/src/commands/play.ts
index 710bb06..784885e 100644
--- a/src/commands/play.ts
+++ b/src/commands/play.ts
@@ -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});
});