guilds.js 0.0.2 → 0.0.4

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/dist/index.d.cts CHANGED
@@ -1,5 +1,61 @@
1
+ declare namespace api_types_d_exports {
2
+ export { AvatarDecorationData, Collectible, Nameplate, PrimaryGuild, User$1 as User };
3
+ }
4
+ interface AvatarDecorationData {
5
+ asset: string;
6
+ sku_id: string;
7
+ }
8
+ interface Collectible {
9
+ nameplate?: Nameplate;
10
+ }
11
+ interface Nameplate {
12
+ sku_id: string;
13
+ asset: string;
14
+ label: string;
15
+ palette: string;
16
+ }
17
+ interface PrimaryGuild {
18
+ badge?: string;
19
+ identity_enabled?: boolean;
20
+ identity_guild_id?: string;
21
+ tag?: string;
22
+ }
23
+ interface User$1 {
24
+ accent_color?: number;
25
+ avatar?: string;
26
+ avatar_decoration_data?: AvatarDecorationData;
27
+ banner?: string;
28
+ bot?: boolean;
29
+ collectibles?: Collectible;
30
+ discriminator: string;
31
+ email?: string;
32
+ flags?: number;
33
+ global_name: string;
34
+ id: string;
35
+ locale?: string;
36
+ mfa_enabled?: boolean;
37
+ premium_type?: number;
38
+ primary_guild?: PrimaryGuild;
39
+ public_flags?: number;
40
+ system?: boolean;
41
+ username: string;
42
+ verified?: boolean;
43
+ }
44
+ //#endregion
45
+ //#region src/utils/color-convert.d.ts
46
+ /**
47
+ * Converts an integer color to a hex color string
48
+ * @returns Hex string or null
49
+ */
50
+ declare function colorIntToHex(color: number | null, addHashSymbol?: boolean): string | null;
51
+ /**
52
+ * Converts a hex color string to an integer color
53
+ * @returns Color integer or null
54
+ */
55
+ declare function hexToColorInt(hex: string | null): number | null;
56
+ //#endregion
1
57
  //#region src/utils/constants.d.ts
2
- declare const activityTypes: {
58
+ declare const ActivityTypes: {
3
59
  readonly Competing: 5;
4
60
  readonly Custom: 4;
5
61
  readonly Listening: 2;
@@ -8,99 +64,284 @@ declare const activityTypes: {
8
64
  readonly Watching: 3;
9
65
  };
10
66
  declare const baseApiUrl = "https://discord.com/api/v10";
11
- declare const errorCodes: readonly ["ClientIntentsError", "ClientPropsError", "ClientTokenError", "DiscordAPIError", "GatewayError", "WebSocketError"];
12
- declare const opCodes: {
13
- readonly Dispatch: 0;
14
- readonly Heartbeat: 1;
15
- readonly HeartbeatACK: 11;
16
- readonly Hello: 10;
17
- readonly Identify: 2;
18
- readonly InvalidSession: 9;
19
- readonly PresenceUpdate: 3;
20
- readonly Reconnect: 7;
21
- readonly RequestGuildMembers: 8;
22
- readonly RequestSoundboardSounds: 12;
23
- readonly Resume: 6;
67
+ declare const GatewayIntents: {
68
+ readonly AutoModerationConfiguration: number;
69
+ readonly AutoModerationExecution: number;
70
+ readonly DirectMessagePolls: number;
71
+ readonly DirectMessageReactions: number;
72
+ readonly DirectMessages: number;
73
+ readonly DirectMessageTyping: number;
74
+ readonly GuildExpressions: number;
75
+ readonly GuildIntegrations: number;
76
+ readonly GuildInvites: number;
77
+ readonly GuildMembers: number;
78
+ readonly GuildMessagePolls: number;
79
+ readonly GuildMessageReactions: number;
80
+ readonly GuildMessages: number;
81
+ readonly GuildMessageTyping: number;
82
+ readonly GuildModeration: number;
83
+ readonly GuildPresences: number;
84
+ readonly Guilds: number;
85
+ readonly GuildScheduledEvents: number;
86
+ readonly GuildVoiceStates: number;
87
+ readonly GuildWebhooks: number;
88
+ readonly MessageContent: number;
89
+ };
90
+ declare const GatewayOpcodes: {
91
+ /** Receive */readonly Dispatch: 0; /** Send or Receive */
92
+ readonly Heartbeat: 1; /** Receive */
93
+ readonly HeartbeatACK: 11; /** Receive */
94
+ readonly Hello: 10; /** Send */
95
+ readonly Identify: 2; /** Receive */
96
+ readonly InvalidSession: 9; /** Send */
97
+ readonly PresenceUpdate: 3; /** Receive */
98
+ readonly Reconnect: 7; /** Send */
99
+ readonly RequestGuildMembers: 8; /** Send */
100
+ readonly RequestSoundboardSounds: 12; /** Send */
101
+ readonly Resume: 6; /** Send */
24
102
  readonly VoiceStateUpdate: 3;
25
103
  };
26
104
  //#endregion
105
+ //#region src/utils/endpoints.d.ts
106
+ /** Discord's API v10 endpoints */
107
+ declare const Endpoints: {
108
+ /**
109
+ * - GET `/gateway`
110
+ */
111
+ gateway(): "https://discord.com/api/v10/gateway";
112
+ /**
113
+ * - GET `/gateway/bot`
114
+ * - POST `/gateway/bot`
115
+ */
116
+ gatewayBot(): "https://discord.com/api/v10/gateway/bot";
117
+ /**
118
+ * - GET `/users/{userId}`
119
+ * @param userId User ID (default: "@me")
120
+ */
121
+ user(userId?: string): `https://discord.com/api/v10/users/${string}`;
122
+ };
123
+ //#endregion
124
+ //#region src/utils/parse-intents.d.ts
125
+ /**
126
+ * Parse intents into bitfield
127
+ * @param intents Intents resolvable
128
+ * @returns Parsed intents as a bitfield
129
+ */
130
+ declare function parseIntents(intents: IntentsResolvable): number;
131
+ //#endregion
27
132
  //#region src/classes/EventHandler.d.ts
133
+ /** Class representing a type-safe EventEmitter */
28
134
  declare class EventHandler<Events extends Record<string, any[]>> {
29
135
  #private;
136
+ /**
137
+ * Add a new event listener
138
+ * @param event Event name
139
+ * @param listener Listener callback
140
+ */
30
141
  on<K extends keyof Events>(event: K, listener: (...args: Events[K]) => any): this;
142
+ /**
143
+ * Add a new event listener which only runs once
144
+ * @param event Event name
145
+ * @param listener Listener callback
146
+ */
31
147
  once<K extends keyof Events>(event: K, listener: (...args: Events[K]) => any): this;
148
+ /**
149
+ * Remove an event name
150
+ * @param event Event name
151
+ * @param listener Listener callback
152
+ */
32
153
  off<K extends keyof Events>(event: K, listener: (...args: Events[K]) => any): this;
154
+ /**
155
+ * Emit an event
156
+ * @param event Event name
157
+ * @param args Event arguments
158
+ */
33
159
  emit<K extends keyof Events>(event: K, ...args: Events[K]): Promise<boolean>;
34
160
  }
35
161
  //#endregion
36
162
  //#region src/classes/GuildsError.d.ts
163
+ /** Class representing a library-related error */
37
164
  declare class GuildsError extends Error {
38
165
  static name: string;
39
- readonly scope?: ErrorCode;
166
+ readonly scope?: ErrorScope;
40
167
  get name(): string;
41
- constructor(message: string, scope?: ErrorCode);
168
+ constructor(message: string, scope?: ErrorScope);
42
169
  }
43
170
  //#endregion
44
- //#region src/classes/Routes.d.ts
45
- declare class Routes {
46
- static gateway(bot?: boolean): "https://discord.com/api/v10/gateway/bot" | "https://discord.com/api/v10/gateway";
47
- static user(userId?: string): `https://discord.com/api/v10/users/${string}`;
171
+ //#region src/classes/RESTManager.d.ts
172
+ /** Class representing a Discord REST API manager */
173
+ declare class RESTManager {
174
+ #private;
175
+ /**
176
+ * Instantiate a new Discord API manager
177
+ * @param token Client token
178
+ */
179
+ constructor(token: string);
180
+ /**
181
+ * Create a HTTP DELETE request
182
+ * @param endpoint Endpoint URI
183
+ * @param init Request data
184
+ */
185
+ delete<T = any>(endpoint: string, init?: RequestInit): Promise<Response & {
186
+ data: T;
187
+ }>;
188
+ /**
189
+ * Create a HTTP GET request
190
+ * @param endpoint Endpoint URI
191
+ * @param init Request data
192
+ */
193
+ get<T = any>(endpoint: string, init?: RequestInit): Promise<Response & {
194
+ data: T;
195
+ }>;
196
+ /**
197
+ * Create a HTTP PATCH request
198
+ * @param endpoint Endpoint URI
199
+ * @param init Request data
200
+ */
201
+ patch<T = any>(endpoint: string, init?: RequestInit): Promise<Response & {
202
+ data: T;
203
+ }>;
204
+ /**
205
+ * Create a HTTP POST request
206
+ * @param endpoint Endpoint URI
207
+ * @param init Request data
208
+ */
209
+ post<T = any>(endpoint: string, init?: RequestInit): Promise<Response & {
210
+ data: T;
211
+ }>;
212
+ /**
213
+ * Create a HTTP PUT request
214
+ * @param endpoint Endpoint URI
215
+ * @param init Request data
216
+ */
217
+ put<T = any>(endpoint: string, init?: RequestInit): Promise<Response & {
218
+ data: T;
219
+ }>;
48
220
  }
49
221
  //#endregion
50
- //#region src/classes/DiscordAPI.d.ts
51
- declare class DiscordAPI {
222
+ //#region src/classes/User.d.ts
223
+ /**
224
+ * Class representing a Discord user
225
+ * @see https://docs.discord.com/developers/resources/user
226
+ */
227
+ declare class User {
52
228
  #private;
53
- constructor(token: string);
54
- get token(): string;
55
- get(input: string | URL | Request, init?: RequestInit): Promise<Response>;
229
+ /** The user's banner color as a color integer */
230
+ accentColor?: number;
231
+ /** The user's banner color as a hex color*/
232
+ accentColorHex: string | null;
233
+ /** The user's about me (client only) */
234
+ bio: string | null;
235
+ /** Whether the user is an application (bot) */
236
+ bot: boolean;
237
+ /** The user's discriminator, or "0" if they have none */
238
+ discriminator: string;
239
+ /** The user's display name or bot's application name */
240
+ displayName?: string;
241
+ /** The user's email (user clients only) */
242
+ email?: string;
243
+ /** The user's ID snowflake */
244
+ id: string;
245
+ /** Whether the user has two factor authentication enabled (user clients only) */
246
+ mfaEnabled?: boolean;
247
+ /** The data from Discord's API provided as-is */
248
+ rawData: User$1;
249
+ /** Whether the user is a Discord system account */
250
+ system: boolean;
251
+ /** The user's username (not to be confused with display name or tag) */
252
+ username: string;
253
+ /** Whether the user's email is verified (user clients only) */
254
+ verified?: boolean;
255
+ constructor(client: Client, data: User$1);
256
+ /** The client associated with this user */
257
+ get client(): Client;
258
+ /** Get the user's avatar as an image URL */
259
+ avatarURL(props: AvatarURLProps): string | null;
260
+ /** `username#0000` or just `username` (if no discriminator) */
261
+ get tag(): string;
262
+ /** User mention as a string, e.g. <@123456789> */
263
+ toString(): string;
56
264
  }
57
265
  //#endregion
58
266
  //#region src/classes/Client.d.ts
59
- declare class Client<Ready extends boolean = false> extends EventHandler<ClientEvents> {
267
+ /** Class representing a Discord client */
268
+ declare class Client extends EventHandler<ClientEvents> {
60
269
  #private;
61
- get token(): string;
62
- get intents(): number;
63
- get heartbeatInterval(): NodeJS.Timeout | undefined;
64
- get presence(): ClientPresence;
65
- isReady(): this is Client<true>;
270
+ /** Gateway heartbeat inteval */
271
+ heartbeatInterval?: NodeJS.Timeout;
272
+ /** Last received sequence number */
273
+ sequenceNumber: number | null;
274
+ /** Gateway session ID */
275
+ sessionId?: string;
276
+ /** REST manager instance to handle API calls */
277
+ rest: RESTManager;
278
+ /** Client intents bitfield */
279
+ intents: number;
280
+ /** Whether the client is ready */
281
+ ready: boolean;
282
+ /** WebSocket connection */
283
+ ws?: WebSocket;
284
+ /** Client user, or null if not ready */
285
+ user: User | null;
286
+ /** Current presence information */
287
+ presence: ClientPresenceProps;
288
+ /**
289
+ * Instantiate a new Client
290
+ * @param props Client options
291
+ */
66
292
  constructor(props: ClientProps);
67
- connect(): Promise<Client<true>>;
68
- setPresence(presence: Partial<ClientPresence>): this;
69
- disconnect(): Promise<void>;
293
+ /** The client's token */
294
+ get token(): string;
295
+ /** Start the connection to Discord's gateway */
296
+ connect(): Promise<Client>;
297
+ destroyed: boolean;
298
+ lastHeartbeatAck: boolean;
299
+ /** Update the client's user presence */
300
+ setPresence(presence: Partial<ClientPresenceProps>): this;
301
+ /** Destroy the connection to Discord's gateway */
302
+ disconnect(): void;
70
303
  }
71
304
  //#endregion
72
- //#region src/types.d.ts
73
- type ActivityType = keyof typeof activityTypes | (typeof activityTypes)[keyof typeof activityTypes];
305
+ //#region src/typings/index.d.ts
306
+ interface AvatarURLProps {
307
+ size: 128 | 256 | 512 | 1024 | 2048 | 4096;
308
+ format?: "webp" | "png" | "jpg" | "gif";
309
+ }
74
310
  type ClientEvents = {
75
311
  debug: [message: string];
76
312
  error: [error: any];
77
- ready: [readyClient: Client<true>];
313
+ ready: [client: Client];
78
314
  };
79
- interface ClientPresence {
80
- activities: ClientActivity[];
315
+ interface ClientPresenceProps {
316
+ activities: UserActivity[];
81
317
  platform: "desktop" | "mobile";
82
318
  status: UserStatus;
83
319
  }
84
- interface ClientActivity {
85
- name: string;
86
- state?: string;
87
- type: ActivityType;
88
- url?: string;
89
- }
90
- interface ClientPresence {}
91
320
  interface ClientProps {
92
321
  token: string;
93
- intents: number;
94
- presence?: Partial<ClientPresence>;
322
+ intents: IntentsResolvable;
323
+ presence?: Partial<ClientPresenceProps>;
95
324
  }
96
- type ErrorCode = (typeof errorCodes)[keyof typeof errorCodes];
325
+ declare const errorScopes: readonly ["ClientIntentsError", "ClientPropsError", "ClientTokenError", "DiscordAPIError", "GatewayError", "WebSocketError"];
326
+ type ErrorScope = (typeof errorScopes)[keyof typeof errorScopes];
327
+ type GatewayIntent = keyof typeof GatewayIntents | (typeof GatewayIntents)[keyof typeof GatewayIntents];
328
+ type GatewayOpcode = (typeof GatewayOpcodes)[keyof typeof GatewayOpcodes];
97
329
  interface GatewayPayload {
98
- op: (typeof opCodes)[keyof typeof opCodes];
330
+ op: GatewayOpcode;
99
331
  d?: any;
100
332
  s?: number | null;
101
333
  t?: string | null;
102
334
  }
335
+ type HTTPRequestMethod = "DELETE" | "GET" | "PATCH" | "POST" | "PUT";
103
336
  type If<Condition extends boolean, Then, Else = never> = Condition extends true ? Then : Else;
337
+ type IntentsResolvable = number | number[] | GatewayIntent[];
338
+ interface UserActivity {
339
+ name: string;
340
+ state?: string;
341
+ type: UserActivityType;
342
+ url?: string;
343
+ }
344
+ type UserActivityType = keyof typeof ActivityTypes | (typeof ActivityTypes)[keyof typeof ActivityTypes];
104
345
  type UserStatus = "online" | "idle" | "dnd" | "offline";
105
346
  //#endregion
106
- export { ActivityType, Client, ClientActivity, ClientEvents, ClientPresence, ClientProps, DiscordAPI, ErrorCode, EventHandler, GatewayPayload, GuildsError, If, Routes, UserStatus, activityTypes, baseApiUrl, errorCodes, opCodes };
347
+ export { ActivityTypes, AvatarURLProps, Client, ClientEvents, ClientPresenceProps, ClientProps, type api_types_d_exports as DiscordAPI, Endpoints, ErrorScope, EventHandler, GatewayIntent, GatewayIntents, GatewayOpcode, GatewayOpcodes, GatewayPayload, GuildsError, HTTPRequestMethod, If, IntentsResolvable, RESTManager, User, UserActivity, UserActivityType, UserStatus, baseApiUrl, colorIntToHex, hexToColorInt, parseIntents };