@stoatx/client 0.3.0 → 0.4.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/dist/index.d.ts CHANGED
@@ -18,6 +18,28 @@ declare class GatewayManager {
18
18
  disconnect(): void;
19
19
  }
20
20
 
21
+ type CDNTag = "attachments" | "avatars" | "backgrounds" | "icons" | "banners" | "emojis";
22
+ declare class AttachmentBuilder {
23
+ readonly filename: string | undefined;
24
+ readonly file: Buffer | Blob;
25
+ /**
26
+ * Creates a new AttachmentBuilder with the given file and optional filename.
27
+ * @param file The file data as a Buffer or Blob.
28
+ * @param filename An optional filename to use for the uploaded file. If not provided, the CDN will assign a default name.
29
+ * Providing a filename can help with organization and debugging, but is not strictly required.
30
+ * @example
31
+ * // Create an attachment from a Buffer with a custom filename
32
+ * const buffer = Buffer.from("Hello, world!");
33
+ * const attachment = new AttachmentBuilder(buffer, "greeting.txt");
34
+ */
35
+ constructor(file: Buffer | Blob, filename?: string);
36
+ /**
37
+ * Uploads this attachment to the Stoat CDN and returns the resulting file ID.
38
+ * @internal — use `resolveAttachment()` instead of calling this directly.
39
+ */
40
+ upload(rest: RESTManager, tag: CDNTag): Promise<string>;
41
+ }
42
+
21
43
  /**
22
44
  * Custom Error class for Stoat API failures
23
45
  */
@@ -46,7 +68,7 @@ declare class RESTManager {
46
68
  /**
47
69
  * Uploads a file to Stoat's CDN and returns the File ID
48
70
  */
49
- uploadFile(filename: string, fileBuffer: Buffer | Blob): Promise<string>;
71
+ uploadFile(tag: CDNTag, fileBuffer: Buffer | Blob, filename?: string): Promise<string>;
50
72
  get(endpoint: string): Promise<any>;
51
73
  post(endpoint: string, body?: any): Promise<any>;
52
74
  patch(endpoint: string, body?: any): Promise<any>;
@@ -346,6 +368,141 @@ declare class MemberManager extends BaseManager<string, Member> {
346
368
  [util.inspect.custom](): Collection<string, Member>;
347
369
  }
348
370
 
371
+ type BitFieldResolvable = number | string | bigint | BitField | BitFieldResolvable[];
372
+ declare class BitField {
373
+ static Flags: Record<string, number | bigint>;
374
+ static DefaultBit: number | bigint;
375
+ bitfield: number | bigint;
376
+ constructor(bits?: BitFieldResolvable);
377
+ /**
378
+ * Checks whether this bitfield has any of the given bits set.
379
+ *
380
+ * @param bit The bit(s) to test against.
381
+ * @returns `true` if at least one of the provided bits is set.
382
+ *
383
+ * @example
384
+ * perms.any(['SendMessage', 'ManageChannel']); // true if either is set
385
+ */
386
+ any(bit: BitFieldResolvable): boolean;
387
+ /**
388
+ * Checks whether this bitfield is exactly equal to the given bit value.
389
+ *
390
+ * @param bit The bit(s) to compare against.
391
+ * @returns `true` if the resolved bit value is identical to this bitfield.
392
+ *
393
+ * @example
394
+ * new Permissions(0n).equals(0n); // true
395
+ */
396
+ equals(bit: BitFieldResolvable): boolean;
397
+ /**
398
+ * Checks whether this bitfield has *all* of the given bits set.
399
+ *
400
+ * @param bit The bit(s) to check for.
401
+ * @returns `true` if every provided bit is set in this bitfield.
402
+ *
403
+ * @example
404
+ * perms.has('SendMessage');
405
+ * perms.has(['SendMessage', 'ViewChannel']); // true only if both are set
406
+ */
407
+ has(bit: BitFieldResolvable, ..._hasParams: any[]): boolean;
408
+ /**
409
+ * Returns the flag names present in `bits` that are *missing* from this bitfield.
410
+ *
411
+ * @param bits The bits to check against.
412
+ * @returns An array of flag name strings that are in `bits` but not in this bitfield.
413
+ *
414
+ * @example
415
+ * // If perms only has SendMessage:
416
+ * perms.missing(['SendMessage', 'ManageChannel']); // ['ManageChannel']
417
+ */
418
+ missing(bits: BitFieldResolvable, ...hasParams: any[]): string[];
419
+ /**
420
+ * Freezes this BitField instance, making it immutable.
421
+ * Subsequent calls to `add()` or `remove()` will return a new instance instead of mutating this one.
422
+ *
423
+ * @returns This instance, frozen.
424
+ */
425
+ freeze(): Readonly<this>;
426
+ /**
427
+ * Adds one or more bits to this bitfield.
428
+ * If the instance is frozen, returns a new BitField with the bits added.
429
+ *
430
+ * @param bits The bit(s) to add.
431
+ * @returns This instance (or a new one if frozen), with the bits added.
432
+ *
433
+ * @example
434
+ * perms.add('SendMessage', 'ViewChannel');
435
+ */
436
+ add(...bits: BitFieldResolvable[]): this;
437
+ /**
438
+ * Removes one or more bits from this bitfield.
439
+ * If the instance is frozen, returns a new BitField with the bits removed.
440
+ *
441
+ * @param bits The bit(s) to remove.
442
+ * @returns This instance (or a new one if frozen), with the bits cleared.
443
+ *
444
+ * @example
445
+ * perms.remove('ManageChannel');
446
+ */
447
+ remove(...bits: BitFieldResolvable[]): this;
448
+ /**
449
+ * Serializes this bitfield to a plain object mapping each flag name to a boolean
450
+ * indicating whether that flag is set.
451
+ *
452
+ * @returns A record of `{ [flagName]: boolean }` for all defined flags.
453
+ *
454
+ * @example
455
+ * perms.serialize();
456
+ * // { SendMessage: true, ManageChannel: false, ... }
457
+ */
458
+ serialize(...hasParams: any[]): Record<string, boolean>;
459
+ /**
460
+ * Returns an array of flag names that are set in this bitfield.
461
+ *
462
+ * @returns An array of string flag names.
463
+ *
464
+ * @example
465
+ * perms.toArray(); // ['SendMessage', 'ViewChannel']
466
+ */
467
+ toArray(...hasParams: any[]): string[];
468
+ /**
469
+ * Returns the bitfield value as a JSON-safe primitive.
470
+ * Numbers are returned as-is; bigints are converted to their string representation
471
+ * to avoid JSON serialization errors.
472
+ */
473
+ toJSON(): number | string;
474
+ /**
475
+ * Returns the underlying numeric value of this bitfield.
476
+ * Allows BitField instances to be used directly in arithmetic expressions.
477
+ */
478
+ valueOf(): number | bigint;
479
+ /**
480
+ * Iterates over the names of all flags that are set in this bitfield.
481
+ *
482
+ * @example
483
+ * for (const flag of perms) {
484
+ * console.log(flag); // 'SendMessage', 'ViewChannel', etc.
485
+ * }
486
+ */
487
+ [Symbol.iterator](...hasParams: any[]): IterableIterator<string>;
488
+ /**
489
+ * Resolves a {@link BitFieldResolvable} into a raw `number | bigint`.
490
+ *
491
+ * Resolution rules (in order):
492
+ * - `undefined` → `DefaultBit`
493
+ * - A number or bigint matching `DefaultBit`'s type and >= 0 → returned as-is
494
+ * - A `BitField` instance → its `.bitfield` value
495
+ * - An array → each element resolved and OR'd together
496
+ * - A numeric string → parsed as `BigInt` or `Number` depending on `DefaultBit`'s type
497
+ * - A named string flag → looked up in `Flags`
498
+ * - Anything else → throws `RangeError`
499
+ *
500
+ * @param bit The value to resolve.
501
+ * @throws {RangeError} If the value cannot be resolved to a valid bit.
502
+ */
503
+ static resolve(bit?: BitFieldResolvable): number | bigint;
504
+ }
505
+
349
506
  declare const PermissionFlags: {
350
507
  readonly ManageChannel: bigint;
351
508
  readonly ManageServer: bigint;
@@ -383,16 +540,16 @@ declare const PermissionFlags: {
383
540
  readonly GrantAllSafe: 4503599627370495n;
384
541
  };
385
542
  type PermissionString = keyof typeof PermissionFlags;
386
- type PermissionResolvable = bigint | PermissionString | PermissionResolvable[];
387
- declare class Permissions {
388
- /**
389
- * Converts a string, BigInt, or array of strings into a single BigInt
390
- */
391
- static resolve(permission: PermissionResolvable): bigint;
392
- /**
393
- * Checks if a specific permission bit exists
394
- */
395
- static has(totalPermissions: bigint, permissionToCheck: PermissionResolvable): boolean;
543
+ type PermissionResolvable = PermissionString | bigint | number | Permissions | PermissionResolvable[];
544
+ declare class Permissions extends BitField {
545
+ static Flags: Record<string, number | bigint>;
546
+ static DefaultBit: bigint;
547
+ static resolve(bit?: PermissionResolvable): bigint;
548
+ has(bit: PermissionResolvable): boolean;
549
+ any(bit: PermissionResolvable): boolean;
550
+ missing(bits: PermissionResolvable): PermissionString[];
551
+ add(...bits: PermissionResolvable[]): this;
552
+ remove(...bits: PermissionResolvable[]): this;
396
553
  }
397
554
 
398
555
  declare class DMChannel extends BaseChannel {
@@ -639,7 +796,7 @@ interface ChannelEditOptions {
639
796
  name?: string;
640
797
  description?: string | null;
641
798
  owner?: string;
642
- icon?: string | null;
799
+ icon?: string | AttachmentBuilder | null;
643
800
  nsfw?: boolean;
644
801
  archived?: boolean;
645
802
  voice?: {
@@ -1104,7 +1261,8 @@ declare class Role extends Base {
1104
1261
  color: string | null;
1105
1262
  hoist: boolean;
1106
1263
  rank: number;
1107
- permissions: bigint;
1264
+ icon: Attachment | null;
1265
+ private _permissions;
1108
1266
  constructor(client: Client, data: any, serverId: string);
1109
1267
  /**
1110
1268
  * Updates the role instance with new data without losing the object reference.
@@ -1117,11 +1275,9 @@ declare class Role extends Base {
1117
1275
  */
1118
1276
  get server(): Server | undefined;
1119
1277
  /**
1120
- * Checks whether this role has a specific permission.
1121
- * @param permission The permission to check for.
1122
- * @returns True if the role has the permission.
1278
+ * Permissions for this role
1123
1279
  */
1124
- hasPermission(permission: PermissionResolvable): boolean;
1280
+ get permissions(): Permissions;
1125
1281
  /**
1126
1282
  * Fetches this role directly from the API to ensure data is up to date.
1127
1283
  * @param force Whether to skip the cache check and force a direct API request. Defaults to false.
@@ -1133,7 +1289,7 @@ declare class Role extends Base {
1133
1289
  * await role.fetch();
1134
1290
  * console.log(`Role updated, current name: ${role.name}`);
1135
1291
  */
1136
- fetch(force?: boolean): Promise<this>;
1292
+ fetch(force?: boolean): Promise<Role>;
1137
1293
  /**
1138
1294
  * Edits the role with the given options. Only the fields provided in the options will be updated; all other fields will remain unchanged.
1139
1295
  * @param options The fields to update.
@@ -1142,12 +1298,12 @@ declare class Role extends Base {
1142
1298
  * @throws {Error} If the API request fails (e.g., lack of permissions).
1143
1299
  * @example
1144
1300
  * // Change the role's name and color
1145
- * await role.edit({ name: "Senior Admin", colour: "#FFD700" });
1301
+ * await role.edit({ name: "Senior Admin", color: "#FFD700" });
1146
1302
  *
1147
1303
  * // Remove the custom color from the role
1148
- * await role.edit({ colour: null });
1304
+ * await role.edit({ color: null });
1149
1305
  */
1150
- edit(options: RoleEditOptions): Promise<this>;
1306
+ edit(options: RoleEditOptions): Promise<Role>;
1151
1307
  /**
1152
1308
  * Deletes this Role from the server.
1153
1309
  * @throws {Error} If the role cannot be deleted (e.g., lack of permissions).
@@ -1168,7 +1324,7 @@ declare class Role extends Base {
1168
1324
  * allow: ["ManageChannel", "SendMessage"]
1169
1325
  * });
1170
1326
  */
1171
- setPermissions(options: RolePermissionOptions): Promise<this>;
1327
+ setPermissions(options: RolePermissionOptions): Promise<Role>;
1172
1328
  /**
1173
1329
  * Updates the hierarchical position of this role.
1174
1330
  * Automatically reconstructs the role array and performs a bulk update.
@@ -1180,7 +1336,66 @@ declare class Role extends Base {
1180
1336
  * await role.setPosition(2);
1181
1337
  * console.log(`Role moved to rank: ${role.rank}`);
1182
1338
  */
1183
- setPosition(newPosition: number): Promise<this>;
1339
+ setPosition(newPosition: number): Promise<Role>;
1340
+ /**
1341
+ * Change the name for this role
1342
+ * @param name The new name for the role
1343
+ * @returns A promise that resolves to this updated Role object.
1344
+ * @throws {Error} If API request fails.
1345
+ * @example
1346
+ * // Change the role's name
1347
+ * await role.setName("New Role Name");
1348
+ * console.log(`Role's new name: ${role.name}`);
1349
+ */
1350
+ setName(name: string): Promise<Role>;
1351
+ /**
1352
+ * Change the color for this role, it can be a HEX or CSS colours
1353
+ * @param {[string]} color The new color for the role
1354
+ * @returns A promise that resolves to this updated Role object.
1355
+ * @throws {Error} If API request fails
1356
+ * @example
1357
+ * // Change the role's color
1358
+ * await role.setColour("#FF0000");
1359
+ * console.log(`Role's new color: ${role.color}`);
1360
+ *
1361
+ * // Use CSS color linear-graident
1362
+ * await role.setColour("linear-gradient(90deg, #FF0000, #0000FF)");
1363
+ * console.log(`Role's new color: ${role.color}`);
1364
+ *
1365
+ * // Remove the custom color from the role
1366
+ * await role.setColour(null);
1367
+ * console.log(`Role's color removed, current color: ${role.color}`);
1368
+ */
1369
+ setColor(color: string | null): Promise<Role>;
1370
+ /**
1371
+ * Edit the icon of this role
1372
+ * @param icon Autumn ID for the new icon, or null to remove the custom icon
1373
+ * @returns A promise that resolves to this updated Role object.
1374
+ * @throws {Error} If API request fails
1375
+ * @example
1376
+ * // Set a new icon for the role
1377
+ * await role.setIcon("AUTUMN_ID_FOR_ICON");
1378
+ * console.log(`Role's new icon: ${role.icon}`);
1379
+ *
1380
+ * // Use AttachmentBuilder to upload a new icon file
1381
+ * import { readFile } from "node:fs/promises";
1382
+ * const iconFile = await readFile("./a.jpg");
1383
+ * const attachment = new AttachmentBuilder(iconFile, "a.jpg");
1384
+ * await role.setIcon(attachment);
1385
+ * console.log(`Role's new icon: ${role.icon}`);
1386
+ */
1387
+ setIcon(icon: string | AttachmentBuilder | null): Promise<Role>;
1388
+ /**
1389
+ * Change the hoist status for this role
1390
+ * @param hoist The new hoist status for the role
1391
+ * @returns A promise that resolves to this updated Role object.
1392
+ * @throws {Error} If API request fails
1393
+ * @example
1394
+ * // Enable hoisting for the role
1395
+ * await role.setHoist(true);
1396
+ * console.log(`Role is now hoisted: ${role.hoist}`);
1397
+ */
1398
+ setHoist(hoist: boolean): Promise<Role>;
1184
1399
  /**
1185
1400
  * Customizer for Node.js `console.log` and `util.inspect`.
1186
1401
  * Hides the cyclic client reference and raw serverId for a cleaner output.
@@ -1194,8 +1409,9 @@ interface RoleCreateOptions {
1194
1409
  }
1195
1410
  interface RoleEditOptions {
1196
1411
  name?: string;
1197
- colour?: string | null;
1412
+ color?: string | null;
1198
1413
  hoist?: boolean;
1414
+ icon?: string | AttachmentBuilder | null;
1199
1415
  }
1200
1416
  interface RolePermissionOptions {
1201
1417
  allow?: PermissionResolvable;
@@ -1273,7 +1489,7 @@ declare class RoleManager extends BaseManager<string, Role> {
1273
1489
  fetch(role: RoleResolvable, force?: boolean): Promise<Role>;
1274
1490
  /**
1275
1491
  * Edits an existing role in the server.
1276
- * @param role The RoleResolvable to edit.
1492
+ * @param role The {@link RoleResolvable} to edit.
1277
1493
  * @param options The fields to update.
1278
1494
  * @returns A promise that resolves to the updated Role.
1279
1495
  * @throws {TypeError} If invalid options or RoleResolvable are provided.
@@ -1552,7 +1768,7 @@ declare class Member extends Base {
1552
1768
  /** Gets the Server object this member belongs to */
1553
1769
  get server(): Server | undefined;
1554
1770
  /** Calculates the member's total permissions using BigInt */
1555
- get permissions(): bigint;
1771
+ get permissions(): Permissions;
1556
1772
  /** Get avatar URL for this member, or null if they don't have one.
1557
1773
  * @example
1558
1774
  * // Get a member's avatar URL
@@ -1599,8 +1815,6 @@ declare class Member extends Base {
1599
1815
  */
1600
1816
  send(options: string | MessageOptions): Promise<Message>;
1601
1817
  setNickname(nickname: string): Promise<Member>;
1602
- /** Checks if the member has a specific permission */
1603
- hasPermission(permission: PermissionResolvable): boolean;
1604
1818
  /**
1605
1819
  * Edit this member.
1606
1820
  * @param options The options to edit the member with (nickname, roles, timeout, etc.)
@@ -1692,7 +1906,7 @@ declare class ReactionCollector extends Collector<string, MessageReaction> {
1692
1906
  interface MessageOptions {
1693
1907
  content?: string;
1694
1908
  embeds?: (TextEmbedData | EmbedBuilder)[];
1695
- attachments?: string[];
1909
+ attachments?: string[] | AttachmentBuilder[];
1696
1910
  interactions?: any[];
1697
1911
  flags?: number;
1698
1912
  masquerade?: Masquerade;
@@ -1906,4 +2120,4 @@ declare class UnknownChannel extends BaseChannel {
1906
2120
  constructor(client: Client, data: any);
1907
2121
  }
1908
2122
 
1909
- export { Attachment, type AttachmentMetadata, Base, BaseChannel, type BotInformation, type Categories, type ChannelCreateOptions, type ChannelEditOptions, ChannelManager, type ChannelResolvable, type ChannelRolePermissionOptions, ChannelType, Client, type ClientEvents, type ClientOptions, ClientUser, Collection, Collector, type CollectorOptions, DMChannel, EmbedBuilder, Emoji, EmojiManager, type EmojiParent, type FetchMembersOptions, GatewayManager, type Interaction, type Masquerade, Member, type MemberBanOptions, type MemberEditOptions, MemberManager, type MemberResolvable, Message, MessageCollector, type MessageCollectorOptions, type MessageFetchOptions, MessageManager, type MessageOptions, MessageReaction, type MessageResolvable, PermissionFlags, type PermissionResolvable, type PermissionString, Permissions, RESTManager, ReactionCollector, type ReactionCollectorOptions, type ReplyIntent, Role, type RoleCreateOptions, type RoleEditOptions, RoleManager, type RolePermissionOptions, type RoleResolvable, Server, ServerChannelManager, type ServerEditOptions, ServerManager, StoatAPIError, SweeperManager, type SweeperOptions, TextChannel, type TextEmbedData, UnknownChannel, User, type UserEditOptions, UserManager, UserPresence, type UserProfile, UserRelationship, type UserResolvable, type UserStatus };
2123
+ export { Attachment, AttachmentBuilder, type AttachmentMetadata, Base, BaseChannel, BitField, type BitFieldResolvable, type BotInformation, type CDNTag, type Categories, type ChannelCreateOptions, type ChannelEditOptions, ChannelManager, type ChannelResolvable, type ChannelRolePermissionOptions, ChannelType, Client, type ClientEvents, type ClientOptions, ClientUser, Collection, Collector, type CollectorOptions, DMChannel, EmbedBuilder, Emoji, EmojiManager, type EmojiParent, type FetchMembersOptions, GatewayManager, type Interaction, type Masquerade, Member, type MemberBanOptions, type MemberEditOptions, MemberManager, type MemberResolvable, Message, MessageCollector, type MessageCollectorOptions, type MessageFetchOptions, MessageManager, type MessageOptions, MessageReaction, type MessageResolvable, PermissionFlags, type PermissionResolvable, type PermissionString, Permissions, RESTManager, ReactionCollector, type ReactionCollectorOptions, type ReplyIntent, Role, type RoleCreateOptions, type RoleEditOptions, RoleManager, type RolePermissionOptions, type RoleResolvable, Server, ServerChannelManager, type ServerEditOptions, ServerManager, StoatAPIError, SweeperManager, type SweeperOptions, TextChannel, type TextEmbedData, UnknownChannel, User, type UserEditOptions, UserManager, UserPresence, type UserProfile, UserRelationship, type UserResolvable, type UserStatus };