Add split command (#363)

Co-authored-by: Max Isom <hi@maxisom.me>
Co-authored-by: Max Isom <codetheweb@users.noreply.github.com>
This commit is contained in:
Hellyson Rodrigo Parteka 2022-03-09 23:47:52 -03:00 committed by GitHub
parent d438d46c09
commit 3dd1f21945
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 188 additions and 61 deletions

View file

@ -1,3 +1,4 @@
/* eslint-disable complexity */
import {CommandInteraction, GuildMember} from 'discord.js';
import {inject, injectable} from 'inversify';
import {Except} from 'type-fest';
@ -18,11 +19,13 @@ export default class AddQueryToQueue {
query,
addToFrontOfQueue,
shuffleAdditions,
shouldSplitChapters,
interaction,
}: {
query: string;
addToFrontOfQueue: boolean;
shuffleAdditions: boolean;
shouldSplitChapters: boolean;
interaction: CommandInteraction;
}): Promise<void> {
const guildId = interaction.guild!.id;
@ -60,18 +63,18 @@ export default class AddQueryToQueue {
// YouTube source
if (url.searchParams.get('list')) {
// YouTube playlist
newSongs.push(...await this.getSongs.youtubePlaylist(url.searchParams.get('list')!));
newSongs.push(...await this.getSongs.youtubePlaylist(url.searchParams.get('list')!, shouldSplitChapters));
} else {
const song = await this.getSongs.youtubeVideo(url.href);
const songs = await this.getSongs.youtubeVideo(url.href, shouldSplitChapters);
if (song) {
newSongs.push(song);
if (songs) {
newSongs.push(...songs);
} else {
throw new Error('that doesn\'t exist');
}
}
} else if (url.protocol === 'spotify:' || url.host === 'open.spotify.com') {
const [convertedSongs, nSongsNotFound, totalSongs] = await this.getSongs.spotifySource(query, playlistLimit);
const [convertedSongs, nSongsNotFound, totalSongs] = await this.getSongs.spotifySource(query, playlistLimit, shouldSplitChapters);
if (totalSongs > playlistLimit) {
extraMsg = `a random sample of ${playlistLimit} songs was taken`;
@ -93,10 +96,10 @@ export default class AddQueryToQueue {
}
} catch (_: unknown) {
// Not a URL, must search YouTube
const song = await this.getSongs.youtubeVideoSearch(query);
const songs = await this.getSongs.youtubeVideoSearch(query, shouldSplitChapters);
if (song) {
newSongs.push(song);
if (songs) {
newSongs.push(...songs);
} else {
throw new Error('that doesn\'t exist');
}