Skip to content

Commit 027cea7

Browse files
authored
Added checks, more jsdoc and samples
1 parent 36d5028 commit 027cea7

File tree

5 files changed

+86
-11
lines changed

5 files changed

+86
-11
lines changed

src/structures/LavalinkManagerStatics.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ export const LavalinkPlugins = {
8181
GoogleCloudTTS: "tts-plugin",
8282
LavaSearch: "lavasearch-plugin",
8383
Jiosaavn_Plugin: "jiosaavn-plugin",
84-
LavalinkFilterPlugin: "lavalink-filter-plugin"
84+
LavalinkFilterPlugin: "lavalink-filter-plugin",
85+
JavaTimedLyricsPlugin: "java-lyrics-plugin"
8586
}
8687

8788
/** Lavalink Sources regexes for url validations */
@@ -126,6 +127,9 @@ export const SourceLinksRegexes: Record<SourcesRegex, RegExp> = {
126127

127128
appleMusic: /https?:\/\/?(?:www\.)?music\.apple\.com\/(\S+)/,
128129

130+
/** From jiosaavn-plugin */
131+
jiosaavn: /(https?:\/\/)(www\.)?jiosaavn\.com\/(?<type>song|album|featured|artist)\/([a-zA-Z0-9-_\/,]+)/,
132+
129133
/** FROM DUNCTE BOT PLUGIN */
130134
tiktok: /https:\/\/www\.tiktok\.com\//,
131135
mixcloud: /https:\/\/www\.mixcloud\.com\//,

src/structures/Node.ts

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -647,17 +647,26 @@ export class LavalinkNode {
647647
*
648648
* ```ts
649649
* const lyrics = await player.node.lyrics.get(track, true);
650+
* // use it of player instead:
651+
* // const lyrics = await player.getLyrics(track, true);
650652
* ```
651653
*/
652-
//Get lyrics for a track
653654
get: async (track: Track, skipTrackSource: boolean = false) => {
654655
if (!this.sessionId) throw new Error("the Lavalink-Node is either not ready, or not up to date!");
656+
657+
if(
658+
!this.info.plugins.find(v => v.name === "lavalyrics-plugin")
659+
) throw new RangeError(`there is no lavalyrics-plugin available in the lavalink node (required for lyrics): ${this.id}`);
660+
661+
if(
662+
!this.info.plugins.find(v => v.name === "lavasrc-plugin") &&
663+
!this.info.plugins.find(v => v.name === "java-lyrics-plugin")
664+
) throw new RangeError(`there is no lyrics source (via lavasrc-plugin / java-lyrics-plugin) available in the lavalink node (required for lyrics): ${this.id}`);
665+
655666
const url = `/lyrics?track=${track.encoded}&skipTrackSource=${skipTrackSource}`;
656667
return (await this.request(url)) as LyricsResult | null;
657668
},
658669

659-
//Get current playing track lyrics
660-
661670
/**
662671
* Get the lyrics of the current playing track
663672
*
@@ -666,11 +675,23 @@ export class LavalinkNode {
666675
* @returns the lyrics of the current playing track
667676
* @example
668677
* ```ts
669-
* const lyrics = await player.node.lyrics.getCurrentTrack(guildId);
678+
* const lyrics = await player.node.lyrics.getCurrent(guildId);
679+
* // use it of player instead:
680+
* // const lyrics = await player.getCurrentLyrics();
670681
* ```
671682
*/
672-
getCurrentTrack: async (guildId: string, skipTrackSource: boolean = false) => {
683+
getCurrent: async (guildId: string, skipTrackSource: boolean = false) => {
673684
if (!this.sessionId) throw new Error("the Lavalink-Node is either not ready, or not up to date!");
685+
686+
if(
687+
!this.info.plugins.find(v => v.name === "lavalyrics-plugin")
688+
) throw new RangeError(`there is no lavalyrics-plugin available in the lavalink node (required for lyrics): ${this.id}`);
689+
690+
if(
691+
!this.info.plugins.find(v => v.name === "lavasrc-plugin") &&
692+
!this.info.plugins.find(v => v.name === "java-lyrics-plugin")
693+
) throw new RangeError(`there is no lyrics source (via lavasrc-plugin / java-lyrics-plugin) available in the lavalink node (required for lyrics): ${this.id}`);
694+
674695
const url = `/sessions/${this.sessionId}/players/${guildId}/track/lyrics?skipTrackSource=${skipTrackSource}`;
675696
return (await this.request(url)) as LyricsResult | null;
676697
},
@@ -683,11 +704,23 @@ export class LavalinkNode {
683704
* @example
684705
* ```ts
685706
* await player.node.lyrics.subscribe(guildId);
707+
* // use it of player instead:
708+
* // const lyrics = await player.subscribeLyrics();
686709
* ```
687710
*/
688711

689712
subscribe: async (guildId: string) => {
690713
if (!this.sessionId) throw new Error("the Lavalink-Node is either not ready, or not up to date!");
714+
715+
if(
716+
!this.info.plugins.find(v => v.name === "lavalyrics-plugin")
717+
) throw new RangeError(`there is no lavalyrics-plugin available in the lavalink node (required for lyrics): ${this.id}`);
718+
719+
if(
720+
!this.info.plugins.find(v => v.name === "lavasrc-plugin") &&
721+
!this.info.plugins.find(v => v.name === "java-lyrics-plugin")
722+
) throw new RangeError(`there is no lyrics source (via lavasrc-plugin / java-lyrics-plugin) available in the lavalink node (required for lyrics): ${this.id}`);
723+
691724
return await this.request(`/sessions/${this.sessionId}/players/${guildId}/lyrics/subscribe`, (options) => {
692725
options.method = "POST";
693726
}).catch(() => { });
@@ -700,10 +733,22 @@ export class LavalinkNode {
700733
* @example
701734
* ```ts
702735
* await player.node.lyrics.unsubscribe(guildId);
736+
* // use it of player instead:
737+
* // const lyrics = await player.unsubscribeLyrics();
703738
* ```
704739
*/
705740
unsubscribe: async (guildId: string) => {
706741
if (!this.sessionId) throw new Error("the Lavalink-Node is either not ready, or not up to date!");
742+
743+
if(
744+
!this.info.plugins.find(v => v.name === "lavalyrics-plugin")
745+
) throw new RangeError(`there is no lavalyrics-plugin available in the lavalink node (required for lyrics): ${this.id}`);
746+
747+
if(
748+
!this.info.plugins.find(v => v.name === "lavasrc-plugin") &&
749+
!this.info.plugins.find(v => v.name === "java-lyrics-plugin")
750+
) throw new RangeError(`there is no lyrics source (via lavasrc-plugin / java-lyrics-plugin) available in the lavalink node (required for lyrics): ${this.id}`);
751+
707752
return await this.request(`/sessions/${this.sessionId}/players/${guildId}/lyrics/unsubscribe`, (options) => {
708753
options.method = "DELETE";
709754
}).catch(() => { });

src/structures/Player.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -641,16 +641,24 @@ export class Player {
641641
* @param guildId The guild id to get the current lyrics for
642642
* @param skipTrackSource If true, it will not try to get the lyrics from the track source
643643
* @returns The current lyrics
644+
* @example
645+
* ```ts
646+
* const lyrics = await player.getCurrentLyrics();
647+
* ```
644648
*/
645-
public async getCurrentLyrics(guildId: string, skipTrackSource?: boolean) {
646-
return await this.node.lyrics.getCurrentTrack(guildId, skipTrackSource);
649+
public async getCurrentLyrics(skipTrackSource?: boolean) {
650+
return await this.node.lyrics.getCurrent(this.guildId, skipTrackSource);
647651
}
648652

649653
/**
650654
* Get the lyrics of a specific track
651655
* @param track The track to get the lyrics for
652656
* @param skipTrackSource If true, it will not try to get the lyrics from the track source
653657
* @returns The lyrics of the track
658+
* @example
659+
* ```ts
660+
* const lyrics = await player.getLyrics(player.queue.tracks[0], true);
661+
* ```
654662
*/
655663
public async getLyrics(track: Track, skipTrackSource?: boolean) {
656664
return await this.node.lyrics.get(track, skipTrackSource);
@@ -660,17 +668,25 @@ export class Player {
660668
* Subscribe to the lyrics event on a specific guild to active live lyrics events
661669
* @param guildId The guild id to subscribe to
662670
* @returns The unsubscribe function
671+
* @example
672+
* ```ts
673+
* const lyrics = await player.subscribeLyrics();
674+
* ```
663675
*/
664-
public subscribe(guildId: string) {
665-
return this.node.lyrics.subscribe(guildId);
676+
public subscribeLyrics() {
677+
return this.node.lyrics.subscribe(this.guildId);
666678
}
667679

668680
/**
669681
* Unsubscribe from the lyrics event on a specific guild to disable live lyrics events
670682
* @param guildId The guild id to unsubscribe from
671683
* @returns The unsubscribe function
684+
* @example
685+
* ```ts
686+
* const lyrics = await player.unsubscribeLyrics();
687+
* ```
672688
*/
673-
public unsubscribe(guildId: string) {
689+
public unsubscribeLyrics(guildId: string) {
674690
return this.node.lyrics.unsubscribe(guildId);
675691
}
676692

src/structures/Types/Utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export type SourcesRegex = "YoutubeRegex" |
9191
"musicYandex" |
9292
"radiohost" |
9393
"bandcamp" |
94+
"jiosaavn" |
9495
"appleMusic" |
9596
"TwitchTv" |
9697
"vimeo";

src/structures/Utils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ export class ManagerUtils {
309309
if (SourceLinksRegexes.musicYandex.test(queryString) && !node.info?.sourceManagers?.includes("yandexmusic")) {
310310
throw new Error("Query / Link Provided for this Source but Lavalink Node has not 'yandexmusic' enabled");
311311
}
312+
if(SourceLinksRegexes.jiosaavn.test(queryString) && !node.info?.sourceManagers?.includes("jiosaavn")) {
313+
throw new Error("Query / Link Provided for this Source but Lavalink Node has not 'jiosaavn' (via jiosaavn-plugin) enabled");
314+
}
312315
return;
313316
}
314317

@@ -367,6 +370,12 @@ export class ManagerUtils {
367370
if (source === "dzsearch" && node.info?.sourceManagers?.includes("deezer") && !node.info?.sourceManagers?.includes("http")) {
368371
throw new Error("Lavalink Node has not 'http' enabled, which is required to have 'dzsearch' to work");
369372
}
373+
if(source === "jsrec" && !node.info?.sourceManagers?.includes("jiosaavn")) {
374+
throw new Error("Lavalink Node has not 'jiosaavn' (via jiosaavn-plugin) enabled, which is required to have 'jsrec' to work");
375+
}
376+
if(source === "jssearch" && !node.info?.sourceManagers?.includes("jiosaavn")) {
377+
throw new Error("Lavalink Node has not 'jiosaavn' (via jiosaavn-plugin) enabled, which is required to have 'jssearch' to work");
378+
}
370379
if (source === "scsearch" && !node.info?.sourceManagers?.includes("soundcloud")) {
371380
throw new Error("Lavalink Node has not 'soundcloud' enabled, which is required to have 'scsearch' work");
372381
}

0 commit comments

Comments
 (0)