forked from shipgirlproject/Shoukaku
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
305 lines (263 loc) · 10.3 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
declare module 'shoukaku' {
import { EventEmitter } from "events";
import { Client as DiscordClient, Base64String, Guild } from 'discord.js';
export const version: string;
export class ShoukakuError extends Error {
constructor(message: string);
public name: string;
}
export class ShoukakuTimeout extends Error {
constructor(message: string);
public name: string;
}
export class ShoukakuUtil {
public static mergeDefault(def: Object, given: Object): Object;
public static searchType(string: string): string;
}
export class ShoukakuTrackList {
type: string;
playlistName?: string;
tracks: Array<ShoukakuTrack>;
}
export class ShoukakuTrack {
track: string;
info: {
identifier?: string;
isSeekable?: boolean;
author?: string;
length?: number;
isStream?: boolean;
position?: number;
title?: string;
uri?: string;
};
}
export interface EqualizerBand {
band: number;
gain: number;
}
export type Source = 'youtube' | 'soundcloud';
export enum ShoukakuStatus {
CONNECTING = 'CONNECTING',
CONNECTED = 'CONNECTED',
DISCONNECTING = 'DISCONNECTING',
DISCONNECTED = 'DISCONNECTED',
}
export interface ShoukakuNodeStats {
playingPlayers: number;
op: 'stats';
memory: {
reservable: number;
used: number;
free: number;
allocated: number;
};
frameStats: {
sent: number;
deficit: number;
nulled: number;
};
players: number;
cpu: {
cores: number;
systemLoad: number;
lavalinkLoad: number;
};
uptime: number;
}
export interface ShoukakuJoinOptions {
guildID: string;
voiceChannelID: string;
mute?: boolean;
deaf?: boolean;
}
export interface ShoukakuPlayOptions {
noReplace?: boolean,
startTime?: boolean | number;
endTime?: boolean | number;
}
export interface ShoukakuOptions {
resumable?: boolean;
resumableTimeout?: number;
reconnectTries?: number;
moveOnDisconnect?: boolean;
restTimeout?: number;
}
export interface ShoukakuNodeOptions {
name: string;
host: string;
port: number;
auth: string;
}
class ShoukakuConstants {
static ShoukakuStatus: ShoukakuStatus;
static ShoukakuNodeStats: ShoukakuNodeStats;
static ShoukakuJoinOptions: ShoukakuJoinOptions;
static ShoukakuPlayOptions: ShoukakuPlayOptions;
static ShoukakuOptions: ShoukakuOptions;
static ShoukakuNodeOptions: ShoukakuNodeOptions;
static ShoukakuNodes: Array<ShoukakuNodeOptions>;
}
export { ShoukakuConstants as Constants };
export interface Reason {
op: string;
reason: string;
code: number;
byRemote: boolean;
type: string;
guildId: string;
}
export interface PlayerUpdate {
op: "playerUpdate";
guildId: string;
state: {
time: number;
position: number;
}
}
export class ShoukakuRest {
constructor(host: string, port: string, auth: string, timeout: number);
private auth: string;
public timeout: number;
public url: string;
public resolve(identifier: string, search: Source): Promise<ShoukakuTrackList | null>;
public decode(track: Base64String): Promise<Object>;
public getRoutePlannerStatus(): Promise<Object>;
public unmarkFailedAddress(address: string): Promise<number>;
public unmarkAllFailedAddress(): Promise<number>;
private _getFetch(url: string): Promise<JSON>;
private _postFetch(url: string, body: Object): Promise<number>;
}
export interface ShoukakuPlayer {
on(event: 'end', listener: (reason: Reason) => void): this;
on(event: 'error', listener: (err: ShoukakuError | Error) => void): this;
on(event: 'nodeDisconnect', listener: (name: string) => void): this;
on(event: 'resumed', listener: () => void): this;
on(event: 'playerUpdate', listener: (data: PlayerUpdate) => void): this;
on(event: 'closed' | 'trackException', listener: (data: unknown) => void): this;
once(event: 'end', listener: (reason: Reason) => void): this;
once(event: 'error', listener: (err: ShoukakuError | Error) => void): this;
once(event: 'nodeDisconnect', listener: (name: string) => void): this;
once(event: 'resumed', listener: () => void): this;
once(event: 'playerUpdate', listener: (data: PlayerUpdate) => void): this;
once(event: 'closed' | 'trackException', listener: (data: unknown) => void): this;
off(event: 'end', listener: (reason: Reason) => void): this;
off(event: 'error', listener: (err: ShoukakuError | Error) => void): this;
off(event: 'nodeDisconnect', listener: (name: string) => void): this;
off(event: 'resumed', listener: () => void): this;
off(event: 'playerUpdate', listener: (data: PlayerUpdate) => void): this;
off(event: 'closed' | 'trackException', listener: (data: unknown) => void): this;
}
export class ShoukakuPlayer extends EventEmitter {
constructor(node: ShoukakuSocket, guild: Guild);
public voiceConnection: ShoukakuLink;
public track: string | null;
public paused: boolean;
public volume: number;
public bands: EqualizerBand[];
public position: number;
private connect(options: unknown, callback:(error: ShoukakuError | Error | null, player: ShoukakuPlayer) => void): void;
public disconnect(): void;
public moveToNode(name: string): Promise<void>;
public playTrack(track: string | ShoukakuTrack, options?: ShoukakuPlayOptions): Promise<boolean>;
public stopTrack(): Promise<boolean>;
public setPaused(pause?: boolean): Promise<boolean>;
public setEqualizer(bands: EqualizerBand[]): Promise<boolean>;
public setVolume(volume: number): Promise<boolean>;
public seekTo(position: number): Promise<boolean>;
private _listen(event: string, data: unknown): void;
private _resetPlayer(): void;
private _resume(): Promise<void>;
}
export class ShoukakuLink {
constructor(node: ShoukakuSocket, player: ShoukakuPlayer, guild: Guild);
public node: ShoukakuSocket;
public player: ShoukakuPlayer;
public guildID: string;
public shardID: number;
public userID: string;
public sessionID: string | null;
public voiceChannelID: string | null;
public selfMute: boolean;
public selfDeaf: boolean;
public state: ShoukakuStatus;
private lastServerUpdate: unknown | null;
private _callback: (err: ShoukakuError | Error | null, player: ShoukakuPlayer) => void | null;
private _timeout: number | null;
private stateUpdate(data: unknown);
private serverUpdate(data: unknown);
public attemptReconnect(): Promise<ShoukakuPlayer>;
private _connect(d: unknown, callback: (err: ShoukakuError | Error | null, player: ShoukakuPlayer) => void);
private _disconnect(): void;
private _move(): Promise<void>;
private _sendDiscordWS(d: unknown): void;
private _clearVoice(): void;
private _destroy(): Promise<boolean>;
private _voiceUpdate(): Promise<boolean>;
private _nodeDisconnected(): void;
}
export class ShoukakuSocket {
constructor(shoukaku: Shoukaku, node: ShoukakuOptions);
public shoukaku: Shoukaku;
public players: Map<string, ShoukakuPlayer>;
public rest: ShoukakuRest;
public state: ShoukakuStatus;
public stats: ShoukakuNodeStats;
public reconnectAttempts: number;
public name: string;
public url: string;
private auth: string;
private resumed: boolean;
private cleaner: boolean;
private packetRouter: unknown;
private eventRouter: unknown;
private resumable: boolean;
private resumableTimeout: number;
public penalties: number;
public connect(id: string, shardCount: number, resumable: boolean | string): void;
public joinVoiceChannel(options: ShoukakuJoinOptions): Promise<ShoukakuPlayer>;
public leaveVoiceChannel(guildID: string): void;
private send(data: unknown): Promise<boolean>;
private _configureResuming(): Promise<boolean>;
private _executeCleaner(): Promise<void>;
private _upgrade(response: unknown): void;
private _open(): void;
private _message(message: string): void;
private _error(error: Error): void;
private _close(code: number, reason: string): void;
}
export interface Shoukaku {
on(event: 'debug', listener: (name: string, data: unknown) => void): this;
on(event: 'error', listener: (name: string, error: ShoukakuError | Error) => void): this;
on(event: 'ready', listener: (name: string, reconnect: boolean) => void): this;
on(event: 'close', listener: (name: string, code: number, reason: string | null) => void): this;
on(event: 'disconnected', listener: (name: string, reason: string | null) => void): this;
once(event: 'debug', listener: (name: string, data: unknown) => void): this;
once(event: 'error', listener: (name: string, error: ShoukakuError | Error) => void): this;
once(event: 'ready', listener: (name: string, reconnect: boolean) => void): this;
once(event: 'close', listener: (name: string, code: number, reason: string | null) => void): this;
once(event: 'disconnected', listener: (name: string, reason: string | null) => void): this;
off(event: 'debug', listener: (name: string, data: unknown) => void): this;
off(event: 'error', listener: (name: string, error: ShoukakuError | Error) => void): this;
off(event: 'ready', listener: (name: string, reconnect: boolean) => void): this;
off(event: 'close', listener: (name: string, code: number, reason: string | null) => void): this;
off(event: 'disconnected', listener: (name: string, reason: string | null) => void): this;
}
export class Shoukaku extends EventEmitter {
constructor(client: DiscordClient, nodes: ShoukakuNodeOptions[], options: ShoukakuOptions);
public client: DiscordClient;
public id: string | null;
public shardCount: number | null;
public nodes: Map<string, ShoukakuSocket>;
public players: Map<string, ShoukakuPlayer>;
public totalPlayers: number;
private options: ShoukakuOptions;
private rawRouter: unknown;
public addNode(nodeOptions: ShoukakuNodeOptions): void;
public removeNode(name: string, reason?: string): void;
public getNode(name?: string): ShoukakuSocket;
public getPlayer(guildId: string): ShoukakuPlayer | null;
private _ready(name: string, resumed: boolean): void;
private _close(name: string, code: number, reason: string): void;
}
}