This repository has been archived by the owner on Sep 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
1422 lines (1267 loc) · 28.9 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Generated by dts-bundle v0.7.3
// Dependencies for this module:
// ../phin
// ../events
// ../ws
import type { IJSONResponseOptions } from "phin";
import type { EventEmitter } from "events";
import type WebSocket from "ws";
export enum NodeStatus {
/**
* The websocket is currently connected to the node.
*/
CONNECTED = 0,
/**
* The websocket is connecting to the node.
*/
CONNECTING = 1,
/**
* The websocket is currently disconnected from the node.
*/
DISCONNECTED = 2,
/**
* The websocket is currently trying to reconnect.
*/
RECONNECTING = 3
}
export class Node {
/**
* The identifier for this node.
*/
readonly id: string | number;
/**
* Whether to use wss/https
*/
readonly secure: boolean;
/**
* The configured port of the andesite instance.
*/
readonly port?: number;
/**
* The reconnection options for this node.
*/
readonly reconnection: Required<ReconnectionOptions>;
/**
* The current reconnection try this node is on, or 0 if this player hasn't closed.
*/
currentReconnect: number;
/**
* The resume id for this node.
*/
connectionId?: number;
/**
* When a connection is closed, events will be buffered for up to the timeout specified here.
*/
eventBuffer?: number;
/**
* The metadata of the andesite-instance.
*/
meta?: NodeMetadata;
/**
* The stats of the andesite-instance.
*/
stats?: NodeStats;
/**
* @param manager The manager instance.
* @param options The options for this node.
*/
constructor(manager: PlayerManager, options: Required<NodeOptions>);
/**
* The rest manager for this node.
*/
get rest(): REST;
/**
* The active players for this node.
*/
get players(): Map<string, Player>;
/**
* The host of this andesite instance.
*/
get host(): string;
/**
* The authorization for this andesite instance.
*/
get auth(): string | undefined;
/**
* The current status of this node.
*/
get status(): NodeStatus;
/**
* The manager instance.
*/
get manager(): PlayerManager;
/**
* Penalties of this node. The higher the return number, the larger load the andesite instance is handling.
*/
get penalties(): number;
/**
* Whether the websocket is open / connected.
*/
get connected(): boolean;
/**
* Creates a new player with the provided guildId and transport.
*
* @param guildId The guild id.
* @param transport The transport to use.
*/
createPlayer(guildId: string, transport?: PlayerTransport): Player;
/**
* Destroys a player that is assigned the provided guild id.
*
* @param guildId Guild ID of the player to destroy.
*/
destroyPlayer(guildId: string): Promise<boolean>;
/**
* Send a packet to the andesite instance.
* @param data The packet data
* @param prioritize Whether to prioritize this packet.
*/
sendWs(data: {
op: string;
} & Dictionary, prioritize?: boolean): Promise<void>;
/**
* Configure the event buffer for this session.
* @param timeout Timeout for event buffering, in milliseconds
*/
configureEventBuffer(timeout: number): Promise<number>;
/**
* Closes the websocket connection.
* @returns {Promise<void>}
*/
close(reason?: string): Promise<void>;
/**
* Connect this node to the andesite instance.
*/
connect(userId: string): Promise<this>;
/**
* Reconnects to the andesite instance.
*/
reconnect(): Promise<void>;
/**
* Emits a debug message.
* @param message The debug message.
* @private
*/
debug(message: string): void;
/**
* Processes all of the queued payloads.
* @private
*/
protected processQueue(): Promise<void>;
/**
* Cleans up the websocket listeners.
* @since 1.0.0
* @private
*/
protected cleanUp(): void;
/**
* queues a reconnect.
* @protected
*/
protected queueReconnect(): NodeJS.Timeout;
}
export class REST extends EventEmitter {
/**
* The node instance.
*/
readonly node: Node;
/**
* Request analytics.
*/
requests: {
successful: number;
failed: number;
};
/**
* @param node The node this rest manager belongs to.
*/
constructor(node: Node);
/**
* The base url for all requests.
*/
get baseUrl(): string;
/**
* Returns stats about the andesite instance.
*/
getStats(): Promise<NodeStats>;
/**
* Loads tracks with the provided identifier..
* @param identifier The search identifier.
*/
loadTracks(identifier: string): Promise<LoadTracksResponse>;
/**
* Returns metadata for the provided track.
*
* @param track The track to decode.
*/
decodeTracks(track: string): Promise<TrackInfo>;
/**
* Returns metadata for the provided tracks.
*
* @param track The tracks to decode.
*/
decodeTracks(track: string[]): Promise<TrackInfo[]>;
/**
* @param event
* @param args
*/
emit(event: string, ...args: any[]): boolean;
/**
* Makes a request to the andesite instance.
*
* @param endpoint The endpoint to make a request to.
* @param options Additional request options
*/
make<T>(endpoint: string, options?: RequestOptions): Promise<T>;
}
export type RequestOptions = Omit<IJSONResponseOptions, "url" | "parse"> & {
data?: {
toString(): string;
};
headers?: Dictionary<string>;
};
export abstract class Player extends EventEmitter {
/**
* The ID of the guild this player is for.
*/
readonly guildId: string;
/**
* The ID of the channel this player is connected to.
*/
channelId: string | null;
/**
* Whether this player is connected to a voice channel or not.
*/
connected: boolean;
/**
* The state of this player.
*/
state: PlayerState | null;
/**
* Whether this player is playing or not.
*/
playing: boolean;
/**
* The current track that is playing.
*/
track: string | null;
/**
* The timestamp in which this player started playing.
*/
timestamp: number | null;
/**
* @param node The node instance.
* @param guildId The guild id instance.
*/
protected constructor(node: Node, guildId: string);
/**
* Creates a player.
* @param transport The transport to use. Either "websocket" or "rest".
* @param node The node.
* @param guildId The guild id.
*/
static create(transport: PlayerTransport, node: Node, guildId: string): Player;
/**
* The node this player is hosted on.
*/
get node(): Node;
/**
* The player manager.
*/
get manager(): PlayerManager;
/**
* The current filters that are applied.
*/
get filters(): FilterChain;
/**
*/
on<E extends keyof PlayerEvents>(event: E, listener: (args: PlayerEvents[E]) => void): this;
/**
*/
once<E extends keyof PlayerEvents>(event: E, listener: (args: PlayerEvents[E]) => void): this;
/**
*/
off<E extends keyof PlayerEvents>(event: E, listener: (args: PlayerEvents[E]) => void): any;
/**
*/
emit<E extends keyof PlayerEvents>(event: E, ...args: PlayerEvents[E]): boolean;
/**
* Connects this player to a voice channel.
* @param channel A voice channel object or id.
* @param options Options for self deafening or muting.
*/
connect(channel: string | {
id: string;
} | null, options?: ConnectOptions): Player;
/**
* Disconnects this player from the voice channel.
*/
disconnect(): Player;
/**
* Fetches the player state from the andesite instance.
*/
fetchState(): Promise<PlayerState>;
/**
* Handles an event sent by the andesite instance.
* @param event The received event
*/
handleEvent(event: Event): Promise<boolean>;
/**
* Handles a voice server or state update.
* @param update The voice server or state update.
*/
handleVoiceUpdate(update: DiscordVoiceServer | DiscordVoiceState): Promise<Player>;
/**
* Resumes this player.
*/
resume(): Promise<Player>;
/**
* Plays a track on the guild.
* @param track Base64 encoded lavaplayer track. If null, the player is stopped. Only use null for mixer players, for regular players use stop instead.
* @param options
* @returns {Promise<Player>}
*/
abstract playTrack(track: string | {
track: string;
}, options?: PlayOptions): Promise<Player>;
/**
* Stops playing audio on the guild.
*/
abstract stop(): Promise<Player>;
/**
* Update the pause state of this player.
* @param state Whether or not to pause the player
*/
abstract setPaused(state?: boolean): Promise<Player>;
/**
* Update the track position.
* @param pos Timestamp to set the current track to, in milliseconds
*/
abstract seekTo(pos: number): Promise<Player>;
/**
* Update the volume of this player.
* @param volume Volume to set on the player
*/
abstract setVolume(volume?: number): Promise<Player>;
/**
* Configures the audio filters for the guild
* @param filters The filter map.
*/
abstract setFilters(filters: FilterMap | FilterChain): Promise<Player>;
/**
* Update the player.
* @param payload The player update data.
*/
abstract update(payload: UpdatePlayer): Promise<Player>;
/**
* Destroys this player.
*/
abstract destroy(): Promise<Player>;
/**
* Provides a voice server update event to the andesite instance..
* @param update The voice update payload.
*/
protected abstract sendVoiceServerUpdate(update: VoiceServerUpdate): Promise<Player>;
/**
* Used for general debugging.
* @param message The debug message.
* @protected
*/
protected debug(message: string): void;
}
interface PlayerEvents {
trackStart: [ TrackStartEvent ];
trackStuck: [ TrackStuckEvent ];
trackEnd: [ TrackEndEvent ];
trackException: [ TrackExceptionEvent ];
webSocketClosed: [ WebSocketClosedEvent ];
move: [ string ];
}
export class FilterChain {
/**
* @param player The player instance.
* @param base
*/
constructor(player: Player, base?: FilterMap);
/**
* Runs several checks on a timescale filter.
* @param timescale
*/
static validateTimescale(timescale: Timescale): void;
/**
* Runs several checks on a tremolo filter.
* @param tremolo
*/
static validateTremolo(tremolo: Tremolo): void;
/**
* Runs several checks on a vibrato filter.
* @param vibrato
*/
static validateVibrato(vibrato: Vibrato): void;
/**
* Runs a check on a volume filter.
* @param volume
*/
static validateVolume({ volume }: Volume): void;
/**
* Returns true if the difference between a given value and the default.
* is greater or equal to 0.01;.
*
* @param val Value to check.
* @param def Default value.
*/
static isSet(val: number, def: number): boolean;
/**
* The configured equalizer filter.
*/
getEqualizer(): Equalizer | null;
/**
* Configures the equalizer filter.
* @param bands The gain values for each band.
*/
setEqualizer(...bands: number[]): FilterChain;
/**
* Set the equalizer bands.
* @param bands The bands to supply.
*/
setEqualizer(...bands: Band[]): FilterChain;
/**
* Returns whether the equalizer filter is enabled.
*/
isEqualizerEnabled(): Boolean;
/**
* Get the current volume of the player.
* @param toPercentage Whether to convert the current volume to a percentage (0-100 instead of 0-1)
*/
getVolume(toPercentage?: boolean): number;
/**
* Configure the volume for this player.
* @param volume The volume amount (must be 0-5) or null to reset the volume.
*/
setVolume(volume: number | null): FilterChain;
/**
* The current karaoke configuration.
*/
getKaraoke(): Karaoke | null;
/**
* Configure the karaoke filter.
* @param level
* @param monoLevel
* @param filterBand
*/
setKaraoke(level?: number, monoLevel?: number, filterBand?: number): FilterChain;
/**
* Configure the karaoke filter.
* @param data The karaoke filter data.
*/
setKaraoke(data?: Karaoke): FilterChain;
/**
* The current timescale configuration.
*/
getTimescale(): Timescale | null;
/**
* Configure the timescale filter.
* @param speed The track speed.
* @param pitch The track pitch
* @param rate The track rate
*/
setTimescale(speed?: number, pitch?: number, rate?: number): FilterChain;
/**
* Configure the timescale filter.
* @param data The timescale filter data.
*/
setTimescale(data?: Timescale): FilterChain;
/**
* Check whether the timescale filter is enabled.
*/
isTimescaleEnabled(): boolean;
/**
* The current karaoke configuration.
*/
getTremolo(): Tremolo | null;
/**
* Configure the tremolo filter.
* @param depth
* @param frequency
*/
setTremolo(depth?: number, frequency?: number): FilterChain;
/**
* Configure the tremolo filter.
* @param data The tremolo filter data.
*/
setTremolo(data?: Tremolo): FilterChain;
/**
* Check whether the tremolo filter is enabled.
*/
isTremoloEnabled(): boolean;
/**
* Returns the configured vibrato filter, or null.
*/
getVibrato(): Vibrato | null;
/**
* Configure the tremolo filter.
* @param depth
* @param frequency
*/
setVibrato(depth?: number, frequency?: number): FilterChain;
/**
* Configures the vibrato filter.
* @param data The vibrato filter data.
*/
setVibrato(data?: Vibrato): FilterChain;
/**
* Check whether the vibrato filter is enabled.
*/
isVibratoEnabled(): boolean;
/**
* Applies this filter chain to the player.
*/
apply(): Promise<Player>;
/**
* Get the JSON representation for this filter chain.
*/
toJSON(): FilterMap;
}
export enum ManagerEvent {
NODE_READY = "nodeReady",
NODE_ERROR = "nodeError",
NODE_PACKET = "nodePacket",
NODE_DISCONNECT = "nodeDisconnect",
DEBUG = "debug"
}
export class PlayerManager extends EventEmitter {
/**
* All connected nodes.
*/
readonly nodes: Map<string | number, Node>;
/**
* The send method used for disconnecting/connecting from voice channels.
*/
readonly send: SendMethod;
/**
* The configured user id.
*/
userId: string | null;
/**
* Default reconnection options.
*/
reconnectionDefaults: Required<ReconnectionOptions>;
/**
* The default event buffer to use for all configured nodes.
*/
eventBuffer?: number;
/**
* @param options The player manager options.
*/
constructor(options: PlayerManagerOptions);
/**
* An array of ideal nodes, sorted by the amount of penalties one has.
*/
get ideal(): Node[];
/**
* Every player spanning across each configured node..
*/
get players(): Map<string, Player>;
/**
* Initializes every configured node.
* @param userId The user id to use.
*/
init(userId?: string | null): Promise<void>;
/**
* Creates a new player.
*
* @param guildId The guild id.
* @param options The transport and node to use.
*
* @returns The created player.
*/
createPlayer(guildId: string, options?: CreatePlayerOptions): Player;
/**
* Destroys a player.
*
* @param guildId The Guild ID of the player to destroy.
*
* @returns Whether the player was destroyed.
*/
destroyPlayer(guildId: string): Promise<boolean>;
/**
* Used for providing voice server updates to lavalink.
* @param update The voice server update sent by Discord.
*/
serverUpdate(update: DiscordVoiceServer): Promise<void>;
/**
* Used for providing voice state updates to lavalink
* @param update The voice state update sent by Discord.
*/
stateUpdate(update: DiscordVoiceState): Promise<void>;
}
export interface PlayerManager {
on<E extends keyof PlayerManagerEvents>(event: E, listener: (...args: PlayerManagerEvents[E]) => void): this;
once<E extends keyof PlayerManagerEvents>(event: E, listener: (...args: PlayerManagerEvents[E]) => void): this;
off<E extends keyof PlayerManagerEvents>(event: E, listener: (...args: PlayerManagerEvents[E]) => void): this;
emit<E extends keyof PlayerManagerEvents>(event: E, ...args: PlayerManagerEvents[E]): boolean;
}
interface PlayerManagerEvents {
[ManagerEvent.NODE_READY]: [ Node ];
[ManagerEvent.NODE_DISCONNECT]: [ Partial<Omit<WebSocket.CloseEvent, "reason">> & {
reason: string;
}, Node ];
[ManagerEvent.NODE_PACKET]: [ Dictionary, Node ];
[ManagerEvent.NODE_ERROR]: [ Error | string, Node ];
[ManagerEvent.DEBUG]: [ string ];
}
export namespace Stats {
interface Players {
total: number;
playing: number;
}
interface VirtualMachine {
name: string;
vendor: string;
version: string;
}
interface Spec {
name: string;
vendor: string;
version: string;
}
interface Version {
feature: number;
interim: number;
update: number;
patch: number;
pre: string | null;
build: number;
optional: string;
}
interface Runtime {
uptime: number;
pid: number;
managementSpecVersion: string;
name: string;
vm: VirtualMachine;
spec: Spec;
version: Version;
}
interface OperatingSystem {
processors: number;
name: string;
arch: string;
version: string;
}
interface CPU {
andesite: number;
system: number;
}
interface ClassLoading {
loaded: number;
totalLoaded: number;
unloaded: number;
}
interface Thread {
running: number;
daemon: number;
peak: number;
totalStarted: number;
}
interface Compilation {
name: string;
totalTime: number;
}
interface Heap {
init: number;
used: number;
committed: number;
max: number;
}
interface NonHeap {
init: number;
used: number;
committed: number;
max: number;
}
interface Memory {
pendingFinalization: number;
heap: Heap;
nonHeap: NonHeap;
}
interface GarbageCollector {
name: string;
collectionCount: number;
collectionTime: number;
pools: string[];
}
interface CollectionUsage {
init: number;
used: number;
committed: number;
max: number;
}
interface PeakUsage {
init: number;
used: number;
committed: number;
max: number;
}
interface Usage {
init: number;
used: number;
committed: number;
max: number;
}
interface MemoryPool {
name: string;
type: string;
collectionUsage: CollectionUsage;
collectionUsageThreshold?: number;
collectionUsageThresholdCount?: number;
peakUsage: PeakUsage;
usage: Usage;
usageThreshold?: number;
usageThresholdCount?: number;
managers: string[];
}
interface MemoryManager {
name: string;
pools: string[];
}
interface FrameStatistic {
user: string;
guild: string;
success: number;
loss: number;
}
}
export interface NodeStats {
players: Stats.Players;
runtime: Stats.Runtime;
os: Stats.OperatingSystem;
cpu: Stats.CPU;
classLoading: Stats.ClassLoading;
thread: Stats.Thread;
compilation: Stats.Compilation;
memory: Stats.Memory;
gc: Stats.GarbageCollector[];
memoryPools: Stats.MemoryPool[];
memoryManagers: Stats.MemoryManager[];
frameStats: Stats.FrameStatistic[];
}
export interface NodeMetadata {
/**
* List of plugins loaded.
*/
loadedPlugins: string[];
/**
* Region defined in the config.
*/
nodeRegion: string;
/**
* Revision version of the node.
*/
versionRevision: string;
/**
* List of sources enabled in the config.
*/
enabledSources: string[];
/**
* Commit hash of the node.
*/
versionCommit: string;
/**
* Build number provided by the CI
*/
versionBuild: number;
/**
* Major version of the node.
*/
versionMajor: string;
/**
* Minor version of the node.
*/
versionMinor: string;
/**
* Version of the node.
*/
version: string;
/**
* ID defined in the config.
*/
nodeId: string;
}
export interface Equalizer {
/**
* Array of bands to configure.
*/
bands: Band[];
}
export interface Band {
/**
* Band number to configure
*/
band: number;
/**
* Value to set for the band.
* @default 0
*/
gain?: number;
}
export interface Karaoke {
/**
* @default 1
*/
level?: number;
/**
* @default 1
*/
monoLevel?: number;
/**
* @default 220
*/
filterBand?: number;
/**
* @default 100
*/
filterWidth?: number;
}
export interface Volume {
volume: number;
}
export interface Timescale {
/**
* Speed to play music at.
* @default 1
*/
speed?: number;
/**
* Pitch to set.
* @default 1
*/
pitch?: number;
/**
* Rate to set.
* @default 1
*/
rate?: number;
}
export interface Tremolo {
/**
* @default 2
*/
frequency?: number;
/**
* @default 0.5
*/
depth?: number;
}
export interface Vibrato {
/**
* @default 2
*/
frequency?: number;
/**
* @default 0.5
*/
depth?: number;
}
export interface StackFrame {
/**
* Name of the class loader.
*/
classLoader: string | null;
/**