lunibee 0.2.1 → 0.2.3

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.
Files changed (49) hide show
  1. package/README.md +6 -6
  2. package/dist/builders/attachment.d.ts +5 -1
  3. package/dist/builders/commands.d.ts +136 -47
  4. package/dist/builders/components.d.ts +164 -45
  5. package/dist/builders/embed.d.ts +5 -1
  6. package/dist/builders/index.d.ts +9 -4
  7. package/dist/builders/index.js +206 -105
  8. package/dist/builders/index.js.map +8 -8
  9. package/dist/core/events.d.ts +28 -12
  10. package/dist/core/index.d.ts +2 -1
  11. package/dist/core/index.js +377 -150
  12. package/dist/core/index.js.map +25 -25
  13. package/dist/core/permissions.d.ts +6 -2
  14. package/dist/index.d.ts +5 -4
  15. package/dist/index.js +662 -268
  16. package/dist/index.js.map +33 -32
  17. package/dist/managers/base.d.ts +4 -0
  18. package/dist/managers/emoji.d.ts +7 -1
  19. package/dist/managers/guild-resources.d.ts +11 -3
  20. package/dist/managers/guild.d.ts +13 -5
  21. package/dist/managers/index.d.ts +31 -14
  22. package/dist/managers/index.js +167 -80
  23. package/dist/managers/index.js.map +18 -18
  24. package/dist/managers/member.d.ts +5 -3
  25. package/dist/managers/message.d.ts +7 -3
  26. package/dist/managers/role.d.ts +13 -1
  27. package/dist/rest/error-codes.d.ts +48 -0
  28. package/dist/rest/errors.d.ts +1 -0
  29. package/dist/rest/index.d.ts +1 -0
  30. package/dist/rest/index.js +53 -3
  31. package/dist/rest/index.js.map +7 -6
  32. package/dist/rest/routes.d.ts +4 -2
  33. package/dist/sharding/index.js +7 -6
  34. package/dist/sharding/index.js.map +6 -6
  35. package/dist/structures/base.d.ts +18 -9
  36. package/dist/structures/index.d.ts +15 -9
  37. package/dist/structures/index.js +198 -68
  38. package/dist/structures/index.js.map +12 -12
  39. package/dist/structures/interactions.d.ts +85 -11
  40. package/dist/structures/resources.d.ts +11 -1
  41. package/dist/types/gateway.d.ts +14 -0
  42. package/dist/types/index.d.ts +204 -16
  43. package/dist/types/index.js +37 -10
  44. package/dist/types/index.js.map +4 -4
  45. package/dist/voice/index.js +4 -3
  46. package/dist/voice/index.js.map +3 -3
  47. package/dist/ws/index.js +2 -1
  48. package/dist/ws/index.js.map +5 -5
  49. package/package.json +15 -15
@@ -2,6 +2,8 @@ import { REST } from "@lunibee/rest";
2
2
  import { GuildMember, type ResourceContext } from "@lunibee/structures";
3
3
  import { ResourceManager } from "./base.js";
4
4
  export interface MemberEditOptions {
5
+ /** Audit-log reason. */
6
+ reason?: string;
5
7
  nick?: string | null;
6
8
  roles?: string[];
7
9
  mute?: boolean;
@@ -23,9 +25,9 @@ export declare class GuildMemberManager extends ResourceManager<string, GuildMem
23
25
  kick(userId: string, reason?: string): Promise<void>;
24
26
  /** Bans a user from the guild. */
25
27
  ban(userId: string, options?: BanOptions): Promise<void>;
26
- /** Unbans a user from the guild. */
27
- unban(userId: string): Promise<void>;
28
- /** Edits a guild member (nickname, roles, timeout, mute, deaf). @param reason Audit-log reason. */
28
+ /** Unbans a user from the guild. @param reason Audit-log reason. */
29
+ unban(userId: string, reason?: string): Promise<void>;
30
+ /** Edits a guild member (nickname, roles, timeout, mute, deaf). Put the audit-log reason in `options.reason`. @param reason Deprecated: use `options.reason`. Removed in 0.3.0. */
29
31
  edit(userId: string, options: MemberEditOptions, reason?: string): Promise<GuildMember>;
30
32
  /** Adds a role to a member. @param reason Audit-log reason. */
31
33
  addRole(userId: string, roleId: string, reason?: string): Promise<void>;
@@ -21,13 +21,17 @@ export type MessageCreateOptions = Record<string, unknown> & {
21
21
  files?: MessageFile[];
22
22
  };
23
23
  export type MessageEditOptions = MessageCreateOptions;
24
- /** Splits `files` out of a message payload into a REST upload, encoding string data as UTF-8. */
25
- export declare function toRequest(options: MessageCreateOptions): unknown;
24
+ /**
25
+ * Splits `files` out of a message payload into a REST upload, encoding string
26
+ * data as UTF-8. `allowedMentions` is the client's default, applied only when
27
+ * the payload has no `allowed_mentions` of its own.
28
+ */
29
+ export declare function toRequest(options: MessageCreateOptions, allowedMentions?: unknown): unknown;
26
30
  export declare class MessageManager {
27
31
  #private;
28
32
  /** Cached messages; always empty unless a message cache is configured. */
29
33
  readonly cache: Collection<string, Message>;
30
- constructor(rest: REST, context: ResourceContext, channelId: string, cache?: MessageCacheOptions);
34
+ constructor(rest: REST, context: ResourceContext, channelId: string, cache?: MessageCacheOptions, allowedMentions?: unknown);
31
35
  resolve(messageId: string): Promise<Message>;
32
36
  send(options: MessageCreateOptions): Promise<Message>;
33
37
  fetch(messageId: string): Promise<Message>;
@@ -29,6 +29,18 @@ export declare class RoleManager extends ResourceManager<string, Role> {
29
29
  create(options: RoleCreateOptions): Promise<Role>;
30
30
  /** Edits an existing role. */
31
31
  edit(roleId: string, options: RoleEditOptions): Promise<Role>;
32
- /** Deletes a role from the guild. */
32
+ /** Deletes a role. @param reason Audit-log reason. */
33
+ remove(roleId: string, reason?: string): Promise<void>;
34
+ /**
35
+ * Moves roles in the hierarchy. Discord shifts the other roles around them.
36
+ * @param positions Each role's ID and its new position.
37
+ * @param reason Audit-log reason.
38
+ * @returns Every role in the guild, in their new order.
39
+ */
40
+ setPositions(positions: readonly {
41
+ id: string;
42
+ position: number;
43
+ }[], reason?: string): Promise<Role[]>;
44
+ /** @deprecated Use {@link RoleManager.remove}, which also takes an audit-log reason. Removed in 0.3.0. */
33
45
  deleteRole(roleId: string): Promise<void>;
34
46
  }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Discord JSON error codes that bots commonly handle, by name, for comparing
3
+ * with `RESTError.code`: `if (error.code === RESTErrorCode.UnknownMessage) …`.
4
+ *
5
+ * Values are from Discord's "JSON Error Codes" table
6
+ * (discord/discord-api-docs, developers/topics/opcodes-and-status-codes.mdx,
7
+ * checked at commit 86f0a46). Any other code is still available as a number
8
+ * on `RESTError.code`.
9
+ */
10
+ export declare const RESTErrorCode: {
11
+ readonly UnknownAccount: 10001;
12
+ readonly UnknownChannel: 10003;
13
+ readonly UnknownGuild: 10004;
14
+ readonly UnknownInvite: 10006;
15
+ readonly UnknownMember: 10007;
16
+ readonly UnknownMessage: 10008;
17
+ readonly UnknownPermissionOverwrite: 10009;
18
+ readonly UnknownRole: 10011;
19
+ readonly UnknownUser: 10013;
20
+ readonly UnknownEmoji: 10014;
21
+ readonly UnknownWebhook: 10015;
22
+ readonly UnknownBan: 10026;
23
+ readonly UnknownSticker: 10060;
24
+ readonly UnknownInteraction: 10062;
25
+ readonly UnknownScheduledEvent: 10070;
26
+ readonly BotsCannotUseEndpoint: 20001;
27
+ readonly MaxGuilds: 30001;
28
+ readonly MaxPins: 30003;
29
+ readonly MaxRoles: 30005;
30
+ readonly MaxWebhooks: 30007;
31
+ readonly MaxEmojis: 30008;
32
+ readonly MaxReactions: 30010;
33
+ readonly MaxChannels: 30013;
34
+ readonly InteractionAlreadyAcknowledged: 40060;
35
+ readonly MissingAccess: 50001;
36
+ readonly CannotExecuteInDM: 50003;
37
+ readonly CannotEditOthersMessage: 50005;
38
+ readonly CannotSendEmptyMessage: 50006;
39
+ readonly CannotSendMessagesToUser: 50007;
40
+ readonly MissingPermissions: 50013;
41
+ readonly InvalidToken: 50014;
42
+ readonly MessageTooOldToBulkDelete: 50034;
43
+ readonly InvalidFormBody: 50035;
44
+ readonly ThreadArchived: 50083;
45
+ readonly CannotReplyWithoutReadHistory: 160002;
46
+ };
47
+ /** One {@link RESTErrorCode} value, usable as a type. */
48
+ export type RESTErrorCode = (typeof RESTErrorCode)[keyof typeof RESTErrorCode];
@@ -34,6 +34,7 @@ export declare class RESTError extends Error {
34
34
  /** Raw Discord validation/error payload. */ readonly errors?: unknown;
35
35
  /** HTTP method used for the failed request. */ readonly method?: string;
36
36
  /** API path used for the failed request. */ readonly path?: string;
37
+ /** What to check next, for errors with a common cause (missing access or permissions). */ readonly hint?: string;
37
38
  /** Creates a REST error with request context. @param message Error message. @param status HTTP status. @param code Discord error code. @param errors Raw error payload. @param options Request context and cause. */
38
39
  constructor(message: string, status: number, code?: number, errors?: unknown, options?: {
39
40
  method?: string;
@@ -161,6 +161,7 @@ export declare class REST {
161
161
  }
162
162
  export { Routes } from "./routes.js";
163
163
  export { RESTError, abortError, redactPath, type RESTErrorKind, } from "./errors.js";
164
+ export { RESTErrorCode } from "./error-codes.js";
164
165
  export { createRouteKey, normalizeRoutePath, majorParameter, scopeBucket, serializeQuery, type RouteKey, type RESTQuery, } from "./route.js";
165
166
  export { RequestScheduler } from "./scheduler.js";
166
167
  export { RateLimiter } from "./limiter.js";
@@ -2,12 +2,15 @@
2
2
  // packages/rest/package.json
3
3
  var package_default = {
4
4
  name: "@lunibee/rest",
5
- version: "0.2.1",
5
+ version: "0.2.3",
6
6
  type: "module",
7
7
  module: "./src/index.ts",
8
8
  types: "./src/index.ts",
9
9
  exports: {
10
10
  ".": "./src/index.ts"
11
+ },
12
+ dependencies: {
13
+ "@lunibee/types": "workspace:*"
11
14
  }
12
15
  };
13
16
 
@@ -82,6 +85,10 @@ function kindFromStatus(status) {
82
85
  function redactPath(path) {
83
86
  return path.replace(/^(\/webhooks\/[^/?]+\/)[^/?]+/, "$1:token").replace(/^(\/interactions\/[^/?]+\/)[^/?]+/, "$1:token");
84
87
  }
88
+ var HINTS = {
89
+ 50001: "The bot cannot see this resource: check that it is in the guild and has View Channel there.",
90
+ 50013: "The bot lacks a permission for this action, or the target role or member is at or above the bot's highest role."
91
+ };
85
92
 
86
93
  class RESTError extends Error {
87
94
  kind;
@@ -90,12 +97,14 @@ class RESTError extends Error {
90
97
  errors;
91
98
  method;
92
99
  path;
100
+ hint;
93
101
  constructor(message, status, code, errors, options = {}) {
94
102
  super(message, options.cause === undefined ? undefined : { cause: options.cause });
95
103
  this.name = "RESTError";
96
104
  this.status = status;
97
105
  this.kind = options.kind ?? kindFromStatus(status);
98
106
  this.code = code;
107
+ this.hint = code === undefined ? undefined : HINTS[code];
99
108
  this.errors = errors;
100
109
  this.method = options.method;
101
110
  this.path = options.path === undefined ? undefined : redactPath(options.path);
@@ -404,6 +413,8 @@ var Routes = {
404
413
  crosspostMessage: (channelId, messageId) => `${Routes.message(channelId, messageId)}/crosspost`,
405
414
  messageReactions: (channelId, messageId, emoji) => `${Routes.message(channelId, messageId)}/reactions/${encodeURIComponent(emoji)}`,
406
415
  messageReactionsAll: (channelId, messageId) => `${Routes.message(channelId, messageId)}/reactions`,
416
+ channelMessagesPins: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}/messages/pins`,
417
+ channelMessagesPin: (channelId, messageId) => `/channels/${snowflake(channelId, "Channel ID")}/messages/pins/${snowflake(messageId, "Message ID")}`,
407
418
  channelPins: (channelId) => `/channels/${snowflake(channelId, "Channel ID")}/pins`,
408
419
  channelPin: (channelId, messageId) => `/channels/${snowflake(channelId, "Channel ID")}/pins/${snowflake(messageId, "Message ID")}`,
409
420
  messageThread: (channelId, messageId) => `${Routes.message(channelId, messageId)}/threads`,
@@ -462,6 +473,44 @@ function snowflake(value, field) {
462
473
  throw new TypeError(`${field} must be a valid Discord snowflake.`);
463
474
  return value;
464
475
  }
476
+ // packages/rest/src/error-codes.ts
477
+ var RESTErrorCode = {
478
+ UnknownAccount: 10001,
479
+ UnknownChannel: 10003,
480
+ UnknownGuild: 10004,
481
+ UnknownInvite: 10006,
482
+ UnknownMember: 10007,
483
+ UnknownMessage: 10008,
484
+ UnknownPermissionOverwrite: 10009,
485
+ UnknownRole: 10011,
486
+ UnknownUser: 10013,
487
+ UnknownEmoji: 10014,
488
+ UnknownWebhook: 10015,
489
+ UnknownBan: 10026,
490
+ UnknownSticker: 10060,
491
+ UnknownInteraction: 10062,
492
+ UnknownScheduledEvent: 10070,
493
+ BotsCannotUseEndpoint: 20001,
494
+ MaxGuilds: 30001,
495
+ MaxPins: 30003,
496
+ MaxRoles: 30005,
497
+ MaxWebhooks: 30007,
498
+ MaxEmojis: 30008,
499
+ MaxReactions: 30010,
500
+ MaxChannels: 30013,
501
+ InteractionAlreadyAcknowledged: 40060,
502
+ MissingAccess: 50001,
503
+ CannotExecuteInDM: 50003,
504
+ CannotEditOthersMessage: 50005,
505
+ CannotSendEmptyMessage: 50006,
506
+ CannotSendMessagesToUser: 50007,
507
+ MissingPermissions: 50013,
508
+ InvalidToken: 50014,
509
+ MessageTooOldToBulkDelete: 50034,
510
+ InvalidFormBody: 50035,
511
+ ThreadArchived: 50083,
512
+ CannotReplyWithoutReadHistory: 160002
513
+ };
465
514
  // packages/rest/src/redis.ts
466
515
  var RESERVE_SCRIPT = `
467
516
  local raw = redis.call('GET', KEYS[1])
@@ -643,7 +692,7 @@ class WebhookClient {
643
692
  // packages/rest/src/index.ts
644
693
  var LIBRARY_VERSION = package_default.version;
645
694
  var LIBRARY_URL = "https://github.com/Ekretos/lunibee";
646
- var USER_AGENT = `DiscordBot (${LIBRARY_URL}, ${package_default.version})`;
695
+ var USER_AGENT = `DiscordBot (${LIBRARY_URL}, ${LIBRARY_VERSION})`;
647
696
  var REQUEST_DATA_KEYS = new Set([
648
697
  "body",
649
698
  "files",
@@ -882,6 +931,7 @@ export {
882
931
  MemoryRateLimitStore,
883
932
  REST,
884
933
  RESTError,
934
+ RESTErrorCode,
885
935
  RateLimiter,
886
936
  RedisRateLimitStore,
887
937
  RequestScheduler,
@@ -899,4 +949,4 @@ export {
899
949
  serializeQuery
900
950
  };
901
951
 
902
- //# debugId=DB3368A765BDA92764756E2164756E21
952
+ //# debugId=0345D6D5C65D143C64756E2164756E21