From af639159d1647ffb7b4c5c5f7ad035fe8766b6dc Mon Sep 17 00:00:00 2001 From: sofushn Date: Sat, 7 Sep 2024 13:09:45 +0200 Subject: [PATCH 1/6] feat: allow running without spotify --- src/commands/play.ts | 8 +- src/inversify.config.ts | 16 +-- src/services/add-query-to-queue.ts | 70 +----------- src/services/config.ts | 4 +- src/services/get-songs.ts | 102 ++++++++++++++++-- src/services/youtube-api.ts | 2 +- ...get-youtube-and-spotify-suggestions-for.ts | 84 ++++++++------- 7 files changed, 160 insertions(+), 126 deletions(-) diff --git a/src/commands/play.ts b/src/commands/play.ts index 25aef1c5..7851eb7c 100644 --- a/src/commands/play.ts +++ b/src/commands/play.ts @@ -1,7 +1,7 @@ import {AutocompleteInteraction, ChatInputCommandInteraction} from 'discord.js'; import {URL} from 'url'; import {SlashCommandBuilder} from '@discordjs/builders'; -import {inject, injectable} from 'inversify'; +import {inject, injectable, optional} from 'inversify'; import Spotify from 'spotify-web-api-node'; import Command from './index.js'; import {TYPES} from '../types.js'; @@ -36,12 +36,12 @@ export default class implements Command { public requiresVC = true; - private readonly spotify: Spotify; + private readonly spotify?: Spotify; private readonly cache: KeyValueCacheProvider; private readonly addQueryToQueue: AddQueryToQueue; - constructor(@inject(TYPES.ThirdParty) thirdParty: ThirdParty, @inject(TYPES.KeyValueCache) cache: KeyValueCacheProvider, @inject(TYPES.Services.AddQueryToQueue) addQueryToQueue: AddQueryToQueue) { - this.spotify = thirdParty.spotify; + constructor(@inject(TYPES.ThirdParty) @optional() thirdParty: ThirdParty, @inject(TYPES.KeyValueCache) cache: KeyValueCacheProvider, @inject(TYPES.Services.AddQueryToQueue) addQueryToQueue: AddQueryToQueue) { + this.spotify = thirdParty?.spotify; this.cache = cache; this.addQueryToQueue = addQueryToQueue; } diff --git a/src/inversify.config.ts b/src/inversify.config.ts index 2f2005e2..8e621cbc 100644 --- a/src/inversify.config.ts +++ b/src/inversify.config.ts @@ -57,11 +57,20 @@ container.bind(TYPES.Client).toConstantValue(new Client({intents})); // Managers container.bind(TYPES.Managers.Player).to(PlayerManager).inSingletonScope(); +// Config values +container.bind(TYPES.Config).toConstantValue(new ConfigProvider()); + // Services container.bind(TYPES.Services.GetSongs).to(GetSongs).inSingletonScope(); container.bind(TYPES.Services.AddQueryToQueue).to(AddQueryToQueue).inSingletonScope(); container.bind(TYPES.Services.YoutubeAPI).to(YoutubeAPI).inSingletonScope(); -container.bind(TYPES.Services.SpotifyAPI).to(SpotifyAPI).inSingletonScope(); + +// Only instanciate spotify dependencies if the Spotify client ID and secret are set +const config = container.get(TYPES.Config); +if (config.SPOTIFY_CLIENT_ID !== '' && config.SPOTIFY_CLIENT_SECRET !== '') { + container.bind(TYPES.Services.SpotifyAPI).to(SpotifyAPI).inSingletonScope(); + container.bind(TYPES.ThirdParty).to(ThirdParty); +} // Commands [ @@ -91,12 +100,7 @@ container.bind(TYPES.Services.SpotifyAPI).to(SpotifyAPI).inSingleton container.bind(TYPES.Command).to(command).inSingletonScope(); }); -// Config values -container.bind(TYPES.Config).toConstantValue(new ConfigProvider()); - // Static libraries -container.bind(TYPES.ThirdParty).to(ThirdParty); - container.bind(TYPES.FileCache).to(FileCacheProvider); container.bind(TYPES.KeyValueCache).to(KeyValueCacheProvider); diff --git a/src/services/add-query-to-queue.ts b/src/services/add-query-to-queue.ts index 401ad902..95e16fff 100644 --- a/src/services/add-query-to-queue.ts +++ b/src/services/add-query-to-queue.ts @@ -1,6 +1,5 @@ /* eslint-disable complexity */ import {ChatInputCommandInteraction, GuildMember} from 'discord.js'; -import {URL} from 'node:url'; import {inject, injectable} from 'inversify'; import shuffle from 'array-shuffle'; import {TYPES} from '../types.js'; @@ -60,74 +59,7 @@ export default class AddQueryToQueue { await interaction.deferReply({ephemeral: queueAddResponseEphemeral}); - let newSongs: SongMetadata[] = []; - let extraMsg = ''; - - // Test if it's a complete URL - try { - const url = new URL(query); - - const YOUTUBE_HOSTS = [ - 'www.youtube.com', - 'youtu.be', - 'youtube.com', - 'music.youtube.com', - 'www.music.youtube.com', - ]; - - if (YOUTUBE_HOSTS.includes(url.host)) { - // YouTube source - if (url.searchParams.get('list')) { - // YouTube playlist - newSongs.push(...await this.getSongs.youtubePlaylist(url.searchParams.get('list')!, shouldSplitChapters)); - } else { - const songs = await this.getSongs.youtubeVideo(url.href, shouldSplitChapters); - - 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, shouldSplitChapters); - - if (totalSongs > playlistLimit) { - extraMsg = `a random sample of ${playlistLimit} songs was taken`; - } - - if (totalSongs > playlistLimit && nSongsNotFound !== 0) { - extraMsg += ' and '; - } - - if (nSongsNotFound !== 0) { - if (nSongsNotFound === 1) { - extraMsg += '1 song was not found'; - } else { - extraMsg += `${nSongsNotFound.toString()} songs were not found`; - } - } - - newSongs.push(...convertedSongs); - } else { - const song = await this.getSongs.httpLiveStream(query); - - if (song) { - newSongs.push(song); - } else { - throw new Error('that doesn\'t exist'); - } - } - } catch (_: unknown) { - // Not a URL, must search YouTube - const songs = await this.getSongs.youtubeVideoSearch(query, shouldSplitChapters); - - if (songs) { - newSongs.push(...songs); - } else { - throw new Error('that doesn\'t exist'); - } - } + let [newSongs, extraMsg] = await this.getSongs.getSongs(query, playlistLimit, shouldSplitChapters); if (newSongs.length === 0) { throw new Error('no songs found'); diff --git a/src/services/config.ts b/src/services/config.ts index b6b9aeaa..a5af5a4e 100644 --- a/src/services/config.ts +++ b/src/services/config.ts @@ -12,8 +12,8 @@ export const DATA_DIR = path.resolve(process.env.DATA_DIR ? process.env.DATA_DIR const CONFIG_MAP = { DISCORD_TOKEN: process.env.DISCORD_TOKEN, YOUTUBE_API_KEY: process.env.YOUTUBE_API_KEY, - SPOTIFY_CLIENT_ID: process.env.SPOTIFY_CLIENT_ID, - SPOTIFY_CLIENT_SECRET: process.env.SPOTIFY_CLIENT_SECRET, + SPOTIFY_CLIENT_ID: process.env.SPOTIFY_CLIENT_ID ?? '', + SPOTIFY_CLIENT_SECRET: process.env.SPOTIFY_CLIENT_SECRET ?? '', REGISTER_COMMANDS_ON_BOT: process.env.REGISTER_COMMANDS_ON_BOT === 'true', DATA_DIR, CACHE_DIR: path.join(DATA_DIR, 'cache'), diff --git a/src/services/get-songs.ts b/src/services/get-songs.ts index b9577347..dcaec0cd 100644 --- a/src/services/get-songs.ts +++ b/src/services/get-songs.ts @@ -1,34 +1,120 @@ -import {inject, injectable} from 'inversify'; +import {inject, injectable, optional} from 'inversify'; import * as spotifyURI from 'spotify-uri'; import {SongMetadata, QueuedPlaylist, MediaSource} from './player.js'; import {TYPES} from '../types.js'; import ffmpeg from 'fluent-ffmpeg'; import YoutubeAPI from './youtube-api.js'; import SpotifyAPI, {SpotifyTrack} from './spotify-api.js'; +import {URL} from 'node:url'; @injectable() export default class { private readonly youtubeAPI: YoutubeAPI; - private readonly spotifyAPI: SpotifyAPI; + private readonly spotifyAPI?: SpotifyAPI; - constructor(@inject(TYPES.Services.YoutubeAPI) youtubeAPI: YoutubeAPI, @inject(TYPES.Services.SpotifyAPI) spotifyAPI: SpotifyAPI) { + constructor(@inject(TYPES.Services.YoutubeAPI) youtubeAPI: YoutubeAPI, @inject(TYPES.Services.SpotifyAPI) @optional() spotifyAPI?: SpotifyAPI) { this.youtubeAPI = youtubeAPI; this.spotifyAPI = spotifyAPI; } - async youtubeVideoSearch(query: string, shouldSplitChapters: boolean): Promise { + async getSongs(query: string, playlistLimit: number, shouldSplitChapters: boolean): Promise<[SongMetadata[], string]> { + let newSongs: SongMetadata[] = []; + let extraMsg = ''; + + // Test if it's a complete URL + try { + const url = new URL(query); + + const YOUTUBE_HOSTS = [ + 'www.youtube.com', + 'youtu.be', + 'youtube.com', + 'music.youtube.com', + 'www.music.youtube.com', + ]; + + if (YOUTUBE_HOSTS.includes(url.host)) { + // YouTube source + if (url.searchParams.get('list')) { + // YouTube playlist + newSongs.push(...await this.youtubePlaylist(url.searchParams.get('list')!, shouldSplitChapters)); + } else { + const songs = await this.youtubeVideo(url.href, shouldSplitChapters); + + if (songs) { + newSongs.push(...songs); + } else { + throw new Error('that doesn\'t exist'); + } + } + } else if (url.protocol === 'spotify:' || url.host === 'open.spotify.com') { + if (this.spotifyAPI === undefined) { + throw new Error('Spotify is not enabled!') + } + + const [convertedSongs, nSongsNotFound, totalSongs] = await this.spotifySource(query, playlistLimit, shouldSplitChapters); + + if (totalSongs > playlistLimit) { + extraMsg = `a random sample of ${playlistLimit} songs was taken`; + } + + if (totalSongs > playlistLimit && nSongsNotFound !== 0) { + extraMsg += ' and '; + } + + if (nSongsNotFound !== 0) { + if (nSongsNotFound === 1) { + extraMsg += '1 song was not found'; + } else { + extraMsg += `${nSongsNotFound.toString()} songs were not found`; + } + } + + newSongs.push(...convertedSongs); + } else { + const song = await this.httpLiveStream(query); + + if (song) { + newSongs.push(song); + } else { + throw new Error('that doesn\'t exist'); + } + } + } catch (err: any) { + if (err = 'spotify not enabled') { + throw err; + } + + // Not a URL, must search YouTube + const songs = await this.youtubeVideoSearch(query, shouldSplitChapters); + + if (songs) { + newSongs.push(...songs); + } else { + throw new Error('that doesn\'t exist'); + } + } + + return [newSongs, extraMsg]; + } + + private async youtubeVideoSearch(query: string, shouldSplitChapters: boolean): Promise { return this.youtubeAPI.search(query, shouldSplitChapters); } - async youtubeVideo(url: string, shouldSplitChapters: boolean): Promise { + private async youtubeVideo(url: string, shouldSplitChapters: boolean): Promise { return this.youtubeAPI.getVideo(url, shouldSplitChapters); } - async youtubePlaylist(listId: string, shouldSplitChapters: boolean): Promise { + private async youtubePlaylist(listId: string, shouldSplitChapters: boolean): Promise { return this.youtubeAPI.getPlaylist(listId, shouldSplitChapters); } - async spotifySource(url: string, playlistLimit: number, shouldSplitChapters: boolean): Promise<[SongMetadata[], number, number]> { + private async spotifySource(url: string, playlistLimit: number, shouldSplitChapters: boolean): Promise<[SongMetadata[], number, number]> { + if (this.spotifyAPI === undefined) { + return [[], 0, 0]; + } + const parsed = spotifyURI.parse(url); switch (parsed.type) { @@ -58,7 +144,7 @@ export default class { } } - async httpLiveStream(url: string): Promise { + private async httpLiveStream(url: string): Promise { return new Promise((resolve, reject) => { ffmpeg(url).ffprobe((err, _) => { if (err) { diff --git a/src/services/youtube-api.ts b/src/services/youtube-api.ts index 143033ae..216a2c0c 100644 --- a/src/services/youtube-api.ts +++ b/src/services/youtube-api.ts @@ -95,7 +95,7 @@ export default class { } if (!firstVideo) { - throw new Error('No video found.'); + return []; } return this.getVideo(firstVideo.url, shouldSplitChapters); diff --git a/src/utils/get-youtube-and-spotify-suggestions-for.ts b/src/utils/get-youtube-and-spotify-suggestions-for.ts index 6594b526..c33cbeeb 100644 --- a/src/utils/get-youtube-and-spotify-suggestions-for.ts +++ b/src/utils/get-youtube-and-spotify-suggestions-for.ts @@ -14,28 +14,19 @@ const filterDuplicates = (items: T[]) => { return results; }; -const getYouTubeAndSpotifySuggestionsFor = async (query: string, spotify: SpotifyWebApi, limit = 10): Promise => { - const [youtubeSuggestions, spotifyResults] = await Promise.all([ - getYouTubeSuggestionsFor(query), - spotify.search(query, ['track', 'album'], {limit: 5}), - ]); +const getYouTubeAndSpotifySuggestionsFor = async (query: string, spotify?: SpotifyWebApi, limit = 10): Promise => { + + // Only search Spotify if enabled + let spotifySuggestionPromise = spotify !== undefined + ? spotify.search(query, ['album', 'track'], {limit}) + : undefined; + + const youtubeSuggestions = await getYouTubeSuggestionsFor(query); const totalYouTubeResults = youtubeSuggestions.length; + const numOfYouTubeSuggestions = Math.min(limit, totalYouTubeResults); - const spotifyAlbums = filterDuplicates(spotifyResults.body.albums?.items ?? []); - const spotifyTracks = filterDuplicates(spotifyResults.body.tracks?.items ?? []); - - const totalSpotifyResults = spotifyAlbums.length + spotifyTracks.length; - - // Number of results for each source should be roughly the same. - // If we don't have enough Spotify suggestions, prioritize YouTube results. - const maxSpotifySuggestions = Math.floor(limit / 2); - const numOfSpotifySuggestions = Math.min(maxSpotifySuggestions, totalSpotifyResults); - - const maxYouTubeSuggestions = limit - numOfSpotifySuggestions; - const numOfYouTubeSuggestions = Math.min(maxYouTubeSuggestions, totalYouTubeResults); - - const suggestions: APIApplicationCommandOptionChoice[] = []; + let suggestions: APIApplicationCommandOptionChoice[] = []; suggestions.push( ...youtubeSuggestions @@ -45,24 +36,45 @@ const getYouTubeAndSpotifySuggestionsFor = async (query: string, spotify: Spotif value: suggestion, }), )); + + + if (spotify !== undefined && spotifySuggestionPromise !== undefined) { + + const spotifyResponse = (await spotifySuggestionPromise).body + const spotifyAlbums = filterDuplicates(spotifyResponse.albums?.items ?? []); + const spotifyTracks = filterDuplicates(spotifyResponse.tracks?.items ?? []); + + const totalSpotifyResults = spotifyAlbums.length + spotifyTracks.length; + + // Number of results for each source should be roughly the same. + // If we don't have enough Spotify suggestions, prioritize YouTube results. + const maxSpotifySuggestions = Math.floor(limit / 2); + const numOfSpotifySuggestions = Math.min(maxSpotifySuggestions, totalSpotifyResults); + + + const maxSpotifyAlbums = Math.floor(numOfSpotifySuggestions / 2); + const numOfSpotifyAlbums = Math.min(maxSpotifyAlbums, spotifyResponse.albums?.items.length ?? 0); + const maxSpotifyTracks = numOfSpotifySuggestions - numOfSpotifyAlbums; + + // make room for spotify results + const maxYouTubeSuggestions = limit - numOfSpotifySuggestions; + suggestions = suggestions.slice(0, maxYouTubeSuggestions) + + suggestions.push( + ...spotifyAlbums.slice(0, maxSpotifyAlbums).map(album => ({ + name: `Spotify: 💿 ${album.name}${album.artists.length > 0 ? ` - ${album.artists[0].name}` : ''}`, + value: `spotify:album:${album.id}`, + })), + ); + + suggestions.push( + ...spotifyTracks.slice(0, maxSpotifyTracks).map(track => ({ + name: `Spotify: 🎵 ${track.name}${track.artists.length > 0 ? ` - ${track.artists[0].name}` : ''}`, + value: `spotify:track:${track.id}`, + })), + ); - const maxSpotifyAlbums = Math.floor(numOfSpotifySuggestions / 2); - const numOfSpotifyAlbums = Math.min(maxSpotifyAlbums, spotifyResults.body.albums?.items.length ?? 0); - const maxSpotifyTracks = numOfSpotifySuggestions - numOfSpotifyAlbums; - - suggestions.push( - ...spotifyAlbums.slice(0, maxSpotifyAlbums).map(album => ({ - name: `Spotify: 💿 ${album.name}${album.artists.length > 0 ? ` - ${album.artists[0].name}` : ''}`, - value: `spotify:album:${album.id}`, - })), - ); - - suggestions.push( - ...spotifyTracks.slice(0, maxSpotifyTracks).map(track => ({ - name: `Spotify: 🎵 ${track.name}${track.artists.length > 0 ? ` - ${track.artists[0].name}` : ''}`, - value: `spotify:track:${track.id}`, - })), - ); + } return suggestions; }; From 107464e22244e5f488212269f780675bc1494190 Mon Sep 17 00:00:00 2001 From: sofushn Date: Sat, 7 Sep 2024 21:49:10 +0200 Subject: [PATCH 2/6] chore: make linter parse --- src/services/get-songs.ts | 8 +++---- ...get-youtube-and-spotify-suggestions-for.ts | 23 ++++++++----------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/services/get-songs.ts b/src/services/get-songs.ts index dcaec0cd..c48d87dc 100644 --- a/src/services/get-songs.ts +++ b/src/services/get-songs.ts @@ -18,7 +18,7 @@ export default class { } async getSongs(query: string, playlistLimit: number, shouldSplitChapters: boolean): Promise<[SongMetadata[], string]> { - let newSongs: SongMetadata[] = []; + const newSongs: SongMetadata[] = []; let extraMsg = ''; // Test if it's a complete URL @@ -49,7 +49,7 @@ export default class { } } else if (url.protocol === 'spotify:' || url.host === 'open.spotify.com') { if (this.spotifyAPI === undefined) { - throw new Error('Spotify is not enabled!') + throw new Error('Spotify is not enabled!'); } const [convertedSongs, nSongsNotFound, totalSongs] = await this.spotifySource(query, playlistLimit, shouldSplitChapters); @@ -81,7 +81,7 @@ export default class { } } } catch (err: any) { - if (err = 'spotify not enabled') { + if (err instanceof Error && err.message === 'Spotify is not enabled!') { throw err; } @@ -112,7 +112,7 @@ export default class { private async spotifySource(url: string, playlistLimit: number, shouldSplitChapters: boolean): Promise<[SongMetadata[], number, number]> { if (this.spotifyAPI === undefined) { - return [[], 0, 0]; + return [[], 0, 0]; } const parsed = spotifyURI.parse(url); diff --git a/src/utils/get-youtube-and-spotify-suggestions-for.ts b/src/utils/get-youtube-and-spotify-suggestions-for.ts index c33cbeeb..bd6f1c87 100644 --- a/src/utils/get-youtube-and-spotify-suggestions-for.ts +++ b/src/utils/get-youtube-and-spotify-suggestions-for.ts @@ -15,12 +15,11 @@ const filterDuplicates = (items: T[]) => { }; const getYouTubeAndSpotifySuggestionsFor = async (query: string, spotify?: SpotifyWebApi, limit = 10): Promise => { - // Only search Spotify if enabled - let spotifySuggestionPromise = spotify !== undefined - ? spotify.search(query, ['album', 'track'], {limit}) - : undefined; - + const spotifySuggestionPromise = spotify === undefined + ? undefined + : spotify.search(query, ['album', 'track'], {limit}); + const youtubeSuggestions = await getYouTubeSuggestionsFor(query); const totalYouTubeResults = youtubeSuggestions.length; @@ -36,11 +35,9 @@ const getYouTubeAndSpotifySuggestionsFor = async (query: string, spotify?: Spoti value: suggestion, }), )); - - + if (spotify !== undefined && spotifySuggestionPromise !== undefined) { - - const spotifyResponse = (await spotifySuggestionPromise).body + const spotifyResponse = (await spotifySuggestionPromise).body; const spotifyAlbums = filterDuplicates(spotifyResponse.albums?.items ?? []); const spotifyTracks = filterDuplicates(spotifyResponse.tracks?.items ?? []); @@ -51,14 +48,13 @@ const getYouTubeAndSpotifySuggestionsFor = async (query: string, spotify?: Spoti const maxSpotifySuggestions = Math.floor(limit / 2); const numOfSpotifySuggestions = Math.min(maxSpotifySuggestions, totalSpotifyResults); - const maxSpotifyAlbums = Math.floor(numOfSpotifySuggestions / 2); const numOfSpotifyAlbums = Math.min(maxSpotifyAlbums, spotifyResponse.albums?.items.length ?? 0); const maxSpotifyTracks = numOfSpotifySuggestions - numOfSpotifyAlbums; - // make room for spotify results + // Make room for spotify results const maxYouTubeSuggestions = limit - numOfSpotifySuggestions; - suggestions = suggestions.slice(0, maxYouTubeSuggestions) + suggestions = suggestions.slice(0, maxYouTubeSuggestions); suggestions.push( ...spotifyAlbums.slice(0, maxSpotifyAlbums).map(album => ({ @@ -66,14 +62,13 @@ const getYouTubeAndSpotifySuggestionsFor = async (query: string, spotify?: Spoti value: `spotify:album:${album.id}`, })), ); - + suggestions.push( ...spotifyTracks.slice(0, maxSpotifyTracks).map(track => ({ name: `Spotify: 🎵 ${track.name}${track.artists.length > 0 ? ` - ${track.artists[0].name}` : ''}`, value: `spotify:track:${track.id}`, })), ); - } return suggestions; From 66e022489ff8caaf1d9dcdbd34c93fe702dfa024 Mon Sep 17 00:00:00 2001 From: sofushn Date: Mon, 28 Oct 2024 14:57:08 +0100 Subject: [PATCH 3/6] fix: Spotify URL is part of query description even when disabled --- src/commands/play.ts | 48 +++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/src/commands/play.ts b/src/commands/play.ts index 7851eb7c..c87ccd5a 100644 --- a/src/commands/play.ts +++ b/src/commands/play.ts @@ -1,6 +1,6 @@ import {AutocompleteInteraction, ChatInputCommandInteraction} from 'discord.js'; import {URL} from 'url'; -import {SlashCommandBuilder} from '@discordjs/builders'; +import {SlashCommandBuilder, SlashCommandSubcommandsOnlyBuilder} from '@discordjs/builders'; import {inject, injectable, optional} from 'inversify'; import Spotify from 'spotify-web-api-node'; import Command from './index.js'; @@ -13,26 +13,7 @@ import AddQueryToQueue from '../services/add-query-to-queue.js'; @injectable() export default class implements Command { - public readonly slashCommand = new SlashCommandBuilder() - .setName('play') - .setDescription('play a song') - .addStringOption(option => option - .setName('query') - .setDescription('YouTube URL, Spotify URL, or search query') - .setAutocomplete(true) - .setRequired(true)) - .addBooleanOption(option => option - .setName('immediate') - .setDescription('add track to the front of the queue')) - .addBooleanOption(option => option - .setName('shuffle') - .setDescription('shuffle the input if you\'re adding multiple tracks')) - .addBooleanOption(option => option - .setName('split') - .setDescription('if a track has chapters, split it')) - .addBooleanOption(option => option - .setName('skip') - .setDescription('skip the currently playing track')); + public readonly slashCommand: Partial & Pick; public requiresVC = true; @@ -44,6 +25,31 @@ export default class implements Command { this.spotify = thirdParty?.spotify; this.cache = cache; this.addQueryToQueue = addQueryToQueue; + + const queryDescription = thirdParty === undefined + ? 'YouTube URL or search query' + : 'YouTube URL, Spotify URL, or search query'; + + this.slashCommand = new SlashCommandBuilder() + .setName('play') + .setDescription('play a song') + .addStringOption(option => option + .setName('query') + .setDescription(queryDescription) + .setAutocomplete(true) + .setRequired(true)) + .addBooleanOption(option => option + .setName('immediate') + .setDescription('add track to the front of the queue')) + .addBooleanOption(option => option + .setName('shuffle') + .setDescription('shuffle the input if you\'re adding multiple tracks')) + .addBooleanOption(option => option + .setName('split') + .setDescription('if a track has chapters, split it')) + .addBooleanOption(option => option + .setName('skip') + .setDescription('skip the currently playing track')); } public async execute(interaction: ChatInputCommandInteraction): Promise { From 6a81754a2ec7a267a431923a6c542dce713a59c4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 29 Oct 2024 10:31:47 +0000 Subject: [PATCH 4/6] Bump p-limit from 4.0.0 to 6.1.0 Bumps [p-limit](https://github.com/sindresorhus/p-limit) from 4.0.0 to 6.1.0. - [Release notes](https://github.com/sindresorhus/p-limit/releases) - [Commits](https://github.com/sindresorhus/p-limit/compare/v4.0.0...v6.1.0) --- updated-dependencies: - dependency-name: p-limit dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- package.json | 2 +- yarn.lock | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 483b51e4..4ae71bde 100644 --- a/package.json +++ b/package.json @@ -113,7 +113,7 @@ "nodesplash": "^0.1.1", "ora": "^8.1.0", "p-event": "^5.0.1", - "p-limit": "^4.0.0", + "p-limit": "^6.1.0", "p-queue": "^7.2.0", "p-retry": "6.2.0", "pagination.djs": "^4.0.10", diff --git a/yarn.lock b/yarn.lock index 8a9cb994..33319a9d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3823,12 +3823,12 @@ p-limit@^3.0.2: dependencies: yocto-queue "^0.1.0" -p-limit@^4.0.0: - version "4.0.0" - resolved "https://registry.npmjs.org/p-limit/-/p-limit-4.0.0.tgz" - integrity sha512-5b0R4txpzjPWVw/cXXUResoD4hb6U/x9BH08L7nw+GN1sezDzPdxeRvpc9c433fZhBan/wusjbCsqwqm4EIBIQ== +p-limit@^6.1.0: + version "6.1.0" + resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-6.1.0.tgz#d91f9364d3fdff89b0a45c70d04ad4e0df30a0e8" + integrity sha512-H0jc0q1vOzlEk0TqAKXKZxdl7kX3OFUzCnNVUnq5Pc3DGo0kpeaMuPqxQn235HibwBEb0/pm9dgKTjXy66fBkg== dependencies: - yocto-queue "^1.0.0" + yocto-queue "^1.1.1" p-locate@^5.0.0: version "5.0.0" @@ -4972,7 +4972,7 @@ tslib@^2.6.2: version "2.8.0" resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.8.0.tgz#d124c86c3c05a40a91e6fdea4021bd31d377971b" integrity sha512-jWVzBLplnCmoaTr13V9dYbiQ99wvZRd0vNWaDRg+aVYRcjDF3nDksxFDE/+fkXnKhpnUUkmx5pK/v8mCtLVqZA== - + tsutils@^3.21.0: version "3.21.0" resolved "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz" @@ -5394,10 +5394,10 @@ yocto-queue@^0.1.0: resolved "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz" integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q== -yocto-queue@^1.0.0: - version "1.0.0" - resolved "https://registry.npmjs.org/yocto-queue/-/yocto-queue-1.0.0.tgz" - integrity sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g== +yocto-queue@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-1.1.1.tgz#fef65ce3ac9f8a32ceac5a634f74e17e5b232110" + integrity sha512-b4JR1PFR10y1mKjhHY9LaGo6tmrgjit7hxVIeAmyMw3jegXR4dhYqLaQF5zMXZxY7tLpMyJeLjr1C4rLmkVe8g== ytsr@^3.8.4: version "3.8.4" From 6ff7d4b9089f253c7a54f9fe8be1a1cb40ffdddd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 29 Oct 2024 10:32:14 +0000 Subject: [PATCH 5/6] Bump @types/ms from 0.7.31 to 0.7.34 Bumps [@types/ms](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/ms) from 0.7.31 to 0.7.34. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/ms) --- updated-dependencies: - dependency-name: "@types/ms" dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- package.json | 2 +- yarn.lock | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 483b51e4..d6e3d7d5 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "@types/debug": "^4.1.5", "@types/fluent-ffmpeg": "^2.1.17", "@types/fs-capacitor": "^2.0.0", - "@types/ms": "0.7.31", + "@types/ms": "0.7.34", "@types/node": "^17.0.0", "@types/node-emoji": "^1.8.1", "@types/spotify-web-api-node": "^5.0.2", diff --git a/yarn.lock b/yarn.lock index 8a9cb994..e97e2568 100644 --- a/yarn.lock +++ b/yarn.lock @@ -550,10 +550,10 @@ resolved "https://registry.npmjs.org/@types/libsodium-wrappers/-/libsodium-wrappers-0.7.9.tgz" integrity sha512-LisgKLlYQk19baQwjkBZZXdJL0KbeTpdEnrAfz5hQACbklCY0gVFnsKUyjfNWF1UQsCSjw93Sj5jSbiO8RPfdw== -"@types/ms@*", "@types/ms@0.7.31": - version "0.7.31" - resolved "https://registry.npmjs.org/@types/ms/-/ms-0.7.31.tgz" - integrity sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA== +"@types/ms@*", "@types/ms@0.7.34": + version "0.7.34" + resolved "https://registry.yarnpkg.com/@types/ms/-/ms-0.7.34.tgz#10964ba0dee6ac4cd462e2795b6bebd407303433" + integrity sha512-nG96G3Wp6acyAgJqGasjODb+acrI7KltPiRxzHPXnP3NgI28bpQDRv53olbqGXbfcgF5aiiHmO3xpwEpS5Ld9g== "@types/node-emoji@^1.8.1": version "1.8.1" @@ -4972,7 +4972,7 @@ tslib@^2.6.2: version "2.8.0" resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.8.0.tgz#d124c86c3c05a40a91e6fdea4021bd31d377971b" integrity sha512-jWVzBLplnCmoaTr13V9dYbiQ99wvZRd0vNWaDRg+aVYRcjDF3nDksxFDE/+fkXnKhpnUUkmx5pK/v8mCtLVqZA== - + tsutils@^3.21.0: version "3.21.0" resolved "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz" From 62aa39b6746b349333b1510cabf19d4ef7030de2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 29 Oct 2024 10:32:25 +0000 Subject: [PATCH 6/6] Bump iso8601-duration from 1.3.0 to 2.1.2 Bumps [iso8601-duration](https://github.com/tolu/ISO8601-duration) from 1.3.0 to 2.1.2. - [Release notes](https://github.com/tolu/ISO8601-duration/releases) - [Commits](https://github.com/tolu/ISO8601-duration/compare/v1.3.0...v2.1.2) --- updated-dependencies: - dependency-name: iso8601-duration dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- package.json | 2 +- yarn.lock | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 483b51e4..9b3d7ecb 100644 --- a/package.json +++ b/package.json @@ -106,7 +106,7 @@ "got": "^12.0.2", "hasha": "^5.2.2", "inversify": "^6.0.1", - "iso8601-duration": "^1.3.0", + "iso8601-duration": "^2.1.2", "libsodium-wrappers": "^0.7.9", "make-dir": "^3.1.0", "node-emoji": "^1.10.0", diff --git a/yarn.lock b/yarn.lock index 8a9cb994..5bc9c795 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3149,10 +3149,10 @@ isexe@^2.0.0: resolved "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz" integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA= -iso8601-duration@^1.3.0: - version "1.3.0" - resolved "https://registry.npmjs.org/iso8601-duration/-/iso8601-duration-1.3.0.tgz" - integrity sha512-K4CiUBzo3YeWk76FuET/dQPH03WE04R94feo5TSKQCXpoXQt9E4yx2CnY737QZnSAI3PI4WlKo/zfqizGx52QQ== +iso8601-duration@^2.1.2: + version "2.1.2" + resolved "https://registry.yarnpkg.com/iso8601-duration/-/iso8601-duration-2.1.2.tgz#b13f14068fe5890c91b91e1f74e474a49f355028" + integrity sha512-yXteYUiKv6x8seaDzyBwnZtPpmx766KfvQuaVNyPifYOjmPdOo3ajd4phDNa7Y5mTQGnXsNEcXFtVun1FjYXxQ== iterate-iterator@^1.0.1: version "1.0.2" @@ -4972,7 +4972,7 @@ tslib@^2.6.2: version "2.8.0" resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.8.0.tgz#d124c86c3c05a40a91e6fdea4021bd31d377971b" integrity sha512-jWVzBLplnCmoaTr13V9dYbiQ99wvZRd0vNWaDRg+aVYRcjDF3nDksxFDE/+fkXnKhpnUUkmx5pK/v8mCtLVqZA== - + tsutils@^3.21.0: version "3.21.0" resolved "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz"