forked from discordjs/RPC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
483 lines (439 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
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
import { EventEmitter } from "events";
export type Listener = (...args: any[]) => void;
export function register(id: string): boolean;
export type eventNames = "ready" | "connected" | "disconnected" | string;
export type RPCEvents =
| "CURRENT_USER_UPDATE"
| "GUILD_STATUS"
| "GUILD_CREATE"
| "CHANNEL_CREATE"
| "RELATIONSHIP_UPDATE"
| "VOICE_CHANNEL_SELECT"
| "VOICE_STATE_CREATE"
| "VOICE_STATE_DELETE"
| "VOICE_STATE_UPDATE"
| "VOICE_SETTINGS_UPDATE"
| "VOICE_SETTINGS_UPDATE_2"
| "VOICE_CONNECTION_STATUS"
| "SPEAKING_START"
| "SPEAKING_STOP"
| "GAME_JOIN"
| "GAME_SPECTATE"
| "ACTIVITY_JOIN"
| "ACTIVITY_JOIN_REQUEST"
| "ACTIVITY_SPECTATE"
| "ACTIVITY_INVITE"
| "NOTIFICATION_CREATE"
| "MESSAGE_CREATE"
| "MESSAGE_UPDATE"
| "MESSAGE_DELETE"
| "LOBBY_DELETE"
| "LOBBY_UPDATE"
| "LOBBY_MEMBER_CONNECT"
| "LOBBY_MEMBER_DISCONNECT"
| "LOBBY_MEMBER_UPDATE"
| "LOBBY_MESSAGE"
| "CAPTURE_SHORTCUT_CHANGE"
| "OVERLAY"
| "OVERLAY_UPDATE"
| "ENTITLEMENT_CREATE"
| "ENTITLEMENT_DELETE"
| "USER_ACHIEVEMENT_UPDATE"
| "READY"
| "ERROR";
export class BaseClient extends EventEmitter {}
/**
* The main hub for interacting with Discord RPC
*/
export class Client extends BaseClient {
/**
* @param options Options for the client.
* You must provide a transport
*/
constructor(options: RPCClientOptions);
/**
* Application used in this client
*/
application?: ClientApplication;
/**
* User used in this application
*/
user?: User;
/**
* Search and connect to RPC
*/
connect(clientId: string): Promise<Client>;
/**
* Performs authentication flow. Automatically calls Client#connect if needed.
* @param options Options for authentication.
* At least one property must be provided to perform login.
* @example client.login({ clientId: '1234567', clientSecret: 'abcdef123' });
*/
login(options?: RPCLoginOptions): Promise<this>;
/**
* Fetch a guild
* @param id Guild ID
* @param timeout Timeout request
*/
getGuild(id: Snowflake, timeout?: number): Promise<Guild>;
/**
* Fetch all guilds
* @param timeout Timeout request
*/
getGuilds(timeout?: number): Promise<Guild[]>;
/**
* Get a channel
* @param id Channel ID
* @param timeout Timeout request
*/
getChannel(id: Snowflake, timeout?: number): Promise<Channel>;
/**
* Get all channels
* @param id Guild ID
* @param timeout Timeout request
*/
getChannels(id?: Snowflake, timeout?: number): Promise<Channel[]>;
/**
* Tell discord which devices are certified
* @param devices Certified devices to send to discord
*/
setCertifiedDevices(devices: CertifiedDevice[]): Promise<null>;
/**
* Set the voice settings for a user, by id
* @param id ID of the user to set
* @param settings Settings
*/
setUserVoiceSettings(
id: Snowflake,
settings: UserVoiceSettings
): Promise<any>;
/**
* Move the user to a voice channel
* @param id ID of the voice channel
* @param options Options
*/
selectVoiceChannel(
id: Snowflake,
options?: {
/**
* Timeout for the command
*/
timeout?: number | undefined;
/**
* Force this move. This should only be done if you
* have explicit permission from the user.
*/
force?: boolean | undefined;
}
): Promise<Channel>;
/**
* Move the user to a text channel
* @param id ID of the voice channel
* @param options Options
*/
selectTextChannel(
id: Snowflake,
options?: {
/**
* Timeout for the command
*/
timeout?: number;
}
): Promise<Channel>;
/**
* Get current voice settings
*/
getVoiceSettings(): Promise<VoiceSettings>;
/**
* Set current voice settings, overriding the current settings until this session disconnects.
* This also locks the settings for any other rpc sessions which may be connected.
* @param args Settings
*/
setVoiceSettings(args: VoiceSettings): Promise<any>;
/**
* Capture a shortcut using the client
* The callback takes (key, stop) where `stop` is a function that will stop capturing.
* This `stop` function must be called before disconnecting or else the user will have
* to restart their client.
* @param callback Callback handling keys
*/
captureShortcut(
callback: (
key: Array<{ type: number; code: number; name: string }>,
stop: () => void
) => void
): Promise<() => void>;
/**
* Sets the presence for the logged in user.
* @param args The rich presence to pass.
* @param pid The application's process ID. Defaults to the executing process' PID.
*/
setActivity(args?: Presence, pid?: number): Promise<any>;
/**
* Clears the currently set presence, if any. This will hide the "Playing X" message
* displayed below the user's name.
* @param pid The application's process ID. Defaults to the executing process' PID.
*/
clearActivity(pid?: number): Promise<any>;
/**
* Invite a user to join the game the RPC user is currently playing
* @param user The user to invite
*/
sendJoinInvite(user: User | User["id"]): Promise<any>;
/**
* Request to join the game the user is playing
* @param user The user whose game you want to request to join
*/
sendJoinRequest(user: User | User["id"]): Promise<any>;
/**
* Reject a join request from a user
* @param user The user whose request you wish to reject
*/
closeJoinRequest(user: User | User["id"]): Promise<any>;
createLobby(type: string, capacity: number, metadata: any): Promise<any>;
updateLobby(
lobby: { id: string } | string,
options?: {
type: string;
owner: { id: string } | string;
capacity: number;
metadata: any;
}
): Promise<any>;
deleteLobby(lobby: { id: string } | string): Promise<any>;
connectToLobby(id: string, secret: string): Promise<any>;
sendToLobby(lobby: { id: string } | string, data: any): Promise<any>;
disconnectFromLobby(lobby: { id: string } | string): Promise<any>;
updateLobbyMember(
lobby: { id: string } | string,
user: { id: string } | string,
metadata: any
): Promise<any>;
/**
* Subscribe to an event
* @param event Name of event e.g. `MESSAGE_CREATE`
* @param args Args for event e.g. `{ channel_id: '1234' }`
*/
subscribe(event: RPCEvents, args: any): Promise<Subscription>;
/**
* Destroy the client
*/
destroy(): Promise<void>;
on(event: eventNames, listener: Listener): this;
once(event: eventNames, listener: Listener): this;
off(event: eventNames, listener: Listener): this;
}
export interface ClientApplication {
description: string;
icon: string;
id: string;
rpc_origins: string[];
name: string;
}
export interface User {
username?: string;
discriminator?: string;
id: string;
avatar?: string;
}
export type Snowflake = string;
export interface ClientOptions {
[option: string]: any;
}
export interface RPCClientOptions extends ClientOptions {
/**
* RPC transport. one of `ipc` or `websocket`
*/
transport: "ipc" | "websocket";
}
export interface RPCLoginOptions {
/**
* Client ID
*/
clientId: string;
/**
* Client secret
*/
clientSecret?: string | undefined;
/**
* Access token
*/
accessToken?: string | undefined;
/**
* RPC token
*/
rpcToken?: string | undefined;
/**
* Token endpoint
*/
redirectUri?: string | undefined;
/**
* Scopes to authorize with
*/
scopes?: string[] | undefined;
prompt?: "none" | "consent" | undefined;
}
export interface Guild {
id: string;
name: string;
icon_url?: string | undefined;
members?: any[] | undefined;
}
export interface Subscription {
unsubscribe(): Promise<boolean>;
}
export interface Channel {
id: string;
name: string;
/**
* Guild text: 0, Guild voice: 2, DM: 1, Group DM: 3
*/
type: number;
guild_id?: string | undefined;
/**
* (text)
*/
topic?: string | undefined;
/**
* (voice)
*/
bitrate?: number | undefined;
/**
* (voice) 0 if none
*/
user_limit?: number | undefined;
/**
* (text)
*/
position?: number | undefined;
/**
* (voice) https://discordapp.com/developers/docs/resources/voice#voice-state-object
*/
voice_states?: any[] | undefined;
/**
* (text) https://discordapp.com/developers/docs/resources/channel#message-object
*/
messages?: any[] | undefined;
}
export interface CertifiedDevice {
/**
* One of `AUDIO_INPUT`, `AUDIO_OUTPUT`, `VIDEO_INPUT`
*/
type: "AUDIO_INPUT" | "AUDIO_OUTPUT" | "VIDEO_INPUT";
/**
* This device's Windows UUID
*/
uuid: string;
/**
* Vendor information
*/
vendor: {
/**
* Vendor's name
*/
name: string;
/**
* Vendor's url
*/
url: string;
};
/**
* Model information
*/
model: {
/**
* Model's name
*/
name: string;
/**
* Model's url
*/
url: string;
};
/**
* Array of related product's Windows UUIDs
*/
related: string[];
/**
* If the device has echo cancellation
*/
echoCancellation: boolean;
/**
* If the device has noise suppression
*/
noiseSuppression: boolean;
/**
* If the device has automatic gain control
*/
automaticGainControl: boolean;
/**
* If the device has a hardware mute
*/
hardwareMute: boolean;
}
export interface UserVoiceSettings {
/**
* ID of the user these settings apply to
*/
id: Snowflake;
/**
* Pan settings, an object with `left` and `right` set between
* 0.0 and 1.0, inclusive
*/
pan?: { left: number; right: number } | undefined;
/**
* The volume
*/
volume?: number | undefined;
/**
* If the user is muted
*/
mute?: boolean | undefined;
}
export interface VoiceSettings {
automaticGainControl: boolean;
echoCancellation: boolean;
noiseSuppression: boolean;
qos: boolean;
silenceWarning: boolean;
deaf: boolean;
mute: boolean;
input?:
| {
device: string;
volume: number;
}
| undefined;
output?:
| {
device: string;
volume: number;
}
| undefined;
mode?:
| {
autoThreshold: boolean;
threshold: number;
shortcut: Array<{ type: number; code: number; name: string }>;
delay: number;
}
| undefined;
}
export interface Presence {
state?: string | undefined;
details?: string | undefined;
startTimestamp?: number | Date | undefined;
endTimestamp?: number | Date | undefined;
largeImageKey?: string | undefined;
largeImageText?: string | undefined;
smallImageKey?: string | undefined;
smallImageText?: string | undefined;
instance?: boolean | undefined;
partyId?: string | undefined;
partySize?: number | undefined;
partyMax?: number | undefined;
matchSecret?: string | undefined;
spectateSecret?: string | undefined;
joinSecret?: string | undefined;
buttons?: Array<{ label: string; url: string }> | undefined;
}