Skip to content

Commit

Permalink
changed spelling for sponsor block events
Browse files Browse the repository at this point in the history
  • Loading branch information
SxMAbel committed Sep 29, 2024
1 parent 91d3319 commit f6efa1f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "magmastream",
"version": "2.6.0-beta.1",
"version": "2.6.0-beta.2",
"description": "A user-friendly Lavalink client designed for NodeJS.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
8 changes: 4 additions & 4 deletions src/structures/Manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,8 @@ export interface ManagerEvents {
trackEnd: [player: Player, track: Track, payload: TrackEndEvent];
trackStuck: [player: Player, track: Track, payload: TrackStuckEvent];
trackError: [player: Player, track: Track | UnresolvedTrack, payload: TrackExceptionEvent];
SegmentsLoaded: [player: Player, track: Track | UnresolvedTrack, payload: SponsorBlockSegmentsLoaded];
SegmentSkipped: [player: Player, track: Track | UnresolvedTrack, payload: SponsorBlockSegmentSkipped];
ChapterStarted: [player: Player, track: Track | UnresolvedTrack, payload: SponsorBlockChapterStarted];
ChaptersLoaded: [player: Player, track: Track | UnresolvedTrack, payload: SponsorBlockChaptersLoaded];
segmentsLoaded: [player: Player, track: Track | UnresolvedTrack, payload: SponsorBlockSegmentsLoaded];
segmentSkipped: [player: Player, track: Track | UnresolvedTrack, payload: SponsorBlockSegmentSkipped];
chapterStarted: [player: Player, track: Track | UnresolvedTrack, payload: SponsorBlockChapterStarted];
chaptersLoaded: [player: Player, track: Track | UnresolvedTrack, payload: SponsorBlockChaptersLoaded];
}
32 changes: 20 additions & 12 deletions src/structures/Node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,16 @@ export class Node {
break;

case "SegmentsLoaded":
this.SponsorBlockSegmentLoaded(player, player.queue.current as Track, payload);
this.sponsorBlockSegmentLoaded(player, player.queue.current as Track, payload);
break;
case "SegmentSkipped":
this.SponsorBlockSegmentSkipped(player, player.queue.current as Track, payload);
this.sponsorBlockSegmentSkipped(player, player.queue.current as Track, payload);
break;
case "ChaptersLoaded":
this.SponsorBlockChaptersLoaded(player, player.queue.current as Track, payload);
this.sponsorBlockChaptersLoaded(player, player.queue.current as Track, payload);
break;
case "ChapterStarted":
this.SponsorBlockChapterStarted(player, player.queue.current as Track, payload);
this.sponsorBlockChapterStarted(player, player.queue.current as Track, payload);
break;

default:
Expand Down Expand Up @@ -328,13 +328,16 @@ export class Node {
if (!player.isAutoplay || !previousTrack) return;

const hasSpotifyURL = ["spotify.com", "open.spotify.com"].some((url) => previousTrack.uri.includes(url));

if (hasSpotifyURL) {
const spotifySuccess = await this.handleSpotifyAutoplay(player); // Check if Spotify autoplay was successful

if (spotifySuccess) return; // If successful, exit the function
}

const hasYouTubeURL = ["youtube.com", "youtu.be"].some((url) => previousTrack.uri.includes(url));
let videoID = previousTrack.uri.substring(previousTrack.uri.indexOf("=") + 1);

if (!hasYouTubeURL) {
const res = await player.search(`${previousTrack.author} - ${previousTrack.title}`, player.get("Internal_BotUser"));
videoID = res.tracks[0].uri.substring(res.tracks[0].uri.indexOf("=") + 1);
Expand All @@ -349,18 +352,23 @@ export class Node {
} while (track.uri.includes(searchURI));

const res = await player.search(searchURI, player.get("Internal_BotUser"));

if (res.loadType === "empty" || res.loadType === "error") return;

let tracks = res.tracks;

if (res.loadType === "playlist") tracks = res.playlist.tracks;

const foundTrack = tracks.sort(() => Math.random() - 0.5).find((shuffledTrack) => shuffledTrack.uri !== track.uri);

if (!foundTrack) return;
if (this.manager.options.replaceYouTubeCredentials) {
foundTrack.author = foundTrack.author.replace("- Topic", "");
foundTrack.title = foundTrack.title.replace("Topic -", "");

if (foundTrack.title.includes("-")) {
const [author, title] = foundTrack.title.split("-").map((str: string) => str.trim());

foundTrack.author = author;
foundTrack.title = title;
}
Expand Down Expand Up @@ -480,20 +488,20 @@ export class Node {
this.manager.emit("socketClosed", player, payload);
}

private SponsorBlockSegmentLoaded(player: Player, track: Track, payload: SponsorBlockSegmentsLoaded) {
return this.manager.emit("SegmentsLoaded", player, track, payload);
private sponsorBlockSegmentLoaded(player: Player, track: Track, payload: SponsorBlockSegmentsLoaded) {
return this.manager.emit("segmentsLoaded", player, track, payload);
}

private SponsorBlockSegmentSkipped(player: Player, track: Track, payload: SponsorBlockSegmentSkipped) {
return this.manager.emit("SegmentSkipped", player, track, payload);
private sponsorBlockSegmentSkipped(player: Player, track: Track, payload: SponsorBlockSegmentSkipped) {
return this.manager.emit("segmentSkipped", player, track, payload);
}

private SponsorBlockChaptersLoaded(player: Player, track: Track, payload: SponsorBlockChaptersLoaded) {
return this.manager.emit("ChaptersLoaded", player, track, payload);
private sponsorBlockChaptersLoaded(player: Player, track: Track, payload: SponsorBlockChaptersLoaded) {
return this.manager.emit("chaptersLoaded", player, track, payload);
}

private SponsorBlockChapterStarted(player: Player, track: Track, payload: SponsorBlockChapterStarted) {
return this.manager.emit("ChapterStarted", player, track, payload);
private sponsorBlockChapterStarted(player: Player, track: Track, payload: SponsorBlockChapterStarted) {
return this.manager.emit("chapterStarted", player, track, payload);
}
public async fetchInfo() {
return (await this.rest.get(`/v4/info`)) as LavalinkInfo;
Expand Down

0 comments on commit f6efa1f

Please sign in to comment.