lunibee 0.1.8 → 0.2.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.
Files changed (44) hide show
  1. package/README.md +2 -0
  2. package/dist/builders/components.d.ts +5 -0
  3. package/dist/builders/index.js +72 -12
  4. package/dist/builders/index.js.map +5 -5
  5. package/dist/collection/index.d.ts +68 -1
  6. package/dist/collection/index.js +334 -1
  7. package/dist/collection/index.js.map +3 -3
  8. package/dist/core/collector.d.ts +13 -0
  9. package/dist/core/events.d.ts +29 -3
  10. package/dist/core/index.d.ts +22 -8
  11. package/dist/core/index.js +1526 -124
  12. package/dist/core/index.js.map +26 -22
  13. package/dist/core/permissions.d.ts +48 -0
  14. package/dist/index.js +1578 -268
  15. package/dist/index.js.map +30 -29
  16. package/dist/managers/advanced.d.ts +116 -0
  17. package/dist/managers/base.d.ts +13 -2
  18. package/dist/managers/emoji.d.ts +1 -1
  19. package/dist/managers/guild.d.ts +28 -2
  20. package/dist/managers/index.d.ts +37 -5
  21. package/dist/managers/index.js +870 -152
  22. package/dist/managers/index.js.map +18 -16
  23. package/dist/managers/message.d.ts +10 -1
  24. package/dist/rest/errors.d.ts +33 -0
  25. package/dist/rest/index.d.ts +1 -1
  26. package/dist/rest/index.js +52 -6
  27. package/dist/rest/index.js.map +5 -5
  28. package/dist/rest/routes.d.ts +20 -0
  29. package/dist/sharding/index.d.ts +29 -0
  30. package/dist/sharding/index.js +99 -15
  31. package/dist/sharding/index.js.map +8 -8
  32. package/dist/structures/base.d.ts +2 -0
  33. package/dist/structures/index.js +96 -42
  34. package/dist/structures/index.js.map +10 -9
  35. package/dist/structures/interactions.d.ts +26 -0
  36. package/dist/types/gateway.d.ts +16 -0
  37. package/dist/types/index.d.ts +55 -1
  38. package/dist/types/index.js.map +2 -2
  39. package/dist/voice/index.d.ts +3 -0
  40. package/dist/voice/index.js +15 -1
  41. package/dist/voice/index.js.map +3 -3
  42. package/dist/ws/index.js +13 -5
  43. package/dist/ws/index.js.map +6 -6
  44. package/package.json +14 -14
@@ -67,6 +67,8 @@ export declare class Channel extends BaseStructure {
67
67
  nsfw?: boolean;
68
68
  rateLimitPerUser?: number;
69
69
  position?: number;
70
+ /** Role and member permission overwrites (empty for DMs and when not provided). */
71
+ permissionOverwrites: import("@lunibee/types").APIOverwrite[];
70
72
  /** Creates a channel structure from Discord channel data. */
71
73
  constructor(data: import("@lunibee/types").APIChannel, context?: ResourceContext);
72
74
  /** Sends a message to this channel. @param options Message payload. @returns The created message. @throws {Error} If the channel is not attached to a client. */
@@ -71,6 +71,7 @@ class Channel extends BaseStructure {
71
71
  nsfw;
72
72
  rateLimitPerUser;
73
73
  position;
74
+ permissionOverwrites;
74
75
  #context;
75
76
  constructor(data, context) {
76
77
  super(data.id);
@@ -84,6 +85,7 @@ class Channel extends BaseStructure {
84
85
  this.nsfw = data.nsfw;
85
86
  this.rateLimitPerUser = data.rate_limit_per_user;
86
87
  this.position = data.position;
88
+ this.permissionOverwrites = (data.permission_overwrites ?? []).map((overwrite) => ({ ...overwrite }));
87
89
  this.#context = context;
88
90
  }
89
91
  sendMessage(options) {
@@ -290,8 +292,11 @@ var Permission = {
290
292
  createEvents: 1n << 44n,
291
293
  useExternalSounds: 1n << 45n,
292
294
  sendVoiceMessages: 1n << 46n,
295
+ setVoiceChannelStatus: 1n << 48n,
293
296
  sendPolls: 1n << 49n,
294
- useExternalApps: 1n << 50n
297
+ useExternalApps: 1n << 50n,
298
+ pinMessages: 1n << 51n,
299
+ bypassSlowmode: 1n << 52n
295
300
  };
296
301
  var Permissions = {
297
302
  CreateInstantInvite: 1n << 0n,
@@ -341,8 +346,11 @@ var Permissions = {
341
346
  CreateEvents: 1n << 44n,
342
347
  UseExternalSounds: 1n << 45n,
343
348
  SendVoiceMessages: 1n << 46n,
349
+ SetVoiceChannelStatus: 1n << 48n,
344
350
  SendPolls: 1n << 49n,
345
- UseExternalApps: 1n << 50n
351
+ UseExternalApps: 1n << 50n,
352
+ PinMessages: 1n << 51n,
353
+ BypassSlowmode: 1n << 52n
346
354
  };
347
355
  var PermissionFlagsBits = {
348
356
  CreateInstantInvite: 1n << 0n,
@@ -392,8 +400,11 @@ var PermissionFlagsBits = {
392
400
  CreateEvents: 1n << 44n,
393
401
  UseExternalSounds: 1n << 45n,
394
402
  SendVoiceMessages: 1n << 46n,
403
+ SetVoiceChannelStatus: 1n << 48n,
395
404
  SendPolls: 1n << 49n,
396
- UseExternalApps: 1n << 50n
405
+ UseExternalApps: 1n << 50n,
406
+ PinMessages: 1n << 51n,
407
+ BypassSlowmode: 1n << 52n
397
408
  };
398
409
 
399
410
  class PermissionSet {
@@ -595,6 +606,10 @@ class PermissionSet {
595
606
  }
596
607
  return false;
597
608
  }
609
+ missing(...permissions) {
610
+ const wanted = new PermissionSet(permissions);
611
+ return wanted.toArray().filter((name) => !this.has(name));
612
+ }
598
613
  add(...permissions) {
599
614
  let bitfield = this.bitfield;
600
615
  for (let i = 0;i < permissions.length; i++) {
@@ -656,6 +671,7 @@ class PermissionsBitField extends PermissionSet {
656
671
  super(value);
657
672
  }
658
673
  }
674
+ var ALL_PERMISSIONS = Object.values(Permission).reduce((bits, bit) => bits | bit, 0n);
659
675
  // packages/types/src/gateway.ts
660
676
  var GatewayIntentBits = {
661
677
  Guilds: 1 << 0,
@@ -721,7 +737,7 @@ var InteractionResponseType = {
721
737
  // packages/rest/package.json
722
738
  var package_default = {
723
739
  name: "@lunibee/rest",
724
- version: "0.1.8",
740
+ version: "0.2.0",
725
741
  type: "module",
726
742
  module: "./src/index.ts",
727
743
  types: "./src/index.ts",
@@ -743,6 +759,9 @@ var REQUEST_DATA_KEYS = new Set([
743
759
  "auth",
744
760
  "signal"
745
761
  ]);
762
+ // packages/managers/src/index.ts
763
+ var BULK_DELETE_MAX_AGE_MS = 14 * 24 * 60 * 60000;
764
+
746
765
  // packages/ws/src/close-codes.ts
747
766
  var GatewayCloseCodes = {
748
767
  UnknownError: 4000,
@@ -1369,6 +1388,17 @@ var InteractionType = {
1369
1388
  ApplicationCommandAutocomplete: 4,
1370
1389
  ModalSubmit: 5
1371
1390
  };
1391
+ var EPHEMERAL = 64;
1392
+ var TOKEN_LIFETIME_MS = 15 * 60000;
1393
+ var DISCORD_EPOCH = 1420070400000n;
1394
+ function toMessageData(options) {
1395
+ if (typeof options === "string")
1396
+ return { content: options };
1397
+ const { ephemeral, ...data } = options;
1398
+ if (ephemeral)
1399
+ data.flags = (typeof data.flags === "number" ? data.flags : 0) | EPHEMERAL;
1400
+ return data;
1401
+ }
1372
1402
 
1373
1403
  class InteractionResponse {
1374
1404
  type;
@@ -1383,14 +1413,10 @@ class InteractionResponse {
1383
1413
  return this.data === undefined ? { type: this.type } : { type: this.type, data: this.data };
1384
1414
  }
1385
1415
  static message(options) {
1386
- const data = { ...options };
1387
- if (options.ephemeral) {
1388
- data.flags = (typeof options.flags === "number" ? options.flags : 0) | 64;
1389
- }
1390
- return new InteractionResponse(InteractionResponseType.ChannelMessage, data);
1416
+ return new InteractionResponse(InteractionResponseType.ChannelMessage, toMessageData(options));
1391
1417
  }
1392
1418
  static defer(ephemeral = false) {
1393
- return new InteractionResponse(InteractionResponseType.DeferredChannelMessage, ephemeral ? { flags: 64 } : undefined);
1419
+ return new InteractionResponse(InteractionResponseType.DeferredChannelMessage, ephemeral ? { flags: EPHEMERAL } : undefined);
1394
1420
  }
1395
1421
  static pong() {
1396
1422
  return new InteractionResponse(InteractionResponseType.Pong);
@@ -1408,6 +1434,7 @@ class Interaction {
1408
1434
  replied = false;
1409
1435
  deferred = false;
1410
1436
  #client;
1437
+ #acknowledging = false;
1411
1438
  constructor(client, data) {
1412
1439
  if (!data.id || !data.token)
1413
1440
  throw new TypeError("Interaction ID and token are required.");
@@ -1457,9 +1484,57 @@ class Interaction {
1457
1484
  return [3, 5, 6, 7, 8].includes(this.#componentType());
1458
1485
  }
1459
1486
  assertUnacknowledged() {
1460
- if (this.replied || this.deferred)
1487
+ if (this.replied || this.deferred || this.#acknowledging)
1461
1488
  throw new Error("Interaction has already been acknowledged.");
1462
1489
  }
1490
+ async acknowledge(response, state) {
1491
+ this.assertUnacknowledged();
1492
+ this.#acknowledging = true;
1493
+ try {
1494
+ const result = await this.postResponse(response);
1495
+ this[state] = true;
1496
+ return result;
1497
+ } finally {
1498
+ this.#acknowledging = false;
1499
+ }
1500
+ }
1501
+ get user() {
1502
+ const raw = this.data.member?.user ?? this.data.user;
1503
+ return raw ? new User(raw) : null;
1504
+ }
1505
+ get member() {
1506
+ const raw = this.data.member;
1507
+ if (!raw || !this.guildId)
1508
+ return null;
1509
+ return new GuildMember({
1510
+ ...raw,
1511
+ guild_id: this.guildId
1512
+ });
1513
+ }
1514
+ get createdTimestamp() {
1515
+ return Number((BigInt(this.id) >> 22n) + DISCORD_EPOCH);
1516
+ }
1517
+ get expiresAt() {
1518
+ return new Date(this.createdTimestamp + TOKEN_LIFETIME_MS);
1519
+ }
1520
+ get isExpired() {
1521
+ return Date.now() >= this.createdTimestamp + TOKEN_LIFETIME_MS;
1522
+ }
1523
+ #webhookMessage(method, messageId, data) {
1524
+ if (!this.#client.interactionWebhookMessage)
1525
+ return Promise.reject(new Error("This interaction client does not support webhook message access."));
1526
+ return this.#client.interactionWebhookMessage(method, this.applicationId, this.token, messageId, data);
1527
+ }
1528
+ fetchReply() {
1529
+ this.assertAcknowledged();
1530
+ return this.#webhookMessage("GET", "@original");
1531
+ }
1532
+ editFollowUp(messageId, options) {
1533
+ return this.#webhookMessage("PATCH", messageId, toMessageData(options));
1534
+ }
1535
+ async deleteFollowUp(messageId) {
1536
+ await this.#webhookMessage("DELETE", messageId);
1537
+ }
1463
1538
  assertAcknowledged() {
1464
1539
  if (!this.replied && !this.deferred)
1465
1540
  throw new Error("Interaction has not been acknowledged.");
@@ -1468,41 +1543,27 @@ class Interaction {
1468
1543
  return this.#client.postInteractionResponse(this.id, this.token, response);
1469
1544
  }
1470
1545
  async reply(options) {
1471
- this.assertUnacknowledged();
1472
- const payload = typeof options === "string" ? { content: options } : options;
1473
- const result = await this.#client.postInteractionResponse(this.id, this.token, InteractionResponse.message(payload));
1474
- this.replied = true;
1475
- return result;
1546
+ return this.acknowledge(InteractionResponse.message(toMessageData(options)), "replied");
1476
1547
  }
1477
1548
  async deferReply(ephemeral = false) {
1478
- this.assertUnacknowledged();
1479
- await this.#client.postInteractionResponse(this.id, this.token, InteractionResponse.defer(ephemeral));
1480
- this.deferred = true;
1549
+ await this.acknowledge(InteractionResponse.defer(ephemeral), "deferred");
1481
1550
  }
1482
1551
  editReply(options) {
1483
1552
  this.assertAcknowledged();
1484
- return this.#client.editInteractionReply(this.token, options);
1553
+ return this.#client.editInteractionReply(this.token, toMessageData(options));
1485
1554
  }
1486
1555
  deleteReply() {
1487
1556
  this.assertAcknowledged();
1488
1557
  return this.#client.deleteInteractionReply(this.token);
1489
1558
  }
1490
1559
  followUp(options) {
1491
- const payload = typeof options === "string" ? { content: options } : options;
1492
- return this.#client.followUpInteraction(this.token, payload);
1560
+ return this.#client.followUpInteraction(this.token, toMessageData(options));
1493
1561
  }
1494
1562
  async update(options) {
1495
- this.assertUnacknowledged();
1496
- const payload = typeof options === "string" ? { content: options } : options;
1497
- const result = await this.#client.postInteractionResponse(this.id, this.token, new InteractionResponse(InteractionResponseType.MessageUpdate, payload));
1498
- this.replied = true;
1499
- return result;
1563
+ return this.acknowledge(new InteractionResponse(InteractionResponseType.MessageUpdate, toMessageData(options)), "replied");
1500
1564
  }
1501
1565
  async showModal(modal) {
1502
- this.assertUnacknowledged();
1503
- const result = await this.#client.postInteractionResponse(this.id, this.token, new InteractionResponse(InteractionResponseType.Modal, modal));
1504
- this.replied = true;
1505
- return result;
1566
+ return this.acknowledge(new InteractionResponse(InteractionResponseType.Modal, modal), "replied");
1506
1567
  }
1507
1568
  }
1508
1569
 
@@ -1530,16 +1591,10 @@ class ComponentInteraction extends Interaction {
1530
1591
  return this.data?.data?.values ?? [];
1531
1592
  }
1532
1593
  async deferUpdate() {
1533
- this.assertUnacknowledged();
1534
- await this.postResponse(new InteractionResponse(InteractionResponseType.DeferredMessageUpdate));
1535
- this.deferred = true;
1594
+ await this.acknowledge(new InteractionResponse(InteractionResponseType.DeferredMessageUpdate), "deferred");
1536
1595
  }
1537
1596
  async update(options) {
1538
- this.assertUnacknowledged();
1539
- const payload = typeof options === "string" ? { content: options } : options;
1540
- const result = await this.postResponse(new InteractionResponse(InteractionResponseType.MessageUpdate, payload));
1541
- this.replied = true;
1542
- return result;
1597
+ return this.acknowledge(new InteractionResponse(InteractionResponseType.MessageUpdate, toMessageData(options)), "replied");
1543
1598
  }
1544
1599
  }
1545
1600
 
@@ -1582,8 +1637,7 @@ class AutocompleteInteraction extends Interaction {
1582
1637
  if (!Array.isArray(choices))
1583
1638
  throw new TypeError("Autocomplete choices must be an array.");
1584
1639
  const response = new InteractionResponse(InteractionResponseType.Autocomplete, { choices });
1585
- await this.postResponse(response);
1586
- this.replied = true;
1640
+ await this.acknowledge(response, "replied");
1587
1641
  }
1588
1642
  }
1589
1643
  function findFocused(options) {
@@ -1977,4 +2031,4 @@ export {
1977
2031
  createInteraction
1978
2032
  };
1979
2033
 
1980
- //# debugId=8FB0F7F12180BD8364756E2164756E21
2034
+ //# debugId=39460C3E91D6CD3564756E2164756E21