magmastream 2.5.16 → 2.6.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -278,6 +278,19 @@ declare class Player {
278
278
  * @param volume
279
279
  */
280
280
  setVolume(volume: number): this;
281
+ /**
282
+ * Sets the sponsorblock for the player.
283
+ * @param segments
284
+ */
285
+ setSponsorBlock(segments?: SponsorBlockSegment[]): Promise<void>;
286
+ /**
287
+ * Gets the sponsorblock for the player.
288
+ */
289
+ getSponsorBlock(): Promise<SponsorBlockSegment[]>;
290
+ /**
291
+ * Deletes the sponsorblock for the player.
292
+ */
293
+ deleteSponsorBlock(): Promise<void>;
281
294
  /**
282
295
  * Sets the track repeat.
283
296
  * @param repeat
@@ -422,6 +435,7 @@ declare class Rest {
422
435
  get(endpoint: string): Promise<unknown>;
423
436
  patch(endpoint: string, body: unknown): Promise<unknown>;
424
437
  post(endpoint: string, body: unknown): Promise<unknown>;
438
+ put(endpoint: string, body: unknown): Promise<unknown>;
425
439
  delete(endpoint: string): Promise<unknown>;
426
440
  }
427
441
  interface playOptions {
@@ -454,6 +468,8 @@ interface playOptions {
454
468
  };
455
469
  }
456
470
 
471
+ declare const validSponsorBlocks: string[];
472
+ type SponsorBlockSegment = "sponsor" | "selfpromo" | "interaction" | "intro" | "outro" | "preview" | "music_offtopic" | "filler";
457
473
  declare class Node {
458
474
  options: NodeOptions;
459
475
  /** The socket for the node. */
@@ -468,7 +484,8 @@ declare class Node {
468
484
  private static _manager;
469
485
  private reconnectTimeout?;
470
486
  private reconnectAttempts;
471
- info: LavalinkInfo;
487
+ /** Actual Lavalink information of the node. */
488
+ info: LavalinkInfo | null;
472
489
  /** Returns if connected to the Node. */
473
490
  get connected(): boolean;
474
491
  /** Returns the address for this node. */
@@ -503,6 +520,36 @@ declare class Node {
503
520
  protected trackStuck(player: Player, track: Track, payload: TrackStuckEvent): void;
504
521
  protected trackError(player: Player, track: Track | UnresolvedTrack, payload: TrackExceptionEvent): void;
505
522
  protected socketClosed(player: Player, payload: WebSocketClosedEvent): void;
523
+ private SponsorBlockSegmentLoaded;
524
+ private SponsorBlockSegmentSkipped;
525
+ private SponsorBlockChaptersLoaded;
526
+ private SponsorBlockChapterStarted;
527
+ fetchInfo(): Promise<LavalinkInfo>;
528
+ getSponsorBlock(player: Player): Promise<SponsorBlockSegment[]>;
529
+ /**
530
+ * Set the current sponsorblocks for the sponsorblock plugin
531
+ * @param player passthrough the player
532
+ * @returns void
533
+ *
534
+ * @example
535
+ * ```ts
536
+ * // use it on the player via player.setSponsorBlock();
537
+ * const sponsorBlockSegments = await player.node.setSponsorBlock(player, ["sponsor", "selfpromo"]);
538
+ * ```
539
+ */
540
+ setSponsorBlock(player: Player, segments?: SponsorBlockSegment[]): Promise<void>;
541
+ /**
542
+ * Delete the sponsorblock plugins
543
+ * @param player passthrough the player
544
+ * @returns void
545
+ *
546
+ * @example
547
+ * ```ts
548
+ * // use it on the player via player.deleteSponsorBlock();
549
+ * const sponsorBlockSegments = await player.node.deleteSponsorBlock(player);
550
+ * ```
551
+ */
552
+ deleteSponsorBlock(player: Player): Promise<void>;
506
553
  }
507
554
  interface NodeOptions {
508
555
  /** The host for the node. */
@@ -656,8 +703,10 @@ interface UnresolvedQuery {
656
703
  type Sizes = "0" | "1" | "2" | "3" | "default" | "mqdefault" | "hqdefault" | "maxresdefault";
657
704
  type LoadType = "track" | "playlist" | "search" | "empty" | "error";
658
705
  type State = "CONNECTED" | "CONNECTING" | "DISCONNECTED" | "DISCONNECTING" | "DESTROYING";
659
- type PlayerEvents = TrackStartEvent | TrackEndEvent | TrackStuckEvent | TrackExceptionEvent | WebSocketClosedEvent;
660
- type PlayerEventType = "TrackStartEvent" | "TrackEndEvent" | "TrackExceptionEvent" | "TrackStuckEvent" | "WebSocketClosedEvent";
706
+ type SponsorBlockSegmentEvents = SponsorBlockSegmentSkipped | SponsorBlockSegmentsLoaded | SponsorBlockChapterStarted | SponsorBlockChaptersLoaded;
707
+ type SponsorBlockSegmentEventType = "SegmentSkipped" | "SegmentsLoaded" | "ChapterStarted" | "ChaptersLoaded";
708
+ type PlayerEvents = TrackStartEvent | TrackEndEvent | TrackStuckEvent | TrackExceptionEvent | WebSocketClosedEvent | SponsorBlockSegmentEvents;
709
+ type PlayerEventType = "TrackStartEvent" | "TrackEndEvent" | "TrackExceptionEvent" | "TrackStuckEvent" | "WebSocketClosedEvent" | "SegmentSkipped" | "SegmentsLoaded" | "ChaptersLoaded" | "ChapterStarted";
661
710
  type TrackEndReason = "finished" | "loadFailed" | "stopped" | "replaced" | "cleanup";
662
711
  type Severity = "common" | "suspicious" | "fault";
663
712
  interface TrackData {
@@ -746,6 +795,44 @@ interface WebSocketClosedEvent extends PlayerEvent {
746
795
  reason: string;
747
796
  byRemote: boolean;
748
797
  }
798
+ interface SponsorBlockSegmentsLoaded extends PlayerEvent {
799
+ type: "SegmentsLoaded";
800
+ segments: {
801
+ category: string;
802
+ start: number;
803
+ end: number;
804
+ }[];
805
+ }
806
+ interface SponsorBlockSegmentSkipped extends PlayerEvent {
807
+ type: "SegmentSkipped";
808
+ segment: {
809
+ category: string;
810
+ start: number;
811
+ end: number;
812
+ };
813
+ }
814
+ interface SponsorBlockChapterStarted extends PlayerEvent {
815
+ type: "ChapterStarted";
816
+ /** The chapter which started */
817
+ chapter: {
818
+ /** The name of the chapter */
819
+ name: string;
820
+ start: number;
821
+ end: number;
822
+ duration: number;
823
+ };
824
+ }
825
+ interface SponsorBlockChaptersLoaded extends PlayerEvent {
826
+ type: "ChaptersLoaded";
827
+ /** All chapters loaded */
828
+ chapters: {
829
+ /** The name of the chapter */
830
+ name: string;
831
+ start: number;
832
+ end: number;
833
+ duration: number;
834
+ }[];
835
+ }
749
836
  interface PlayerUpdate {
750
837
  op: "playerUpdate";
751
838
  /** The guild id of the player. */
@@ -865,8 +952,6 @@ interface ManagerOptions {
865
952
  clientId?: string;
866
953
  /** Value to use for the `Client-Name` header. */
867
954
  clientName?: string;
868
- /** The shard count. */
869
- shards?: number;
870
955
  /** A array of plugins to use. */
871
956
  plugins?: Plugin[];
872
957
  /** Whether players should automatically play the next song. */
@@ -943,6 +1028,10 @@ interface ManagerEvents {
943
1028
  trackEnd: [player: Player, track: Track, payload: TrackEndEvent];
944
1029
  trackStuck: [player: Player, track: Track, payload: TrackStuckEvent];
945
1030
  trackError: [player: Player, track: Track | UnresolvedTrack, payload: TrackExceptionEvent];
1031
+ SegmentsLoaded: [player: Player, track: Track | UnresolvedTrack, payload: SponsorBlockSegmentsLoaded];
1032
+ SegmentSkipped: [player: Player, track: Track | UnresolvedTrack, payload: SponsorBlockSegmentSkipped];
1033
+ ChapterStarted: [player: Player, track: Track | UnresolvedTrack, payload: SponsorBlockChapterStarted];
1034
+ ChaptersLoaded: [player: Player, track: Track | UnresolvedTrack, payload: SponsorBlockChaptersLoaded];
946
1035
  }
947
1036
 
948
- export { type CPUStats, type EqualizerBand, type Exception, type Extendable, type FrameStats, type LavalinkInfo, type LavalinkResponse, type LoadType, Manager, type ManagerEvents, type ManagerOptions, type MemoryStats, Node, type NodeMessage, type NodeOptions, type NodeStats, type Payload, type PlayOptions, Player, type PlayerEvent, type PlayerEventType, type PlayerEvents, type PlayerOptions, type PlayerUpdate, type PlaylistData, type PlaylistRawData, Plugin, Queue, type SearchPlatform, type SearchQuery, type SearchResult, type Severity, type Sizes, type State, Structure, type Track, type TrackData, type TrackDataInfo, type TrackEndEvent, type TrackEndReason, type TrackExceptionEvent, type TrackPluginInfo, type TrackSourceName, type TrackStartEvent, type TrackStuckEvent, TrackUtils, type UnresolvedQuery, type UnresolvedTrack, type VoicePacket, type VoiceServer, type VoiceState, type WebSocketClosedEvent };
1037
+ export { type CPUStats, type EqualizerBand, type Exception, type Extendable, type FrameStats, type LavalinkInfo, type LavalinkResponse, type LoadType, Manager, type ManagerEvents, type ManagerOptions, type MemoryStats, Node, type NodeMessage, type NodeOptions, type NodeStats, type Payload, type PlayOptions, Player, type PlayerEvent, type PlayerEventType, type PlayerEvents, type PlayerOptions, type PlayerUpdate, type PlaylistData, type PlaylistRawData, Plugin, Queue, type SearchPlatform, type SearchQuery, type SearchResult, type Severity, type Sizes, type SponsorBlockChapterStarted, type SponsorBlockChaptersLoaded, type SponsorBlockSegment, type SponsorBlockSegmentEventType, type SponsorBlockSegmentEvents, type SponsorBlockSegmentSkipped, type SponsorBlockSegmentsLoaded, type State, Structure, type Track, type TrackData, type TrackDataInfo, type TrackEndEvent, type TrackEndReason, type TrackExceptionEvent, type TrackPluginInfo, type TrackSourceName, type TrackStartEvent, type TrackStuckEvent, TrackUtils, type UnresolvedQuery, type UnresolvedTrack, type VoicePacket, type VoiceServer, type VoiceState, type WebSocketClosedEvent, validSponsorBlocks };
@@ -93,7 +93,6 @@ class Manager extends events_1.EventEmitter {
93
93
  resumeTimeout: 1000,
94
94
  },
95
95
  ],
96
- shards: 1,
97
96
  autoPlay: true,
98
97
  usePriority: false,
99
98
  clientName: "Magmastream",
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Node = void 0;
3
+ exports.Node = exports.validSponsorBlocks = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const Utils_1 = require("./Utils");
6
6
  const Rest_1 = require("./Rest");
7
7
  const nodeCheck_1 = tslib_1.__importDefault(require("../utils/nodeCheck"));
8
8
  const ws_1 = tslib_1.__importDefault(require("ws"));
9
+ exports.validSponsorBlocks = ["sponsor", "selfpromo", "interaction", "intro", "outro", "preview", "music_offtopic", "filler"];
9
10
  class Node {
10
11
  options;
11
12
  /** The socket for the node. */
@@ -20,6 +21,7 @@ class Node {
20
21
  static _manager;
21
22
  reconnectTimeout;
22
23
  reconnectAttempts = 1;
24
+ /** Actual Lavalink information of the node. */
23
25
  info = null;
24
26
  /** Returns if connected to the Node. */
25
27
  get connected() {
@@ -91,12 +93,14 @@ class Node {
91
93
  connect() {
92
94
  if (this.connected)
93
95
  return;
94
- const headers = Object.assign({
96
+ const headers = {
95
97
  Authorization: this.options.password,
96
- "Num-Shards": String(this.manager.options.shards),
97
98
  "User-Id": this.manager.options.clientId,
98
99
  "Client-Name": this.manager.options.clientName,
99
- });
100
+ };
101
+ if (this.sessionId) {
102
+ headers["Session-Id"] = this.sessionId;
103
+ }
100
104
  this.socket = new ws_1.default(`ws${this.options.secure ? "s" : ""}://${this.address}/v4/websocket`, { headers });
101
105
  this.socket.on("open", this.open.bind(this));
102
106
  this.socket.on("close", this.close.bind(this));
@@ -173,7 +177,7 @@ class Node {
173
177
  case "ready":
174
178
  this.rest.setSessionId(payload.sessionId);
175
179
  this.sessionId = payload.sessionId;
176
- this.info = await this.rest.get("/v4/info");
180
+ this.info = await this.fetchInfo();
177
181
  if (this.options.resumeStatus) {
178
182
  this.rest.patch(`/v4/sessions/${this.sessionId}`, {
179
183
  resuming: this.options.resumeStatus,
@@ -214,6 +218,18 @@ class Node {
214
218
  case "WebSocketClosedEvent":
215
219
  this.socketClosed(player, payload);
216
220
  break;
221
+ case "SegmentsLoaded":
222
+ this.SponsorBlockSegmentLoaded(player, player.queue.current, payload);
223
+ break;
224
+ case "SegmentSkipped":
225
+ this.SponsorBlockSegmentSkipped(player, player.queue.current, payload);
226
+ break;
227
+ case "ChaptersLoaded":
228
+ this.SponsorBlockChaptersLoaded(player, player.queue.current, payload);
229
+ break;
230
+ case "ChapterStarted":
231
+ this.SponsorBlockChapterStarted(player, player.queue.current, payload);
232
+ break;
217
233
  default:
218
234
  error = new Error(`Node#event unknown event '${type}'.`);
219
235
  this.manager.emit("nodeError", this, error);
@@ -394,5 +410,63 @@ class Node {
394
410
  socketClosed(player, payload) {
395
411
  this.manager.emit("socketClosed", player, payload);
396
412
  }
413
+ SponsorBlockSegmentLoaded(player, track, payload) {
414
+ return this.manager.emit("SegmentsLoaded", player, track, payload);
415
+ }
416
+ SponsorBlockSegmentSkipped(player, track, payload) {
417
+ return this.manager.emit("SegmentSkipped", player, track, payload);
418
+ }
419
+ SponsorBlockChaptersLoaded(player, track, payload) {
420
+ return this.manager.emit("ChaptersLoaded", player, track, payload);
421
+ }
422
+ SponsorBlockChapterStarted(player, track, payload) {
423
+ return this.manager.emit("ChapterStarted", player, track, payload);
424
+ }
425
+ async fetchInfo() {
426
+ return (await this.rest.get(`/v4/info`));
427
+ }
428
+ async getSponsorBlock(player) {
429
+ if (!this.info.plugins.some((plugin) => plugin.name === "sponsorblock-plugin"))
430
+ throw new RangeError(`there is no sponsorblock-plugin available in the lavalink node: ${this.options.identifier}`);
431
+ return (await this.rest.get(`/v4/sessions/${this.sessionId}/players/${player.guild}/sponsorblock/categories`));
432
+ }
433
+ /**
434
+ * Set the current sponsorblocks for the sponsorblock plugin
435
+ * @param player passthrough the player
436
+ * @returns void
437
+ *
438
+ * @example
439
+ * ```ts
440
+ * // use it on the player via player.setSponsorBlock();
441
+ * const sponsorBlockSegments = await player.node.setSponsorBlock(player, ["sponsor", "selfpromo"]);
442
+ * ```
443
+ */
444
+ async setSponsorBlock(player, segments = ["sponsor", "selfpromo"]) {
445
+ if (!this.info.plugins.some((plugin) => plugin.name === "sponsorblock-plugin"))
446
+ throw new RangeError(`there is no sponsorblock-plugin available in the lavalink node: ${this.options.identifier}`);
447
+ if (!segments.length)
448
+ throw new RangeError("No Segments provided. Did you mean to use 'deleteSponsorBlock'?");
449
+ if (segments.some((v) => !exports.validSponsorBlocks.includes(v.toLowerCase())))
450
+ throw new SyntaxError(`You provided a sponsorblock which isn't valid, valid ones are: ${exports.validSponsorBlocks.map((v) => `'${v}'`).join(", ")}`);
451
+ await this.rest.put(`/v4/sessions/${this.sessionId}/players/${player.guild}/sponsorblock/categories`, JSON.stringify(segments.map((v) => v.toLowerCase())));
452
+ return;
453
+ }
454
+ /**
455
+ * Delete the sponsorblock plugins
456
+ * @param player passthrough the player
457
+ * @returns void
458
+ *
459
+ * @example
460
+ * ```ts
461
+ * // use it on the player via player.deleteSponsorBlock();
462
+ * const sponsorBlockSegments = await player.node.deleteSponsorBlock(player);
463
+ * ```
464
+ */
465
+ async deleteSponsorBlock(player) {
466
+ if (!this.info.plugins.some((plugin) => plugin.name === "sponsorblock-plugin"))
467
+ throw new RangeError(`there is no sponsorblock-plugin available in the lavalink node: ${this.options.identifier}`);
468
+ await this.rest.delete(`/v4/sessions/${this.sessionId}/players/${player.guild}/sponsorblock/categories`);
469
+ return;
470
+ }
397
471
  }
398
472
  exports.Node = Node;
@@ -329,6 +329,25 @@ class Player {
329
329
  this.manager.emit("playerStateUpdate", oldPlayer, this);
330
330
  return this;
331
331
  }
332
+ /**
333
+ * Sets the sponsorblock for the player.
334
+ * @param segments
335
+ */
336
+ async setSponsorBlock(segments = ["sponsor", "selfpromo"]) {
337
+ return this.node.setSponsorBlock(this, segments);
338
+ }
339
+ /**
340
+ * Gets the sponsorblock for the player.
341
+ */
342
+ async getSponsorBlock() {
343
+ return this.node.getSponsorBlock(this);
344
+ }
345
+ /**
346
+ * Deletes the sponsorblock for the player.
347
+ */
348
+ async deleteSponsorBlock() {
349
+ return this.node.deleteSponsorBlock(this);
350
+ }
332
351
  /**
333
352
  * Sets the track repeat.
334
353
  * @param repeat
@@ -55,7 +55,10 @@ class Rest {
55
55
  return response.data;
56
56
  }
57
57
  catch (error) {
58
- if (error?.response?.status === 404) {
58
+ if (error?.response.data.message === "Guild not found") {
59
+ return [];
60
+ }
61
+ else if (error?.response?.status === 404) {
59
62
  this.node.destroy();
60
63
  this.node.manager.createNode(this.node.options).connect();
61
64
  }
@@ -74,6 +77,10 @@ class Rest {
74
77
  async post(endpoint, body) {
75
78
  return await this.request("POST", endpoint, body);
76
79
  }
80
+ /* Sends a PUT request to the specified endpoint and returns the response data. */
81
+ async put(endpoint, body) {
82
+ return await this.request("PUT", endpoint, body);
83
+ }
77
84
  /* Sends a DELETE request to the specified endpoint and returns the response data. */
78
85
  async delete(endpoint) {
79
86
  return await this.request("DELETE", endpoint);
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  function managerCheck(options) {
4
4
  if (!options)
5
5
  throw new TypeError("ManagerOptions must not be empty.");
6
- const { autoPlay, clientId, clientName, defaultSearchPlatform, nodes, plugins, send, shards, trackPartial, usePriority, useNode, replaceYouTubeCredentials } = options;
6
+ const { autoPlay, clientId, clientName, defaultSearchPlatform, nodes, plugins, send, trackPartial, usePriority, useNode, replaceYouTubeCredentials } = options;
7
7
  if (typeof autoPlay !== "undefined" && typeof autoPlay !== "boolean") {
8
8
  throw new TypeError('Manager option "autoPlay" must be a boolean.');
9
9
  }
@@ -25,9 +25,6 @@ function managerCheck(options) {
25
25
  if (typeof send !== "function") {
26
26
  throw new TypeError('Manager option "send" must be present and a function.');
27
27
  }
28
- if (typeof shards !== "undefined" && typeof shards !== "number") {
29
- throw new TypeError('Manager option "shards" must be a number.');
30
- }
31
28
  if (typeof trackPartial !== "undefined" && !Array.isArray(trackPartial)) {
32
29
  throw new TypeError('Manager option "trackPartial" must be a string array.');
33
30
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "magmastream",
3
- "version": "2.5.16",
3
+ "version": "2.6.0-beta.1",
4
4
  "description": "A user-friendly Lavalink client designed for NodeJS.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",