ryanlink 1.0.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.
Files changed (60) hide show
  1. package/LICENSE +37 -0
  2. package/README.md +455 -0
  3. package/dist/index.d.mts +1335 -0
  4. package/dist/index.d.ts +1335 -0
  5. package/dist/index.js +4694 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/index.mjs +4604 -0
  8. package/dist/index.mjs.map +1 -0
  9. package/package.json +82 -0
  10. package/src/audio/AudioFilters.ts +316 -0
  11. package/src/audio/AudioQueue.ts +782 -0
  12. package/src/audio/AudioTrack.ts +242 -0
  13. package/src/audio/QueueController.ts +252 -0
  14. package/src/audio/TrackCollection.ts +138 -0
  15. package/src/audio/index.ts +9 -0
  16. package/src/config/defaults.ts +223 -0
  17. package/src/config/endpoints.ts +99 -0
  18. package/src/config/index.ts +9 -0
  19. package/src/config/patterns.ts +55 -0
  20. package/src/config/presets.ts +400 -0
  21. package/src/config/symbols.ts +31 -0
  22. package/src/core/PluginSystem.ts +50 -0
  23. package/src/core/RyanlinkPlayer.ts +403 -0
  24. package/src/core/index.ts +6 -0
  25. package/src/extensions/AutoplayExtension.ts +283 -0
  26. package/src/extensions/FairPlayExtension.ts +154 -0
  27. package/src/extensions/LyricsExtension.ts +187 -0
  28. package/src/extensions/PersistenceExtension.ts +182 -0
  29. package/src/extensions/SponsorBlockExtension.ts +81 -0
  30. package/src/extensions/index.ts +9 -0
  31. package/src/index.ts +19 -0
  32. package/src/lavalink/ConnectionPool.ts +326 -0
  33. package/src/lavalink/HttpClient.ts +316 -0
  34. package/src/lavalink/LavalinkConnection.ts +409 -0
  35. package/src/lavalink/index.ts +7 -0
  36. package/src/metadata.ts +88 -0
  37. package/src/types/api/Rest.ts +949 -0
  38. package/src/types/api/Websocket.ts +463 -0
  39. package/src/types/api/index.ts +6 -0
  40. package/src/types/audio/FilterManager.ts +29 -0
  41. package/src/types/audio/Queue.ts +4 -0
  42. package/src/types/audio/QueueManager.ts +30 -0
  43. package/src/types/audio/index.ts +7 -0
  44. package/src/types/common.ts +63 -0
  45. package/src/types/core/Player.ts +322 -0
  46. package/src/types/core/index.ts +5 -0
  47. package/src/types/index.ts +6 -0
  48. package/src/types/lavalink/Node.ts +173 -0
  49. package/src/types/lavalink/NodeManager.ts +34 -0
  50. package/src/types/lavalink/REST.ts +144 -0
  51. package/src/types/lavalink/index.ts +32 -0
  52. package/src/types/voice/VoiceManager.ts +176 -0
  53. package/src/types/voice/index.ts +5 -0
  54. package/src/utils/helpers.ts +169 -0
  55. package/src/utils/index.ts +6 -0
  56. package/src/utils/validators.ts +184 -0
  57. package/src/voice/RegionSelector.ts +184 -0
  58. package/src/voice/VoiceConnection.ts +451 -0
  59. package/src/voice/VoiceSession.ts +297 -0
  60. package/src/voice/index.ts +7 -0
@@ -0,0 +1,463 @@
1
+ import type { APITrack } from "./Rest";
2
+
3
+ /**
4
+ * Exception severity levels
5
+ */
6
+ export const enum Severity {
7
+ /**
8
+ * The cause is known and expected, indicates that there is nothing wrong with the library itself
9
+ */
10
+ Common = "common",
11
+
12
+ /**
13
+ * The cause might not be exactly known, but is possibly caused by outside factors.
14
+ * For example when an outside service responds in a format that we do not expect
15
+ */
16
+ Suspicious = "suspicious",
17
+
18
+ /**
19
+ * The probable cause is an issue with the library or there is no way to tell what the cause might be.
20
+ * This is the default level and other levels are used in cases where the thrower has more in-depth knowledge about the error
21
+ */
22
+ Fault = "fault",
23
+ }
24
+
25
+ /**
26
+ * WebSocket operation types
27
+ */
28
+ export const enum OPType {
29
+ /**
30
+ * Dispatched when you successfully connect to the Lavalink node
31
+ */
32
+ Ready = "ready",
33
+
34
+ /**
35
+ * Dispatched every x seconds with the latest player state
36
+ */
37
+ PlayerUpdate = "playerUpdate",
38
+
39
+ /**
40
+ * Dispatched when the node sends stats once per minute
41
+ */
42
+ Stats = "stats",
43
+
44
+ /**
45
+ * Dispatched when player or voice events occur
46
+ */
47
+ Event = "event",
48
+ }
49
+
50
+ /**
51
+ * Event types from Lavalink
52
+ */
53
+ export const enum EventType {
54
+ /**
55
+ * Dispatched when a track starts playing
56
+ */
57
+ TrackStart = "TrackStartEvent",
58
+
59
+ /**
60
+ * Dispatched when a track ends
61
+ */
62
+ TrackEnd = "TrackEndEvent",
63
+
64
+ /**
65
+ * Dispatched when a track throws an exception
66
+ */
67
+ TrackException = "TrackExceptionEvent",
68
+
69
+ /**
70
+ * Dispatched when a track gets stuck while playing
71
+ */
72
+ TrackStuck = "TrackStuckEvent",
73
+
74
+ /**
75
+ * Dispatched when the websocket connection to Discord voice servers is closed
76
+ */
77
+ WebSocketClosed = "WebSocketClosedEvent",
78
+ }
79
+
80
+ /**
81
+ * Reasons why a track ended
82
+ */
83
+ export const enum TrackEndReason {
84
+ /**
85
+ * The track finished playing.
86
+ * May start next: true
87
+ */
88
+ Finished = "finished",
89
+
90
+ /**
91
+ * The track failed to load.
92
+ * May start next: true
93
+ */
94
+ LoadFailed = "loadFailed",
95
+
96
+ /**
97
+ * The track was stopped.
98
+ * May start next: false
99
+ */
100
+ Stopped = "stopped",
101
+
102
+ /**
103
+ * The track was replaced.
104
+ * May start next: false
105
+ */
106
+ Replaced = "replaced",
107
+
108
+ /**
109
+ * The track was cleaned up.
110
+ * May start next: false
111
+ */
112
+ Cleanup = "cleanup",
113
+ }
114
+
115
+ /**
116
+ * Client headers for WebSocket connection
117
+ */
118
+ export interface ClientHeaders {
119
+ /**
120
+ * Password of your Lavalink server
121
+ */
122
+ Authorization: string;
123
+
124
+ /**
125
+ * User Id of the bot
126
+ */
127
+ "User-Id": string;
128
+
129
+ /**
130
+ * Name of the client in `NAME/VERSION` format
131
+ */
132
+ "Client-Name": string;
133
+
134
+ /**
135
+ * User agent string
136
+ */
137
+ "User-Agent": string;
138
+
139
+ /**
140
+ * Id of the previous session to resume (if any)
141
+ */
142
+ "Session-Id"?: string;
143
+ }
144
+
145
+ /**
146
+ * Base message payload
147
+ */
148
+ export interface BaseMessagePayload {
149
+ /**
150
+ * The op type
151
+ */
152
+ op: OPType | string;
153
+ }
154
+
155
+ /**
156
+ * Ready event payload
157
+ */
158
+ export interface ReadyPayload extends BaseMessagePayload {
159
+ op: OPType.Ready;
160
+
161
+ /**
162
+ * Whether this session was resumed
163
+ */
164
+ resumed: boolean;
165
+
166
+ /**
167
+ * The Lavalink session id of this connection. Not to be confused with a Discord voice session id
168
+ */
169
+ sessionId: string;
170
+ }
171
+
172
+ /**
173
+ * Player update payload
174
+ */
175
+ export interface PlayerUpdatePayload extends BaseMessagePayload {
176
+ op: OPType.PlayerUpdate;
177
+
178
+ /**
179
+ * The guild id of the player
180
+ */
181
+ guildId: string;
182
+
183
+ /**
184
+ * The player state
185
+ */
186
+ state: PlayerState;
187
+ }
188
+
189
+ /**
190
+ * Player state information
191
+ */
192
+ export interface PlayerState {
193
+ /**
194
+ * Unix timestamp in milliseconds
195
+ */
196
+ time: number;
197
+
198
+ /**
199
+ * The position of the track in milliseconds
200
+ */
201
+ position: number;
202
+
203
+ /**
204
+ * Whether Lavalink is connected to the voice gateway
205
+ */
206
+ connected: boolean;
207
+
208
+ /**
209
+ * The ping of the node to the Discord voice server in milliseconds (`-1` if not connected)
210
+ */
211
+ ping: number;
212
+ }
213
+
214
+ /**
215
+ * Stats payload
216
+ */
217
+ export interface StatsPayload extends BaseMessagePayload, NodeStats {
218
+ op: OPType.Stats;
219
+ }
220
+
221
+ /**
222
+ * Node statistics
223
+ */
224
+ export interface NodeStats {
225
+ /**
226
+ * The amount of players connected to the node
227
+ */
228
+ players: number;
229
+
230
+ /**
231
+ * The amount of players playing a track
232
+ */
233
+ playingPlayers: number;
234
+
235
+ /**
236
+ * The uptime of the node in milliseconds
237
+ */
238
+ uptime: number;
239
+
240
+ /**
241
+ * The memory stats of the node
242
+ */
243
+ memory: NodeMemory;
244
+
245
+ /**
246
+ * The cpu stats of the node
247
+ */
248
+ cpu: NodeCPU;
249
+
250
+ /**
251
+ * The frame stats of the node. `null` if the node has no players or when retrieved via `/v4/stats`
252
+ */
253
+ frameStats: FrameStats | null;
254
+ }
255
+
256
+ /**
257
+ * Node memory statistics
258
+ */
259
+ export interface NodeMemory {
260
+ /**
261
+ * The amount of free memory in bytes
262
+ */
263
+ free: number;
264
+
265
+ /**
266
+ * The amount of used memory in bytes
267
+ */
268
+ used: number;
269
+
270
+ /**
271
+ * The amount of allocated memory in bytes
272
+ */
273
+ allocated: number;
274
+
275
+ /**
276
+ * The amount of reservable memory in bytes
277
+ */
278
+ reservable: number;
279
+ }
280
+
281
+ /**
282
+ * Node CPU statistics
283
+ */
284
+ export interface NodeCPU {
285
+ /**
286
+ * The amount of cores the node has
287
+ */
288
+ cores: number;
289
+
290
+ /**
291
+ * The system load of the node
292
+ */
293
+ systemLoad: number;
294
+
295
+ /**
296
+ * The load of Lavalink on the node
297
+ */
298
+ lavalinkLoad: number;
299
+ }
300
+
301
+ /**
302
+ * Frame statistics
303
+ */
304
+ export interface FrameStats {
305
+ /**
306
+ * The amount of frames sent to Discord
307
+ */
308
+ sent: number;
309
+
310
+ /**
311
+ * The amount of frames that were nulled
312
+ */
313
+ nulled: number;
314
+
315
+ /**
316
+ * The difference between sent frames and the expected amount of frames
317
+ * The expected amount of frames is 3000 (1 every 20 ms) per player.
318
+ * If the deficit is negative, too many frames were sent, and if it's positive, not enough frames got sent.
319
+ */
320
+ deficit: number;
321
+ }
322
+
323
+ /**
324
+ * Base event payload
325
+ */
326
+ export interface BaseEventPayload extends BaseMessagePayload {
327
+ op: OPType.Event;
328
+
329
+ /**
330
+ * The type of event
331
+ */
332
+ type: EventType | string;
333
+
334
+ /**
335
+ * The guild id
336
+ */
337
+ guildId: string;
338
+ }
339
+
340
+ /**
341
+ * Track start event payload
342
+ */
343
+ export interface TrackStartEventPayload extends BaseEventPayload {
344
+ type: EventType.TrackStart;
345
+
346
+ /**
347
+ * The track that started playing
348
+ */
349
+ track: APITrack;
350
+ }
351
+
352
+ /**
353
+ * Track end event payload
354
+ */
355
+ export interface TrackEndEventPayload extends BaseEventPayload {
356
+ type: EventType.TrackEnd;
357
+
358
+ /**
359
+ * The track that ended playing
360
+ */
361
+ track: APITrack;
362
+
363
+ /**
364
+ * The reason the track ended
365
+ */
366
+ reason: TrackEndReason;
367
+ }
368
+
369
+ /**
370
+ * Track exception event payload
371
+ */
372
+ export interface TrackExceptionEventPayload extends BaseEventPayload {
373
+ type: EventType.TrackException;
374
+
375
+ /**
376
+ * The track that threw the exception
377
+ */
378
+ track: APITrack;
379
+
380
+ /**
381
+ * The occurred exception
382
+ */
383
+ exception: Exception;
384
+ }
385
+
386
+ /**
387
+ * Exception information
388
+ */
389
+ export interface Exception {
390
+ /**
391
+ * The message of the exception
392
+ */
393
+ message: string | null;
394
+
395
+ /**
396
+ * The severity of the exception
397
+ */
398
+ severity: Severity;
399
+
400
+ /**
401
+ * The cause of the exception
402
+ */
403
+ cause: string;
404
+
405
+ /**
406
+ * The full stack trace of the cause
407
+ */
408
+ causeStackTrace: string;
409
+ }
410
+
411
+ /**
412
+ * Track stuck event payload
413
+ */
414
+ export interface TrackStuckEventPayload extends BaseEventPayload {
415
+ type: EventType.TrackStuck;
416
+
417
+ /**
418
+ * The track that got stuck
419
+ */
420
+ track: APITrack;
421
+
422
+ /**
423
+ * The threshold in milliseconds that was exceeded
424
+ */
425
+ thresholdMs: number;
426
+ }
427
+
428
+ /**
429
+ * WebSocket closed event payload
430
+ */
431
+ export interface WebSocketClosedEventPayload extends BaseEventPayload {
432
+ type: EventType.WebSocketClosed;
433
+
434
+ /**
435
+ * The Discord close event code
436
+ */
437
+ code: number;
438
+
439
+ /**
440
+ * The close reason
441
+ */
442
+ reason: string;
443
+
444
+ /**
445
+ * Whether the connection was closed by Discord
446
+ */
447
+ byRemote: boolean;
448
+ }
449
+
450
+ /**
451
+ * Event payload union type
452
+ */
453
+ export type EventPayload =
454
+ | TrackStartEventPayload
455
+ | TrackEndEventPayload
456
+ | TrackExceptionEventPayload
457
+ | TrackStuckEventPayload
458
+ | WebSocketClosedEventPayload;
459
+
460
+ /**
461
+ * Message payload union type
462
+ */
463
+ export type MessagePayload = ReadyPayload | PlayerUpdatePayload | StatsPayload | EventPayload;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * API type definitions
3
+ */
4
+
5
+ export * from "./Rest";
6
+ export * from "./Websocket";
@@ -0,0 +1,29 @@
1
+ import type { CommonPluginFilters, JsonObject } from "../../types/common";
2
+ import type { Filters } from "../api";
3
+
4
+ /**
5
+ * Yields a union type of filter names (plugins included)
6
+ */
7
+ export type FilterNames<PluginFilters extends JsonObject = CommonPluginFilters> = keyof Filters | keyof PluginFilters;
8
+
9
+ /**
10
+ * Yields the value of a filter by name
11
+ */
12
+ export type FilterValue<
13
+ Name extends FilterNames<PluginFilters>,
14
+ PluginFilters extends JsonObject = CommonPluginFilters,
15
+ > = Name extends keyof Filters
16
+ ? Required<Filters>[Name]
17
+ : Name extends keyof PluginFilters
18
+ ? Required<PluginFilters>[Name]
19
+ : never;
20
+
21
+ /**
22
+ * Alias for Filters
23
+ */
24
+ export type FilterData = Filters;
25
+
26
+ /**
27
+ * Union of filter keys
28
+ */
29
+ export type FilterKey = keyof Filters;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Repeat modes of a queue
3
+ */
4
+ export type RepeatMode = "none" | "track" | "queue";
@@ -0,0 +1,30 @@
1
+ import type { QueueContext } from "../common";
2
+ import type { PlayerUpdateRequestBody } from "../api";
3
+
4
+ /**
5
+ * Options for creating a queue via manager
6
+ */
7
+ export interface CreateQueueOptions<Context extends Record<string, unknown> = QueueContext> extends Pick<
8
+ PlayerUpdateRequestBody,
9
+ "filters" | "volume"
10
+ > {
11
+ /**
12
+ * Guild ID for the queue
13
+ */
14
+ guildId: string;
15
+
16
+ /**
17
+ * Voice channel ID to connect to
18
+ */
19
+ voiceId: string;
20
+
21
+ /**
22
+ * Node name to use (optional, will use best node if not specified)
23
+ */
24
+ node?: string;
25
+
26
+ /**
27
+ * Custom context data for the queue
28
+ */
29
+ context?: Context;
30
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Audio type definitions
3
+ */
4
+
5
+ export * from "./FilterManager";
6
+ export * from "./Queue";
7
+ export * from "./QueueManager";
@@ -0,0 +1,63 @@
1
+ import type { PlayerPlugin } from "../core";
2
+
3
+ /**
4
+ * Represents an empty object
5
+ */
6
+ export type EmptyObject = Record<never, never>;
7
+
8
+ /**
9
+ * Represents JSON serializable data
10
+ */
11
+ export type JsonLike = string | number | null | boolean | JsonArray | JsonObject;
12
+
13
+ /**
14
+ * Represents JSON serializable array
15
+ */
16
+ export type JsonArray = JsonLike[];
17
+
18
+ /**
19
+ * Represents JSON serializable object
20
+ */
21
+ export type JsonObject = { [x: string]: JsonLike };
22
+
23
+ /**
24
+ * Makes select properties required
25
+ */
26
+ export type RequiredProp<T, P extends keyof T> = Omit<T, P> & Required<Pick<T, P>>;
27
+
28
+ /**
29
+ * Makes select properties non-nullable
30
+ */
31
+ export type NonNullableProp<T, P extends keyof T> = {
32
+ [K in keyof T]: K extends P ? NonNullable<T[K]> : T[K];
33
+ };
34
+
35
+ /**
36
+ * Merges a union type into one
37
+ */
38
+ export type MergeUnionType<U> = (U extends unknown ? (i: U) => void : never) extends (i: infer I) => void ? I : never;
39
+
40
+ /**
41
+ * Extracts the event map of a plugin
42
+ */
43
+ export type PluginEventMap<Plugin> = Plugin extends PlayerPlugin<infer EventMap> ? EventMap : Record<string, unknown>;
44
+
45
+ /**
46
+ * Queue context, extend via module declaration
47
+ */
48
+ export interface QueueContext extends Record<string, unknown> {}
49
+
50
+ /**
51
+ * Basic user data, extend via module declaration
52
+ */
53
+ export interface CommonUserData extends Record<string, JsonLike> {}
54
+
55
+ /**
56
+ * Common info provided by plugins, extend via module declaration
57
+ */
58
+ export interface CommonPluginInfo extends Record<string, JsonLike> {}
59
+
60
+ /**
61
+ * Common plugin filters, extend via module declaration
62
+ */
63
+ export interface CommonPluginFilters extends Record<string, JsonLike> {}