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.
- package/LICENSE +37 -0
- package/README.md +455 -0
- package/dist/index.d.mts +1335 -0
- package/dist/index.d.ts +1335 -0
- package/dist/index.js +4694 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +4604 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +82 -0
- package/src/audio/AudioFilters.ts +316 -0
- package/src/audio/AudioQueue.ts +782 -0
- package/src/audio/AudioTrack.ts +242 -0
- package/src/audio/QueueController.ts +252 -0
- package/src/audio/TrackCollection.ts +138 -0
- package/src/audio/index.ts +9 -0
- package/src/config/defaults.ts +223 -0
- package/src/config/endpoints.ts +99 -0
- package/src/config/index.ts +9 -0
- package/src/config/patterns.ts +55 -0
- package/src/config/presets.ts +400 -0
- package/src/config/symbols.ts +31 -0
- package/src/core/PluginSystem.ts +50 -0
- package/src/core/RyanlinkPlayer.ts +403 -0
- package/src/core/index.ts +6 -0
- package/src/extensions/AutoplayExtension.ts +283 -0
- package/src/extensions/FairPlayExtension.ts +154 -0
- package/src/extensions/LyricsExtension.ts +187 -0
- package/src/extensions/PersistenceExtension.ts +182 -0
- package/src/extensions/SponsorBlockExtension.ts +81 -0
- package/src/extensions/index.ts +9 -0
- package/src/index.ts +19 -0
- package/src/lavalink/ConnectionPool.ts +326 -0
- package/src/lavalink/HttpClient.ts +316 -0
- package/src/lavalink/LavalinkConnection.ts +409 -0
- package/src/lavalink/index.ts +7 -0
- package/src/metadata.ts +88 -0
- package/src/types/api/Rest.ts +949 -0
- package/src/types/api/Websocket.ts +463 -0
- package/src/types/api/index.ts +6 -0
- package/src/types/audio/FilterManager.ts +29 -0
- package/src/types/audio/Queue.ts +4 -0
- package/src/types/audio/QueueManager.ts +30 -0
- package/src/types/audio/index.ts +7 -0
- package/src/types/common.ts +63 -0
- package/src/types/core/Player.ts +322 -0
- package/src/types/core/index.ts +5 -0
- package/src/types/index.ts +6 -0
- package/src/types/lavalink/Node.ts +173 -0
- package/src/types/lavalink/NodeManager.ts +34 -0
- package/src/types/lavalink/REST.ts +144 -0
- package/src/types/lavalink/index.ts +32 -0
- package/src/types/voice/VoiceManager.ts +176 -0
- package/src/types/voice/index.ts +5 -0
- package/src/utils/helpers.ts +169 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/validators.ts +184 -0
- package/src/voice/RegionSelector.ts +184 -0
- package/src/voice/VoiceConnection.ts +451 -0
- package/src/voice/VoiceSession.ts +297 -0
- package/src/voice/index.ts +7 -0
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import type { CommonUserData, JsonObject, QueueContext, RequiredProp } from "../common";
|
|
2
|
+
import type { Exception, PlayerState, TrackEndReason } from "../api/Websocket";
|
|
3
|
+
import type { CreateNodeOptions, NodeEventMap } from "../lavalink";
|
|
4
|
+
import type { CreateQueueOptions } from "../audio";
|
|
5
|
+
import type { DefaultPlayerOptions } from "../../config";
|
|
6
|
+
import type { Node } from "../../lavalink/LavalinkConnection";
|
|
7
|
+
import type { VoiceState } from "../../voice/VoiceSession";
|
|
8
|
+
import type { Playlist, Queue } from "../../audio";
|
|
9
|
+
import type { Track } from "../../audio/AudioTrack";
|
|
10
|
+
import type { Player } from "../../core/RyanlinkPlayer";
|
|
11
|
+
import type { LyricsResult } from "../../extensions/LyricsExtension";
|
|
12
|
+
import type { PlayerPlugin } from "../../core/PluginSystem";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Helper type to exclude last element from tuple
|
|
16
|
+
*/
|
|
17
|
+
type ExcludeLast<T extends unknown[]> = T extends [...infer Items, unknown] ? Items : never;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Player event map
|
|
21
|
+
*/
|
|
22
|
+
export interface PlayerEventMap {
|
|
23
|
+
/**
|
|
24
|
+
* Emitted when player is initialized
|
|
25
|
+
*/
|
|
26
|
+
init: [];
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Emitted when a node connects
|
|
30
|
+
*/
|
|
31
|
+
nodeConnect: [node: Node, ...ExcludeLast<NodeEventMap["connect"]>];
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Emitted when a node is ready
|
|
35
|
+
*/
|
|
36
|
+
nodeReady: [node: Node, ...ExcludeLast<NodeEventMap["ready"]>];
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Emitted when a node receives a dispatch
|
|
40
|
+
*/
|
|
41
|
+
nodeDispatch: [node: Node, ...ExcludeLast<NodeEventMap["dispatch"]>];
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Emitted when a node encounters an error
|
|
45
|
+
*/
|
|
46
|
+
nodeError: [node: Node, ...ExcludeLast<NodeEventMap["error"]>];
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Emitted when a node closes
|
|
50
|
+
*/
|
|
51
|
+
nodeClose: [node: Node, ...ExcludeLast<NodeEventMap["close"]>];
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Emitted when a node disconnects
|
|
55
|
+
*/
|
|
56
|
+
nodeDisconnect: [node: Node, ...ExcludeLast<NodeEventMap["disconnect"]>];
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Emitted when voice connection is established
|
|
60
|
+
*/
|
|
61
|
+
voiceConnect: [voice: VoiceState];
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Emitted when voice connection closes
|
|
65
|
+
*/
|
|
66
|
+
voiceClose: [voice: VoiceState, code: number, reason: string, byRemote: boolean];
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Emitted when voice connection changes nodes
|
|
70
|
+
*/
|
|
71
|
+
voiceChange: [voice: VoiceState, previousNode: Node, wasPlaying: boolean];
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Emitted when voice connection is destroyed
|
|
75
|
+
*/
|
|
76
|
+
voiceDestroy: [voice: VoiceState, reason: string];
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Emitted when a queue is created
|
|
80
|
+
*/
|
|
81
|
+
queueCreate: [queue: Queue];
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Emitted when queue state updates
|
|
85
|
+
*/
|
|
86
|
+
queueUpdate: [queue: Queue, state: PlayerState];
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Emitted when queue finishes
|
|
90
|
+
*/
|
|
91
|
+
queueFinish: [queue: Queue];
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Emitted when a queue is destroyed
|
|
95
|
+
*/
|
|
96
|
+
queueDestroy: [queue: Queue, reason: string];
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Emitted when a track starts playing
|
|
100
|
+
*/
|
|
101
|
+
trackStart: [queue: Queue, track: Track];
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Emitted when tracks are added to a queue
|
|
105
|
+
*/
|
|
106
|
+
trackAdd: [player: Player, guildId: string, tracks: Track[]];
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Emitted when a track gets stuck
|
|
110
|
+
*/
|
|
111
|
+
trackStuck: [queue: Queue, track: Track, thresholdMs: number];
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Emitted when a track encounters an error
|
|
115
|
+
*/
|
|
116
|
+
trackError: [queue: Queue, track: Track, exception: Exception];
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Emitted when a track finishes
|
|
120
|
+
*/
|
|
121
|
+
trackFinish: [queue: Queue, track: Track, reason: TrackEndReason];
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Emitted for debug logs
|
|
125
|
+
*/
|
|
126
|
+
debug: [name: string, info: unknown];
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Emitted when SponsorBlock segments are loaded
|
|
130
|
+
*/
|
|
131
|
+
segmentsLoaded: [queue: Queue, track: Track, payload: unknown];
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Emitted when a SponsorBlock segment is skipped
|
|
135
|
+
*/
|
|
136
|
+
segmentSkipped: [queue: Queue, track: Track, payload: unknown];
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Emitted when fair play algorithm is applied to a queue
|
|
140
|
+
*/
|
|
141
|
+
fairPlayApplied: [player: Player, guildId: string, count: number];
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Emitted when lyrics are found for a track
|
|
145
|
+
*/
|
|
146
|
+
lyricsFound: [player: Player, track: Track, result: LyricsResult];
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Emitted when lyrics are not found for a track
|
|
150
|
+
*/
|
|
151
|
+
lyricsNotFound: [player: Player, track: Track];
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Emitted when a queue is saved
|
|
155
|
+
*/
|
|
156
|
+
queueSaved: [guildId: string];
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Emitted when a queue is loaded
|
|
160
|
+
*/
|
|
161
|
+
queueLoaded: [guildId: string, count: number];
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Constructs a record type mapping plugins by their names
|
|
166
|
+
*/
|
|
167
|
+
export type PluginRecord<Plugins extends PlayerPlugin[]> = {
|
|
168
|
+
[Name in Plugins[number]["name"]]: Extract<Plugins[number], { name: Name }>;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Options for creating a Player
|
|
173
|
+
*/
|
|
174
|
+
export interface PlayerOptions<Plugins extends PlayerPlugin[] = PlayerPlugin[]> {
|
|
175
|
+
/**
|
|
176
|
+
* Options for creating node(s)
|
|
177
|
+
*/
|
|
178
|
+
nodes: CreateNodeOptions[];
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Plugins to initialize after creating nodes
|
|
182
|
+
*/
|
|
183
|
+
plugins?: Plugins;
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Whether to initialize automatically upon receiving the bot's ready event.
|
|
187
|
+
* @default true
|
|
188
|
+
*/
|
|
189
|
+
autoInit?: boolean;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Whether to update players for nodes that couldn't resume.
|
|
193
|
+
* @default true
|
|
194
|
+
*/
|
|
195
|
+
autoSync?: boolean;
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* The prefix to use for search queries (not URLs) by default.
|
|
199
|
+
* @default "ytsearch"
|
|
200
|
+
*/
|
|
201
|
+
queryPrefix?: string;
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Whether to relocate queues when a node closes/disconnects.
|
|
205
|
+
* @default true
|
|
206
|
+
*/
|
|
207
|
+
relocateQueues?: boolean;
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Forward voice state updates to your bot's gateway connection
|
|
211
|
+
* @param guildId Id of the guild this voice update is meant for
|
|
212
|
+
* @param payload The voice state update payload to be forwarded
|
|
213
|
+
*/
|
|
214
|
+
forwardVoiceUpdate: (guildId: string, payload: VoiceUpdatePayload) => Promise<void>;
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Return empty or populated array of related tracks
|
|
218
|
+
* @param queue The queue requesting track(s)
|
|
219
|
+
* @param track The track suggested for reference
|
|
220
|
+
*/
|
|
221
|
+
fetchRelatedTracks?: (queue: Queue, track: Track) => Promise<Track[]>;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Player instance options (with defaults applied)
|
|
226
|
+
*/
|
|
227
|
+
export type PlayerInstanceOptions = Omit<
|
|
228
|
+
RequiredProp<PlayerOptions, keyof typeof DefaultPlayerOptions>,
|
|
229
|
+
"nodes" | "plugins"
|
|
230
|
+
>;
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Voice state update payload
|
|
234
|
+
*/
|
|
235
|
+
export interface VoiceUpdatePayload {
|
|
236
|
+
op: 4;
|
|
237
|
+
d: {
|
|
238
|
+
guild_id: string;
|
|
239
|
+
channel_id: string | null;
|
|
240
|
+
self_deaf: boolean;
|
|
241
|
+
self_mute: boolean;
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Options for customizing a 'search' operation
|
|
247
|
+
*/
|
|
248
|
+
export interface SearchOptions {
|
|
249
|
+
/**
|
|
250
|
+
* Node name to use for search
|
|
251
|
+
*/
|
|
252
|
+
node?: string;
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Search prefix (ytsearch, ytmsearch, scsearch, etc.)
|
|
256
|
+
*/
|
|
257
|
+
prefix?: string;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Options for customizing a 'play' operation
|
|
262
|
+
*/
|
|
263
|
+
export interface PlayOptions<
|
|
264
|
+
Context extends Record<string, unknown> = QueueContext,
|
|
265
|
+
UserData extends JsonObject = CommonUserData,
|
|
266
|
+
>
|
|
267
|
+
extends SearchOptions, CreateQueueOptions<Context> {
|
|
268
|
+
/**
|
|
269
|
+
* User data to attach to the track
|
|
270
|
+
*/
|
|
271
|
+
userData?: UserData;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Track search result
|
|
276
|
+
*/
|
|
277
|
+
export interface TrackSearchResult {
|
|
278
|
+
type: "track";
|
|
279
|
+
data: Track;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Playlist search result
|
|
284
|
+
*/
|
|
285
|
+
export interface PlaylistSearchResult {
|
|
286
|
+
type: "playlist";
|
|
287
|
+
data: Playlist;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Query search result
|
|
292
|
+
*/
|
|
293
|
+
export interface QuerySearchResult {
|
|
294
|
+
type: "query";
|
|
295
|
+
data: Track[];
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Empty search result
|
|
300
|
+
*/
|
|
301
|
+
export interface EmptySearchResult {
|
|
302
|
+
type: "empty";
|
|
303
|
+
data: [];
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Error search result
|
|
308
|
+
*/
|
|
309
|
+
export interface ErrorSearchResult {
|
|
310
|
+
type: "error";
|
|
311
|
+
data: Exception;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Search result union type
|
|
316
|
+
*/
|
|
317
|
+
export type SearchResult =
|
|
318
|
+
| TrackSearchResult
|
|
319
|
+
| PlaylistSearchResult
|
|
320
|
+
| QuerySearchResult
|
|
321
|
+
| EmptySearchResult
|
|
322
|
+
| ErrorSearchResult;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import type { MessagePayload } from "../api";
|
|
2
|
+
import type { RESTOptions } from "./REST";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* WebSocket close codes
|
|
6
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code
|
|
7
|
+
*/
|
|
8
|
+
export const enum CloseCodes {
|
|
9
|
+
/**
|
|
10
|
+
* The connection successfully completed the purpose for which it was created.
|
|
11
|
+
*/
|
|
12
|
+
Normal = 1000,
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The endpoint is going away, either because of a server failure or
|
|
16
|
+
* the browser navigating away from the page that opened the connection.
|
|
17
|
+
*/
|
|
18
|
+
GoingAway,
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The endpoint is terminating the connection due to a protocol error.
|
|
22
|
+
*/
|
|
23
|
+
ProtocolError,
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The connection is being terminated because the endpoint received data of a type it cannot accept.
|
|
27
|
+
* (For example, a text-only endpoint received binary data.)
|
|
28
|
+
*/
|
|
29
|
+
UnsupportedData,
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Reserved. A meaning might be defined in the future.
|
|
33
|
+
*/
|
|
34
|
+
Reserved,
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Reserved. Indicates that no status code was provided even though one was expected.
|
|
38
|
+
*/
|
|
39
|
+
NoStatusReceived,
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Reserved. Indicates that a connection was closed abnormally (that is, with no close frame being sent) when a status code is expected.
|
|
43
|
+
*/
|
|
44
|
+
Abnormal,
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The endpoint is terminating the connection because a message was received that contained inconsistent data (e.g., non-UTF-8 data within a text message).
|
|
48
|
+
*/
|
|
49
|
+
InvalidFramePayloadData,
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The endpoint is terminating the connection because it received a message that violates its policy. This is a generic status code, used when codes 1003 and 1009 are not suitable.
|
|
53
|
+
*/
|
|
54
|
+
PolicyViolation,
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The endpoint is terminating the connection because a data frame was received that is too large.
|
|
58
|
+
*/
|
|
59
|
+
MessageTooBig,
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The client is terminating the connection because it expected the server to negotiate one or more extension, but the server didn't.
|
|
63
|
+
*/
|
|
64
|
+
MandatoryExtension,
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request.
|
|
68
|
+
*/
|
|
69
|
+
InternalError,
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* The server is terminating the connection because it is restarting.
|
|
73
|
+
*/
|
|
74
|
+
ServiceRestart,
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The server is terminating the connection due to a temporary condition, e.g., it is overloaded and is casting off some of its clients.
|
|
78
|
+
*/
|
|
79
|
+
TryAgainLater,
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The server was acting as a gateway or proxy and received an invalid response from the upstream server. This is similar to 502 HTTP Status Code.
|
|
83
|
+
*/
|
|
84
|
+
BadGateway,
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Reserved. Indicates that the connection was closed due to a failure to perform a TLS handshake (e.g., the server certificate can't be verified).
|
|
88
|
+
*/
|
|
89
|
+
TLSHandshake,
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Node event map
|
|
94
|
+
*/
|
|
95
|
+
export interface NodeEventMap {
|
|
96
|
+
connect: [reconnects: number, name: string];
|
|
97
|
+
ready: [resumed: boolean, sessionId: string, name: string];
|
|
98
|
+
dispatch: [payload: MessagePayload, name: string];
|
|
99
|
+
error: [error: Error, name: string];
|
|
100
|
+
close: [code: number, reason: string, name: string];
|
|
101
|
+
disconnect: [code: number, reason: string, byLocal: boolean, name: string];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* States of a node
|
|
106
|
+
*/
|
|
107
|
+
export type NodeState = "connecting" | "connected" | "ready" | "reconnecting" | "disconnected";
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Options for creating a node
|
|
111
|
+
*/
|
|
112
|
+
export interface NodeOptions extends RESTOptions {
|
|
113
|
+
/**
|
|
114
|
+
* Name of the node
|
|
115
|
+
*/
|
|
116
|
+
name: string;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* User Id of the bot
|
|
120
|
+
*/
|
|
121
|
+
clientId: string;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Interval at which this node dispatches it's stats.
|
|
125
|
+
* Default: `60_000`
|
|
126
|
+
*/
|
|
127
|
+
statsInterval?: number;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* An assumption of this node's highest possible latency.
|
|
131
|
+
* Default: `2_000`
|
|
132
|
+
*/
|
|
133
|
+
highestLatency?: number;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Number of milliseconds to wait between each reconnect.
|
|
137
|
+
* Default: `10_000`
|
|
138
|
+
*/
|
|
139
|
+
reconnectDelay?: number;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Number of reconnects to attempt for unexpected disconnects.
|
|
143
|
+
* Negative for no limit, zero for no attempts.
|
|
144
|
+
* Default: `3`
|
|
145
|
+
*/
|
|
146
|
+
reconnectLimit?: number;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Number of milliseconds to allow for initial handshake.
|
|
150
|
+
* Default: `5_000`
|
|
151
|
+
*/
|
|
152
|
+
handshakeTimeout?: number;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* SponsorBlock segment information
|
|
157
|
+
*/
|
|
158
|
+
export interface SponsorBlockSegment {
|
|
159
|
+
/**
|
|
160
|
+
* The category of the segment
|
|
161
|
+
*/
|
|
162
|
+
category: string;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* The start time of the segment in milliseconds
|
|
166
|
+
*/
|
|
167
|
+
start: number;
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* The end time of the segment in milliseconds
|
|
171
|
+
*/
|
|
172
|
+
end: number;
|
|
173
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { NodeOptions } from "../../types/lavalink/Node";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Options for creating a node via manager
|
|
5
|
+
*/
|
|
6
|
+
export type CreateNodeOptions = Omit<NodeOptions, "clientId">;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Types of node features for support evaluation
|
|
10
|
+
*/
|
|
11
|
+
export type FeatureTypes = "filter" | "source" | "plugin";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Simplified node stats for relevance evaluation.
|
|
15
|
+
*
|
|
16
|
+
* The value of each field lies within [0, 1]
|
|
17
|
+
* except `streaming`, where -1 reports insufficient data
|
|
18
|
+
*/
|
|
19
|
+
export interface NodeMetrics {
|
|
20
|
+
/**
|
|
21
|
+
* Memory usage (0-1 scale, 0 = no usage, 1 = full usage)
|
|
22
|
+
*/
|
|
23
|
+
memory: number;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Workload (0-1 scale, 0 = no load, 1 = full load)
|
|
27
|
+
*/
|
|
28
|
+
workload: number;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Streaming quality (0-1 scale, 0 = poor, 1 = excellent, -1 = insufficient data)
|
|
32
|
+
*/
|
|
33
|
+
streaming: number;
|
|
34
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import type { JsonLike } from "../common";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Options to create an instance of REST
|
|
5
|
+
*/
|
|
6
|
+
export interface RESTOptions {
|
|
7
|
+
/**
|
|
8
|
+
* URL of your lavalink server (e.g., "http://localhost:2333" or "https://lavalink.example.com")
|
|
9
|
+
* If provided, this takes precedence over host/port/secure
|
|
10
|
+
*/
|
|
11
|
+
origin?: string;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Host of your lavalink server (e.g., "localhost" or "lavalink.example.com")
|
|
15
|
+
* Used only if origin is not provided
|
|
16
|
+
*/
|
|
17
|
+
host?: string;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Port of your lavalink server
|
|
21
|
+
* Default: `2333`
|
|
22
|
+
* Used only if origin is not provided
|
|
23
|
+
*/
|
|
24
|
+
port?: number;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Whether to use secure connection (https/wss)
|
|
28
|
+
* Default: `false`
|
|
29
|
+
* Used only if origin is not provided
|
|
30
|
+
*/
|
|
31
|
+
secure?: boolean;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Password of your lavalink server
|
|
35
|
+
*/
|
|
36
|
+
password: string;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The semver major of your lavalink server.
|
|
40
|
+
* Default: `4`
|
|
41
|
+
*/
|
|
42
|
+
version?: number;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The value to set the `User-Agent` header to.
|
|
46
|
+
* Default: `$client/$version ($repository)`
|
|
47
|
+
*/
|
|
48
|
+
userAgent?: string;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Id of the lavalink session you want to interact with (if any)
|
|
52
|
+
*/
|
|
53
|
+
sessionId?: string;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Whether to include stack trace from lavalink server on error.
|
|
57
|
+
* Default: `false`
|
|
58
|
+
*/
|
|
59
|
+
stackTrace?: boolean;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Number of milliseconds to allow per request.
|
|
63
|
+
* Default: `10_000`
|
|
64
|
+
*/
|
|
65
|
+
requestTimeout?: number;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Options for customizing a request
|
|
70
|
+
*/
|
|
71
|
+
export interface RequestOptions {
|
|
72
|
+
/**
|
|
73
|
+
* The http method
|
|
74
|
+
*/
|
|
75
|
+
method?: string;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The query params to `set` (not `append`)
|
|
79
|
+
*/
|
|
80
|
+
params?: Record<string, Exclude<JsonLike, object>>;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The headers to send
|
|
84
|
+
*/
|
|
85
|
+
headers?: Record<string, Exclude<JsonLike, object>>;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The json data to attach
|
|
89
|
+
*/
|
|
90
|
+
data?: unknown;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The abort signal
|
|
94
|
+
*/
|
|
95
|
+
signal?: AbortSignal;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* The timeout for this request
|
|
99
|
+
*/
|
|
100
|
+
timeout?: number;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Whether the base url should be versioned.
|
|
104
|
+
* Default: `true`
|
|
105
|
+
*/
|
|
106
|
+
versioned?: boolean;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* REST response wrapper
|
|
111
|
+
*/
|
|
112
|
+
export interface RestResponse<Data> extends Pick<Response, "status" | "statusText" | "ok" | "redirected" | "url"> {
|
|
113
|
+
/**
|
|
114
|
+
* Response headers as a plain object
|
|
115
|
+
*/
|
|
116
|
+
headers: Record<string, string>;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Response data
|
|
120
|
+
*/
|
|
121
|
+
data: Data;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* HTTP status codes
|
|
126
|
+
*/
|
|
127
|
+
export const enum HttpStatusCode {
|
|
128
|
+
/**
|
|
129
|
+
* @deprecated
|
|
130
|
+
*/
|
|
131
|
+
Processing = 102,
|
|
132
|
+
Ok = 200,
|
|
133
|
+
NoContent = 204,
|
|
134
|
+
BadRequest = 400,
|
|
135
|
+
Unauthorized,
|
|
136
|
+
Forbidden = 403,
|
|
137
|
+
NotFound,
|
|
138
|
+
MethodNotAllowed,
|
|
139
|
+
TooManyRequests = 429,
|
|
140
|
+
InternalServerError = 500,
|
|
141
|
+
BadGateway = 502,
|
|
142
|
+
ServiceUnavailable,
|
|
143
|
+
GatewayTimeout,
|
|
144
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lavalink type definitions
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export * from "./REST";
|
|
6
|
+
export type { LavalinkInfo } from "../api/Rest";
|
|
7
|
+
export * from "./Node";
|
|
8
|
+
export * from "./NodeManager";
|
|
9
|
+
|
|
10
|
+
import type { StatsPayload } from "../api/Websocket";
|
|
11
|
+
export * from "../api/Websocket";
|
|
12
|
+
import type { Node } from "../../lavalink/LavalinkConnection";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Node stats event data
|
|
16
|
+
*/
|
|
17
|
+
export interface BaseNodeStats extends StatsPayload {}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Node manager events
|
|
21
|
+
*/
|
|
22
|
+
export interface NodeManagerEvents {
|
|
23
|
+
create: [node: Node];
|
|
24
|
+
destroy: [node: Node];
|
|
25
|
+
connect: [node: Node];
|
|
26
|
+
ready: [node: Node, resumed: boolean, sessionId: string];
|
|
27
|
+
disconnect: [node: Node, reason: { code: number; reason: string }];
|
|
28
|
+
reconnecting: [node: Node];
|
|
29
|
+
error: [node: Node, error: Error];
|
|
30
|
+
raw: [node: Node, payload: unknown];
|
|
31
|
+
nodeInfo: [node: Node, info: unknown];
|
|
32
|
+
}
|