@glade-chat/glade.js 0.1.0
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 +21 -0
- package/README.md +52 -0
- package/package.json +57 -0
- package/src/client/Client.js +355 -0
- package/src/errors/index.js +59 -0
- package/src/gateway/Gateway.js +172 -0
- package/src/gateway/handleDispatch.js +259 -0
- package/src/index.js +66 -0
- package/src/managers/CachedManager.js +95 -0
- package/src/managers/ChannelManager.js +40 -0
- package/src/managers/DMManager.js +43 -0
- package/src/managers/FriendManager.js +89 -0
- package/src/managers/HouseManager.js +44 -0
- package/src/managers/InviteManager.js +46 -0
- package/src/managers/MemberManager.js +41 -0
- package/src/managers/MessageManager.js +69 -0
- package/src/managers/RoleManager.js +65 -0
- package/src/managers/RoomManager.js +80 -0
- package/src/managers/UserManager.js +41 -0
- package/src/rest/REST.js +250 -0
- package/src/rest/Routes.js +85 -0
- package/src/structures/Base.js +70 -0
- package/src/structures/ClientUser.js +142 -0
- package/src/structures/DMChannel.js +85 -0
- package/src/structures/House.js +171 -0
- package/src/structures/Invite.js +83 -0
- package/src/structures/Member.js +148 -0
- package/src/structures/Message.js +176 -0
- package/src/structures/ReactionGroup.js +42 -0
- package/src/structures/Role.js +107 -0
- package/src/structures/Room.js +264 -0
- package/src/structures/User.js +113 -0
- package/src/structures/VoiceState.js +42 -0
- package/src/util/Collection.js +167 -0
- package/src/util/Constants.js +183 -0
- package/src/util/Permissions.js +148 -0
- package/src/util/Util.js +62 -0
- package/types/index.d.ts +784 -0
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,784 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for glade.js — the Node.js library for the Glade (glade.chat)
|
|
3
|
+
* API and realtime gateway.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { EventEmitter } from 'node:events';
|
|
7
|
+
import type { Socket } from 'socket.io-client';
|
|
8
|
+
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
// Primitives & shared types
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
|
|
13
|
+
export type RoomType = 'text' | 'voice' | 'portal';
|
|
14
|
+
export type PresenceStatusType = 'online' | 'idle' | 'dnd' | 'offline';
|
|
15
|
+
export type SettableStatusType = 'online' | 'idle' | 'dnd';
|
|
16
|
+
export type FriendStatusType = 'self' | 'none' | 'friends' | 'incoming' | 'outgoing';
|
|
17
|
+
|
|
18
|
+
export type PermissionFlagName =
|
|
19
|
+
| 'Administrator'
|
|
20
|
+
| 'ManageHouse'
|
|
21
|
+
| 'ManageRoles'
|
|
22
|
+
| 'ManageChannels'
|
|
23
|
+
| 'KickMembers'
|
|
24
|
+
| 'ManageMessages'
|
|
25
|
+
| 'ViewChannels'
|
|
26
|
+
| 'SendMessages'
|
|
27
|
+
| 'Connect';
|
|
28
|
+
|
|
29
|
+
export type PermissionResolvable =
|
|
30
|
+
| PermissionFlagName
|
|
31
|
+
| number
|
|
32
|
+
| PermissionsBitField
|
|
33
|
+
| Array<PermissionFlagName | number | PermissionsBitField>;
|
|
34
|
+
|
|
35
|
+
export interface MessagePayload {
|
|
36
|
+
content: string;
|
|
37
|
+
nonce?: string;
|
|
38
|
+
mentions?: string[];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface ClientOptions {
|
|
42
|
+
/** REST origin, without the version segment. Default `https://api.glade.chat`. */
|
|
43
|
+
rest?: string;
|
|
44
|
+
/** Socket.IO gateway origin. Defaults to `rest` when set, else `https://ws.glade.chat`. */
|
|
45
|
+
gateway?: string;
|
|
46
|
+
/** API version segment. Default `v1`. */
|
|
47
|
+
version?: string;
|
|
48
|
+
/** A pre-obtained access token to log in with. */
|
|
49
|
+
token?: string;
|
|
50
|
+
/** Refresh the access token and retry on a 401. Default `true`. */
|
|
51
|
+
autoRefresh?: boolean;
|
|
52
|
+
/** Ms before token expiry to refresh proactively. Default `60000`. */
|
|
53
|
+
refreshSkewMs?: number;
|
|
54
|
+
/** Cache structures from REST/gateway. Default `true`. */
|
|
55
|
+
cache?: boolean;
|
|
56
|
+
/** Auto-subscribe to cached rooms' realtime events on ready. Default `true`. */
|
|
57
|
+
autoSubscribeRooms?: boolean;
|
|
58
|
+
/** Prefetch the client's Houses (and their rooms/roles) on login. Default `true`. */
|
|
59
|
+
fetchHouses?: boolean;
|
|
60
|
+
/** Prefetch the client's DM channels on login. Default `true`. */
|
|
61
|
+
fetchDMs?: boolean;
|
|
62
|
+
/** Extra socket.io-client options. */
|
|
63
|
+
ws?: Record<string, unknown>;
|
|
64
|
+
/** Emit verbose `debug` events. Default `false`. */
|
|
65
|
+
debug?: boolean;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface RequestTokenOptions {
|
|
69
|
+
handle: string;
|
|
70
|
+
password: string;
|
|
71
|
+
/** Two-factor code, if the account has 2FA enabled. */
|
|
72
|
+
code?: string;
|
|
73
|
+
/** Captcha token, if the deployment requires it. */
|
|
74
|
+
turnstileToken?: string;
|
|
75
|
+
/** Backend REST origin (defaults to the public Glade API). */
|
|
76
|
+
rest?: string;
|
|
77
|
+
/** API version segment. */
|
|
78
|
+
version?: string;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface SessionInfo {
|
|
82
|
+
id: string;
|
|
83
|
+
userAgent: string | null;
|
|
84
|
+
location: string | null;
|
|
85
|
+
createdAt: string;
|
|
86
|
+
lastSeenAt: string;
|
|
87
|
+
current: boolean;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface PermissionOverride {
|
|
91
|
+
id: string;
|
|
92
|
+
roomId: string;
|
|
93
|
+
roleId: string;
|
|
94
|
+
allow: number;
|
|
95
|
+
deny: number;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface VoiceOccupant {
|
|
99
|
+
userId: string;
|
|
100
|
+
muted: boolean;
|
|
101
|
+
deafened: boolean;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// ---------------------------------------------------------------------------
|
|
105
|
+
// Collection
|
|
106
|
+
// ---------------------------------------------------------------------------
|
|
107
|
+
|
|
108
|
+
export class Collection<K, V> extends Map<K, V> {
|
|
109
|
+
first(): V | undefined;
|
|
110
|
+
first(amount: number): V[];
|
|
111
|
+
last(): V | undefined;
|
|
112
|
+
last(amount: number): V[];
|
|
113
|
+
random(): V | undefined;
|
|
114
|
+
find(fn: (value: V, key: K, collection: this) => boolean): V | undefined;
|
|
115
|
+
findKey(fn: (value: V, key: K, collection: this) => boolean): K | undefined;
|
|
116
|
+
filter(fn: (value: V, key: K, collection: this) => boolean): Collection<K, V>;
|
|
117
|
+
map<T>(fn: (value: V, key: K, collection: this) => T): T[];
|
|
118
|
+
some(fn: (value: V, key: K, collection: this) => boolean): boolean;
|
|
119
|
+
every(fn: (value: V, key: K, collection: this) => boolean): boolean;
|
|
120
|
+
reduce<T>(fn: (accumulator: T, value: V, key: K, collection: this) => T, initial?: T): T;
|
|
121
|
+
each(fn: (value: V, key: K, collection: this) => void): this;
|
|
122
|
+
toArray(): V[];
|
|
123
|
+
keyArray(): K[];
|
|
124
|
+
clone(): Collection<K, V>;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// ---------------------------------------------------------------------------
|
|
128
|
+
// Permissions
|
|
129
|
+
// ---------------------------------------------------------------------------
|
|
130
|
+
|
|
131
|
+
export const PermissionFlags: { readonly [K in PermissionFlagName]: number };
|
|
132
|
+
export const ALL_PERMISSIONS: number;
|
|
133
|
+
export const DEFAULT_EVERYONE: number;
|
|
134
|
+
export const CHANNEL_OVERRIDABLE: number;
|
|
135
|
+
|
|
136
|
+
export class PermissionsBitField {
|
|
137
|
+
constructor(bits?: PermissionResolvable);
|
|
138
|
+
bitfield: number;
|
|
139
|
+
static Flags: typeof PermissionFlags;
|
|
140
|
+
static All: number;
|
|
141
|
+
static DefaultEveryone: number;
|
|
142
|
+
static resolve(bits?: PermissionResolvable): number;
|
|
143
|
+
has(permission: PermissionResolvable, checkAdmin?: boolean): boolean;
|
|
144
|
+
any(permission: PermissionResolvable): boolean;
|
|
145
|
+
add(...bits: PermissionResolvable[]): this;
|
|
146
|
+
remove(...bits: PermissionResolvable[]): this;
|
|
147
|
+
toArray(): PermissionFlagName[];
|
|
148
|
+
valueOf(): number;
|
|
149
|
+
toJSON(): PermissionFlagName[];
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// ---------------------------------------------------------------------------
|
|
153
|
+
// Errors
|
|
154
|
+
// ---------------------------------------------------------------------------
|
|
155
|
+
|
|
156
|
+
export class GladeError extends Error {}
|
|
157
|
+
|
|
158
|
+
export class GladeAPIError extends GladeError {
|
|
159
|
+
constructor(opts: { status: number; message: string; method: string; path: string; details?: unknown });
|
|
160
|
+
status: number;
|
|
161
|
+
rawMessage: string;
|
|
162
|
+
method: string;
|
|
163
|
+
path: string;
|
|
164
|
+
details: unknown;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export class GladeGatewayError extends GladeError {
|
|
168
|
+
constructor(message: string, code?: string);
|
|
169
|
+
code: string | null;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// ---------------------------------------------------------------------------
|
|
173
|
+
// REST & Gateway
|
|
174
|
+
// ---------------------------------------------------------------------------
|
|
175
|
+
|
|
176
|
+
export interface RequestOptions {
|
|
177
|
+
method?: string;
|
|
178
|
+
path: string;
|
|
179
|
+
body?: unknown;
|
|
180
|
+
query?: Record<string, unknown>;
|
|
181
|
+
headers?: Record<string, string>;
|
|
182
|
+
auth?: boolean;
|
|
183
|
+
sendCookie?: boolean;
|
|
184
|
+
rawBody?: BodyInit;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export interface UploadResult {
|
|
188
|
+
url: string;
|
|
189
|
+
name: string;
|
|
190
|
+
size: number;
|
|
191
|
+
contentType: string;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export class REST {
|
|
195
|
+
constructor(options?: {
|
|
196
|
+
base?: string;
|
|
197
|
+
version?: string;
|
|
198
|
+
autoRefresh?: boolean;
|
|
199
|
+
onToken?: (token: string) => void;
|
|
200
|
+
debug?: (msg: string) => void;
|
|
201
|
+
});
|
|
202
|
+
base: string;
|
|
203
|
+
version: string;
|
|
204
|
+
autoRefresh: boolean;
|
|
205
|
+
token: string | null;
|
|
206
|
+
refreshCookie: string | null;
|
|
207
|
+
readonly apiBase: string;
|
|
208
|
+
setToken(token: string | null): this;
|
|
209
|
+
setRefreshToken(value: string | null): this;
|
|
210
|
+
request<T = unknown>(opts: RequestOptions): Promise<T>;
|
|
211
|
+
get<T = unknown>(path: string, opts?: Partial<RequestOptions>): Promise<T>;
|
|
212
|
+
post<T = unknown>(path: string, body?: unknown, opts?: Partial<RequestOptions>): Promise<T>;
|
|
213
|
+
patch<T = unknown>(path: string, body?: unknown, opts?: Partial<RequestOptions>): Promise<T>;
|
|
214
|
+
put<T = unknown>(path: string, body?: unknown, opts?: Partial<RequestOptions>): Promise<T>;
|
|
215
|
+
delete<T = unknown>(path: string, opts?: Partial<RequestOptions>): Promise<T>;
|
|
216
|
+
refresh(): Promise<string | null>;
|
|
217
|
+
upload(
|
|
218
|
+
file: Buffer | Uint8Array | Blob,
|
|
219
|
+
opts?: { name?: string; contentType?: string; kind?: 'avatar' | 'attachment' },
|
|
220
|
+
): Promise<UploadResult>;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export class Gateway {
|
|
224
|
+
constructor(opts: {
|
|
225
|
+
url: string;
|
|
226
|
+
getToken: () => string | null;
|
|
227
|
+
refresh: () => Promise<string | null>;
|
|
228
|
+
onDispatch: (event: string, data: any) => void;
|
|
229
|
+
onConnect?: () => void;
|
|
230
|
+
onDisconnect?: (reason: string) => void;
|
|
231
|
+
onError?: (err: Error) => void;
|
|
232
|
+
debug?: (msg: string) => void;
|
|
233
|
+
ws?: Record<string, unknown>;
|
|
234
|
+
maxHandshakeRefresh?: number;
|
|
235
|
+
});
|
|
236
|
+
socket: Socket | null;
|
|
237
|
+
id: string | null;
|
|
238
|
+
readonly connected: boolean;
|
|
239
|
+
connect(): void;
|
|
240
|
+
disconnect(): void;
|
|
241
|
+
send(event: string, ...args: any[]): void;
|
|
242
|
+
request<T = any>(event: string, payload?: any, timeout?: number): Promise<T>;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// ---------------------------------------------------------------------------
|
|
246
|
+
// Structures
|
|
247
|
+
// ---------------------------------------------------------------------------
|
|
248
|
+
|
|
249
|
+
export abstract class Base {
|
|
250
|
+
readonly client: Client;
|
|
251
|
+
id?: string;
|
|
252
|
+
toJSON(): Record<string, unknown>;
|
|
253
|
+
valueOf(): string | undefined;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export class User extends Base {
|
|
257
|
+
id: string;
|
|
258
|
+
handle: string;
|
|
259
|
+
displayName: string;
|
|
260
|
+
avatarUrl: string | null;
|
|
261
|
+
bannerUrl: string | null;
|
|
262
|
+
bio: string | null;
|
|
263
|
+
status: PresenceStatusType;
|
|
264
|
+
bot: boolean;
|
|
265
|
+
badges: string[];
|
|
266
|
+
publicKey: string | null;
|
|
267
|
+
twoFactorEnabled: boolean;
|
|
268
|
+
createdAt: string | null;
|
|
269
|
+
readonly tag: string;
|
|
270
|
+
createDM(): Promise<DMChannel>;
|
|
271
|
+
send(content: string | MessagePayload): Promise<Message>;
|
|
272
|
+
fetch(): Promise<User>;
|
|
273
|
+
toString(): string;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export class ClientUser extends User {
|
|
277
|
+
setPresence(status: SettableStatusType): this;
|
|
278
|
+
edit(data: {
|
|
279
|
+
displayName?: string;
|
|
280
|
+
avatarUrl?: string | null;
|
|
281
|
+
bannerUrl?: string | null;
|
|
282
|
+
bio?: string;
|
|
283
|
+
status?: SettableStatusType;
|
|
284
|
+
publicKey?: string;
|
|
285
|
+
currentPassword?: string;
|
|
286
|
+
newPassword?: string;
|
|
287
|
+
}): Promise<this>;
|
|
288
|
+
setStatus(status: SettableStatusType): Promise<this>;
|
|
289
|
+
setDisplayName(displayName: string): Promise<this>;
|
|
290
|
+
setBio(bio: string): Promise<this>;
|
|
291
|
+
setAvatar(
|
|
292
|
+
avatar: string | Buffer | Uint8Array | Blob | null,
|
|
293
|
+
fileOptions?: { name?: string; contentType?: string },
|
|
294
|
+
): Promise<this>;
|
|
295
|
+
setBanner(
|
|
296
|
+
banner: string | Buffer | Uint8Array | Blob | null,
|
|
297
|
+
fileOptions?: { name?: string; contentType?: string },
|
|
298
|
+
): Promise<this>;
|
|
299
|
+
setPublicKey(publicKey: string): Promise<this>;
|
|
300
|
+
setPassword(currentPassword: string, newPassword: string): Promise<this>;
|
|
301
|
+
fetchSessions(): Promise<SessionInfo[]>;
|
|
302
|
+
revokeSession(sessionId: string): Promise<void>;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export class House extends Base {
|
|
306
|
+
id: string;
|
|
307
|
+
name: string;
|
|
308
|
+
iconUrl: string | null;
|
|
309
|
+
accent: string | null;
|
|
310
|
+
ownerId: string;
|
|
311
|
+
createdAt: string | null;
|
|
312
|
+
rooms: RoomManager;
|
|
313
|
+
members: MemberManager;
|
|
314
|
+
roles: RoleManager;
|
|
315
|
+
invites: InviteManager;
|
|
316
|
+
readonly owner: User | null;
|
|
317
|
+
readonly isOwner: boolean;
|
|
318
|
+
edit(data: { name?: string; iconUrl?: string | null }): Promise<House>;
|
|
319
|
+
setName(name: string): Promise<House>;
|
|
320
|
+
setIcon(iconUrl: string | null): Promise<House>;
|
|
321
|
+
delete(): Promise<void>;
|
|
322
|
+
leave(): Promise<void>;
|
|
323
|
+
createRoom(name: string, options?: { type?: RoomType }): Promise<Room>;
|
|
324
|
+
createRole(data: { name: string; color?: string | null; permissions?: PermissionResolvable }): Promise<Role>;
|
|
325
|
+
createInvite(options?: { expiresInMinutes?: number | null; maxUses?: number | null }): Promise<Invite>;
|
|
326
|
+
fetchMembers(): Promise<Collection<string, Member>>;
|
|
327
|
+
fetchRooms(): Promise<Collection<string, Room>>;
|
|
328
|
+
fetchRoles(): Promise<Collection<string, Role>>;
|
|
329
|
+
fetchInvites(): Promise<Collection<string, Invite>>;
|
|
330
|
+
fetchVoiceStates(): Promise<Array<{ roomId: string; users: VoiceOccupant[] }>>;
|
|
331
|
+
toString(): string;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
export class Room extends Base {
|
|
335
|
+
id: string;
|
|
336
|
+
houseId: string;
|
|
337
|
+
name: string;
|
|
338
|
+
type: RoomType;
|
|
339
|
+
topic: string | null;
|
|
340
|
+
position: number;
|
|
341
|
+
createdAt: string | null;
|
|
342
|
+
messages: MessageManager;
|
|
343
|
+
readonly house: House | null;
|
|
344
|
+
isText(): boolean;
|
|
345
|
+
isVoice(): boolean;
|
|
346
|
+
isPortal(): boolean;
|
|
347
|
+
subscribe(): this;
|
|
348
|
+
unsubscribe(): this;
|
|
349
|
+
send(content: string | MessagePayload): Promise<Message>;
|
|
350
|
+
sendTyping(): this;
|
|
351
|
+
stopTyping(): this;
|
|
352
|
+
fetchMessages(options?: { cursor?: string; limit?: number }): Promise<{ messages: Message[]; nextCursor: string | null }>;
|
|
353
|
+
fetchPins(): Promise<Message[]>;
|
|
354
|
+
edit(data: { name?: string; topic?: string | null }): Promise<Room>;
|
|
355
|
+
setName(name: string): Promise<Room>;
|
|
356
|
+
setTopic(topic: string | null): Promise<Room>;
|
|
357
|
+
clone(): Promise<Room>;
|
|
358
|
+
delete(): Promise<void>;
|
|
359
|
+
fetchPermissionOverrides(): Promise<PermissionOverride[]>;
|
|
360
|
+
setPermissionOverride(
|
|
361
|
+
role: string | Role,
|
|
362
|
+
options: { allow?: PermissionResolvable; deny?: PermissionResolvable },
|
|
363
|
+
): Promise<void>;
|
|
364
|
+
toString(): string;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
export class TextRoom extends Room {}
|
|
368
|
+
export class PortalRoom extends Room {}
|
|
369
|
+
|
|
370
|
+
export class VoiceRoom extends Room {
|
|
371
|
+
join(): Promise<{ selfSocketId: string; participants: Array<{ socketId: string; userId: string; muted: boolean }> }>;
|
|
372
|
+
leave(): this;
|
|
373
|
+
setVoiceState(state: { muted: boolean; deafened?: boolean }): this;
|
|
374
|
+
signal(toSocketId: string, data: unknown): this;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
export function createRoom(client: Client, data: any): Room;
|
|
378
|
+
|
|
379
|
+
export class ReactionGroup {
|
|
380
|
+
readonly client: Client;
|
|
381
|
+
readonly message: Message;
|
|
382
|
+
emoji: string;
|
|
383
|
+
count: number;
|
|
384
|
+
userIds: string[];
|
|
385
|
+
readonly me: boolean;
|
|
386
|
+
readonly users: User[];
|
|
387
|
+
toJSON(): { emoji: string; count: number; userIds: string[] };
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
export class Message extends Base {
|
|
391
|
+
id: string;
|
|
392
|
+
roomId: string | null;
|
|
393
|
+
dmChannelId: string | null;
|
|
394
|
+
houseId: string | null;
|
|
395
|
+
content: string;
|
|
396
|
+
clientNonce: string | null;
|
|
397
|
+
pinned: boolean;
|
|
398
|
+
createdAt: string;
|
|
399
|
+
editedAt: string | null;
|
|
400
|
+
authorId: string;
|
|
401
|
+
reactions: ReactionGroup[];
|
|
402
|
+
readonly author: User | null;
|
|
403
|
+
readonly channel: Room | DMChannel | null;
|
|
404
|
+
readonly room: Room | null;
|
|
405
|
+
readonly createdTimestamp: number | null;
|
|
406
|
+
readonly edited: boolean;
|
|
407
|
+
reply(content: string | MessagePayload): Promise<Message>;
|
|
408
|
+
edit(content: string): Promise<Message>;
|
|
409
|
+
delete(): Promise<Message>;
|
|
410
|
+
pin(): Promise<Message>;
|
|
411
|
+
unpin(): Promise<Message>;
|
|
412
|
+
react(emoji: string): Promise<Message>;
|
|
413
|
+
unreact(emoji: string): Promise<Message>;
|
|
414
|
+
toString(): string;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
export class Member extends Base {
|
|
418
|
+
id: string;
|
|
419
|
+
houseId: string;
|
|
420
|
+
nickname: string | null;
|
|
421
|
+
roleIds: string[];
|
|
422
|
+
status: PresenceStatusType;
|
|
423
|
+
readonly user: User | null;
|
|
424
|
+
readonly house: House | null;
|
|
425
|
+
readonly displayName: string | null;
|
|
426
|
+
readonly isOwner: boolean;
|
|
427
|
+
readonly roles: Collection<string, Role>;
|
|
428
|
+
readonly permissions: PermissionsBitField;
|
|
429
|
+
setRoles(roles: Array<string | Role>): Promise<Member>;
|
|
430
|
+
addRole(...roles: Array<string | Role>): Promise<Member>;
|
|
431
|
+
removeRole(...roles: Array<string | Role>): Promise<Member>;
|
|
432
|
+
toString(): string;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
export class Role extends Base {
|
|
436
|
+
id: string;
|
|
437
|
+
houseId: string;
|
|
438
|
+
name: string;
|
|
439
|
+
color: string | null;
|
|
440
|
+
permissions: PermissionsBitField;
|
|
441
|
+
position: number;
|
|
442
|
+
isDefault: boolean;
|
|
443
|
+
hoist: boolean;
|
|
444
|
+
readonly house: House | null;
|
|
445
|
+
edit(data: { name?: string; color?: string | null; permissions?: PermissionResolvable; hoist?: boolean }): Promise<Role>;
|
|
446
|
+
setName(name: string): Promise<Role>;
|
|
447
|
+
setColor(color: string | null): Promise<Role>;
|
|
448
|
+
setPermissions(permissions: PermissionResolvable): Promise<Role>;
|
|
449
|
+
setHoist(hoist: boolean): Promise<Role>;
|
|
450
|
+
delete(): Promise<void>;
|
|
451
|
+
toString(): string;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
export class DMChannel extends Base {
|
|
455
|
+
id: string;
|
|
456
|
+
participantIds: string[];
|
|
457
|
+
messages: MessageManager;
|
|
458
|
+
readonly participants: User[];
|
|
459
|
+
readonly recipient: User | null;
|
|
460
|
+
isDM(): true;
|
|
461
|
+
send(content: string | MessagePayload): Promise<Message>;
|
|
462
|
+
sendTyping(): this;
|
|
463
|
+
stopTyping(): this;
|
|
464
|
+
fetchMessages(options?: { cursor?: string; limit?: number }): Promise<{ messages: Message[]; nextCursor: string | null }>;
|
|
465
|
+
toString(): string;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
export class Invite extends Base {
|
|
469
|
+
id?: string;
|
|
470
|
+
code: string;
|
|
471
|
+
uses?: number;
|
|
472
|
+
maxUses?: number | null;
|
|
473
|
+
expiresAt: string | null;
|
|
474
|
+
createdAt?: string;
|
|
475
|
+
houseId?: string;
|
|
476
|
+
house?: { id: string; name: string; iconUrl: string | null; accent: string | null };
|
|
477
|
+
inviter?: { handle: string; displayName: string };
|
|
478
|
+
readonly expired: boolean;
|
|
479
|
+
redeem(): Promise<House>;
|
|
480
|
+
delete(): Promise<void>;
|
|
481
|
+
toString(): string;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
export class VoiceState {
|
|
485
|
+
constructor(client: Client, data: { userId: string; muted?: boolean; deafened?: boolean; socketId?: string; roomId?: string });
|
|
486
|
+
readonly client: Client;
|
|
487
|
+
userId: string;
|
|
488
|
+
roomId: string | null;
|
|
489
|
+
socketId: string | null;
|
|
490
|
+
muted: boolean;
|
|
491
|
+
deafened: boolean;
|
|
492
|
+
readonly user: User | null;
|
|
493
|
+
toJSON(): { userId: string; roomId: string | null; socketId: string | null; muted: boolean; deafened: boolean };
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// ---------------------------------------------------------------------------
|
|
497
|
+
// Managers
|
|
498
|
+
// ---------------------------------------------------------------------------
|
|
499
|
+
|
|
500
|
+
export abstract class CachedManager<V> {
|
|
501
|
+
readonly client: Client;
|
|
502
|
+
readonly holds: Function;
|
|
503
|
+
cache: Collection<string, V>;
|
|
504
|
+
resolve(idOrInstance: string | { id: string }): V | null;
|
|
505
|
+
resolveId(idOrInstance: string | { id: string }): string;
|
|
506
|
+
[Symbol.iterator](): IterableIterator<V>;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
export class HouseManager extends CachedManager<House> {
|
|
510
|
+
fetch(id: string, options?: { force?: boolean }): Promise<House>;
|
|
511
|
+
fetch(): Promise<Collection<string, House>>;
|
|
512
|
+
create(name: string): Promise<House>;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
export class ChannelManager extends CachedManager<Room> {
|
|
516
|
+
fetch(id: string, options?: { force?: boolean }): Promise<Room | null>;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
export class RoomManager extends CachedManager<Room> {
|
|
520
|
+
readonly house: House;
|
|
521
|
+
fetch(): Promise<Collection<string, Room>>;
|
|
522
|
+
create(name: string, options?: { type?: RoomType }): Promise<Room>;
|
|
523
|
+
reorder(orderedIds: Array<string | Room>): Promise<Collection<string, Room>>;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
export class UserManager extends CachedManager<User> {
|
|
527
|
+
fetch(id: string, options?: { force?: boolean }): Promise<User>;
|
|
528
|
+
search(query?: string): Promise<User[]>;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
export class MessageManager extends CachedManager<Message> {
|
|
532
|
+
readonly channel: Room | DMChannel;
|
|
533
|
+
readonly isDM: boolean;
|
|
534
|
+
fetch(options?: { cursor?: string; limit?: number }): Promise<{ messages: Message[]; nextCursor: string | null }>;
|
|
535
|
+
fetchPins(): Promise<Message[]>;
|
|
536
|
+
send(content: string | MessagePayload): Promise<Message>;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
export class MemberManager extends CachedManager<Member> {
|
|
540
|
+
readonly house: House;
|
|
541
|
+
fetch(id: string, options?: { force?: boolean }): Promise<Member | null>;
|
|
542
|
+
fetch(): Promise<Collection<string, Member>>;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
export class RoleManager extends CachedManager<Role> {
|
|
546
|
+
readonly house: House;
|
|
547
|
+
readonly everyone: Role | null;
|
|
548
|
+
fetch(): Promise<Collection<string, Role>>;
|
|
549
|
+
create(data: { name: string; color?: string | null; permissions?: PermissionResolvable }): Promise<Role>;
|
|
550
|
+
reorder(orderedIds: Array<string | Role>): Promise<Collection<string, Role>>;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
export class DMManager extends CachedManager<DMChannel> {
|
|
554
|
+
fetch(): Promise<Collection<string, DMChannel>>;
|
|
555
|
+
create(user: string | User): Promise<DMChannel>;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
export class FriendManager {
|
|
559
|
+
readonly client: Client;
|
|
560
|
+
cache: Collection<string, User>;
|
|
561
|
+
fetch(): Promise<Collection<string, User>>;
|
|
562
|
+
fetchPending(): Promise<{ incoming: Array<{ id: string; user: User }>; outgoing: Array<{ id: string; user: User }> }>;
|
|
563
|
+
add(handle: string): Promise<{ accepted: boolean; user: User }>;
|
|
564
|
+
accept(requestId: string): Promise<void>;
|
|
565
|
+
decline(requestId: string): Promise<void>;
|
|
566
|
+
remove(user: string | User): Promise<void>;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
export class InviteManager extends CachedManager<Invite> {
|
|
570
|
+
readonly house: House;
|
|
571
|
+
fetch(): Promise<Collection<string, Invite>>;
|
|
572
|
+
create(options?: { expiresInMinutes?: number | null; maxUses?: number | null }): Promise<Invite>;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
// ---------------------------------------------------------------------------
|
|
576
|
+
// Client & events
|
|
577
|
+
// ---------------------------------------------------------------------------
|
|
578
|
+
|
|
579
|
+
export interface TypingStartData {
|
|
580
|
+
userId: string;
|
|
581
|
+
handle: string;
|
|
582
|
+
user: User | null;
|
|
583
|
+
roomId: string | null;
|
|
584
|
+
dmChannelId: string | null;
|
|
585
|
+
typing: boolean;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
export interface PresenceUpdateData {
|
|
589
|
+
userId: string;
|
|
590
|
+
status: PresenceStatusType;
|
|
591
|
+
user: User | null;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
export interface ReactionUpdateData {
|
|
595
|
+
messageId: string;
|
|
596
|
+
roomId: string | null;
|
|
597
|
+
dmChannelId: string | null;
|
|
598
|
+
reactions: ReactionGroup[] | Array<{ emoji: string; count: number; userIds: string[] }>;
|
|
599
|
+
message: Message | null;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
export interface MentionData {
|
|
603
|
+
houseId: string;
|
|
604
|
+
roomId: string;
|
|
605
|
+
message: Message;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
export interface ClientEvents {
|
|
609
|
+
ready: [client: Client];
|
|
610
|
+
debug: [message: string];
|
|
611
|
+
warn: [message: string];
|
|
612
|
+
error: [error: Error];
|
|
613
|
+
raw: [event: string, data: any];
|
|
614
|
+
disconnect: [reason: string];
|
|
615
|
+
messageCreate: [message: Message];
|
|
616
|
+
messageUpdate: [oldMessage: Message | null, newMessage: Message];
|
|
617
|
+
messageDelete: [message: Message | { id: string; roomId: string | null; dmChannelId: string | null }];
|
|
618
|
+
messagePinUpdate: [data: { roomId: string; messageId: string; pinned: boolean; message: Message | null }];
|
|
619
|
+
messageReactionUpdate: [data: ReactionUpdateData];
|
|
620
|
+
typingStart: [data: TypingStartData];
|
|
621
|
+
presenceUpdate: [data: PresenceUpdateData];
|
|
622
|
+
mention: [data: MentionData];
|
|
623
|
+
roomCreate: [room: Room];
|
|
624
|
+
roomUpdate: [oldRoom: Room | null, newRoom: Room | { houseId: string }];
|
|
625
|
+
roomDelete: [room: Room | { roomId: string; houseId: string }];
|
|
626
|
+
roomsReorder: [data: { houseId: string }];
|
|
627
|
+
houseUpdate: [data: { houseId: string; house: House | null }];
|
|
628
|
+
houseDelete: [house: House | { houseId: string }];
|
|
629
|
+
memberJoin: [data: { houseId: string; userId: string }];
|
|
630
|
+
membersUpdate: [data: { houseId: string }];
|
|
631
|
+
rolesUpdate: [data: { houseId: string }];
|
|
632
|
+
friendRequest: [data: { id: string; user: User | null }];
|
|
633
|
+
friendAccepted: [data: { user: User | null }];
|
|
634
|
+
friendRemoved: [data: { userId: string }];
|
|
635
|
+
voicePeerJoin: [state: VoiceState];
|
|
636
|
+
voicePeerLeave: [data: { socketId: string }];
|
|
637
|
+
voicePeerUpdate: [state: VoiceState];
|
|
638
|
+
voiceRoomState: [data: { roomId: string; users: VoiceState[] }];
|
|
639
|
+
voiceSignal: [data: { fromSocketId: string; fromUserId: string; data: unknown }];
|
|
640
|
+
sessionRevoked: [data: { sessionId: string }];
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
export class Client extends EventEmitter {
|
|
644
|
+
constructor(options?: ClientOptions);
|
|
645
|
+
options: Required<ClientOptions>;
|
|
646
|
+
rest: REST;
|
|
647
|
+
gateway: Gateway;
|
|
648
|
+
user: ClientUser | null;
|
|
649
|
+
ready: boolean;
|
|
650
|
+
houses: HouseManager;
|
|
651
|
+
channels: ChannelManager;
|
|
652
|
+
users: UserManager;
|
|
653
|
+
dms: DMManager;
|
|
654
|
+
friends: FriendManager;
|
|
655
|
+
readonly token: string | null;
|
|
656
|
+
readonly connected: boolean;
|
|
657
|
+
|
|
658
|
+
login(token: string | { token: string }): Promise<string>;
|
|
659
|
+
resetToken(): Promise<string>;
|
|
660
|
+
logout(): Promise<void>;
|
|
661
|
+
destroy(): void;
|
|
662
|
+
fetchInvite(code: string): Promise<Invite>;
|
|
663
|
+
redeemInvite(code: string): Promise<House>;
|
|
664
|
+
fetchSubscription(): Promise<any>;
|
|
665
|
+
static requestToken(opts: RequestTokenOptions): Promise<string>;
|
|
666
|
+
|
|
667
|
+
on<K extends keyof ClientEvents>(event: K, listener: (...args: ClientEvents[K]) => void): this;
|
|
668
|
+
once<K extends keyof ClientEvents>(event: K, listener: (...args: ClientEvents[K]) => void): this;
|
|
669
|
+
off<K extends keyof ClientEvents>(event: K, listener: (...args: ClientEvents[K]) => void): this;
|
|
670
|
+
emit<K extends keyof ClientEvents>(event: K, ...args: ClientEvents[K]): boolean;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
// ---------------------------------------------------------------------------
|
|
674
|
+
// Routes & constants
|
|
675
|
+
// ---------------------------------------------------------------------------
|
|
676
|
+
|
|
677
|
+
export const Routes: {
|
|
678
|
+
register(): string;
|
|
679
|
+
login(): string;
|
|
680
|
+
loginTwoFactor(): string;
|
|
681
|
+
twoFactorSetup(): string;
|
|
682
|
+
twoFactorEnable(): string;
|
|
683
|
+
twoFactorDisable(): string;
|
|
684
|
+
refresh(): string;
|
|
685
|
+
logout(): string;
|
|
686
|
+
tokens(): string;
|
|
687
|
+
tokensReset(): string;
|
|
688
|
+
sessions(): string;
|
|
689
|
+
session(id: string): string;
|
|
690
|
+
authMe(): string;
|
|
691
|
+
forgotPassword(): string;
|
|
692
|
+
resetPassword(): string;
|
|
693
|
+
me(): string;
|
|
694
|
+
userSearch(): string;
|
|
695
|
+
user(id: string): string;
|
|
696
|
+
houses(): string;
|
|
697
|
+
house(houseId: string): string;
|
|
698
|
+
houseLeave(houseId: string): string;
|
|
699
|
+
houseMembers(houseId: string): string;
|
|
700
|
+
memberRoles(houseId: string, userId: string): string;
|
|
701
|
+
houseRoles(houseId: string): string;
|
|
702
|
+
houseRolesReorder(houseId: string): string;
|
|
703
|
+
role(roleId: string): string;
|
|
704
|
+
houseRooms(houseId: string): string;
|
|
705
|
+
houseRoomsReorder(houseId: string): string;
|
|
706
|
+
room(roomId: string): string;
|
|
707
|
+
roomClone(roomId: string): string;
|
|
708
|
+
roomMessages(roomId: string): string;
|
|
709
|
+
roomPins(roomId: string): string;
|
|
710
|
+
roomPin(roomId: string, messageId: string): string;
|
|
711
|
+
roomPermissions(roomId: string): string;
|
|
712
|
+
roomPermission(roomId: string, roleId: string): string;
|
|
713
|
+
houseKeysSelf(houseId: string): string;
|
|
714
|
+
houseKeysMembers(houseId: string): string;
|
|
715
|
+
houseKeys(houseId: string): string;
|
|
716
|
+
dms(): string;
|
|
717
|
+
dmMessages(dmId: string): string;
|
|
718
|
+
houseInvites(houseId: string): string;
|
|
719
|
+
invite(code: string): string;
|
|
720
|
+
inviteRedeem(code: string): string;
|
|
721
|
+
inviteRevoke(id: string): string;
|
|
722
|
+
friends(): string;
|
|
723
|
+
friendsPending(): string;
|
|
724
|
+
friendAccept(id: string): string;
|
|
725
|
+
friendDecline(id: string): string;
|
|
726
|
+
friendRemove(userId: string): string;
|
|
727
|
+
uploads(): string;
|
|
728
|
+
subscription(): string;
|
|
729
|
+
checkout(): string;
|
|
730
|
+
portal(): string;
|
|
731
|
+
};
|
|
732
|
+
|
|
733
|
+
export const Events: {
|
|
734
|
+
readonly Ready: 'ready';
|
|
735
|
+
readonly Debug: 'debug';
|
|
736
|
+
readonly Error: 'error';
|
|
737
|
+
readonly Warn: 'warn';
|
|
738
|
+
readonly Raw: 'raw';
|
|
739
|
+
readonly Connecting: 'connecting';
|
|
740
|
+
readonly Reconnecting: 'reconnecting';
|
|
741
|
+
readonly Disconnect: 'disconnect';
|
|
742
|
+
readonly MessageCreate: 'messageCreate';
|
|
743
|
+
readonly MessageUpdate: 'messageUpdate';
|
|
744
|
+
readonly MessageDelete: 'messageDelete';
|
|
745
|
+
readonly MessagePinUpdate: 'messagePinUpdate';
|
|
746
|
+
readonly MessageReactionUpdate: 'messageReactionUpdate';
|
|
747
|
+
readonly TypingStart: 'typingStart';
|
|
748
|
+
readonly PresenceUpdate: 'presenceUpdate';
|
|
749
|
+
readonly Mention: 'mention';
|
|
750
|
+
readonly RoomCreate: 'roomCreate';
|
|
751
|
+
readonly RoomUpdate: 'roomUpdate';
|
|
752
|
+
readonly RoomDelete: 'roomDelete';
|
|
753
|
+
readonly RoomsReorder: 'roomsReorder';
|
|
754
|
+
readonly HouseUpdate: 'houseUpdate';
|
|
755
|
+
readonly HouseDelete: 'houseDelete';
|
|
756
|
+
readonly MemberJoin: 'memberJoin';
|
|
757
|
+
readonly MembersUpdate: 'membersUpdate';
|
|
758
|
+
readonly RolesUpdate: 'rolesUpdate';
|
|
759
|
+
readonly FriendRequest: 'friendRequest';
|
|
760
|
+
readonly FriendAccepted: 'friendAccepted';
|
|
761
|
+
readonly FriendRemoved: 'friendRemoved';
|
|
762
|
+
readonly VoicePeerJoin: 'voicePeerJoin';
|
|
763
|
+
readonly VoicePeerLeave: 'voicePeerLeave';
|
|
764
|
+
readonly VoicePeerUpdate: 'voicePeerUpdate';
|
|
765
|
+
readonly VoiceRoomState: 'voiceRoomState';
|
|
766
|
+
readonly VoiceSignal: 'voiceSignal';
|
|
767
|
+
readonly SessionRevoked: 'sessionRevoked';
|
|
768
|
+
};
|
|
769
|
+
|
|
770
|
+
export const GatewayDispatch: Record<string, string>;
|
|
771
|
+
export const GatewayCommand: Record<string, string>;
|
|
772
|
+
export const RoomTypes: { readonly Text: 'text'; readonly Voice: 'voice'; readonly Portal: 'portal' };
|
|
773
|
+
export const PresenceStatus: { readonly Online: 'online'; readonly Idle: 'idle'; readonly DnD: 'dnd'; readonly Offline: 'offline' };
|
|
774
|
+
export const FriendStatus: { readonly Self: 'self'; readonly None: 'none'; readonly Friends: 'friends'; readonly Incoming: 'incoming'; readonly Outgoing: 'outgoing' };
|
|
775
|
+
export const DefaultOptions: Omit<ClientOptions, 'token'>;
|
|
776
|
+
export const REFRESH_COOKIE: string;
|
|
777
|
+
export const version: string;
|
|
778
|
+
|
|
779
|
+
// Utilities
|
|
780
|
+
export function generateNonce(): string;
|
|
781
|
+
export function decodeJwt(token: string): Record<string, any> | null;
|
|
782
|
+
export function makeQuery(query?: Record<string, unknown>): string;
|
|
783
|
+
export function trimTrailingSlash(url: string): string;
|
|
784
|
+
export function resolveId(value: string | { id: string }): string;
|