novaapp-sdk 1.3.2 → 1.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.js CHANGED
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  ActionRowBuilder: () => ActionRowBuilder,
24
+ AuditLogAPI: () => AuditLogAPI,
24
25
  ButtonBuilder: () => ButtonBuilder,
25
26
  ChannelsAPI: () => ChannelsAPI,
26
27
  Collection: () => Collection,
@@ -31,6 +32,7 @@ __export(index_exports, {
31
32
  HttpClient: () => HttpClient,
32
33
  InteractionOptions: () => InteractionOptions,
33
34
  InteractionsAPI: () => InteractionsAPI,
35
+ InvitesAPI: () => InvitesAPI,
34
36
  Logger: () => Logger,
35
37
  MembersAPI: () => MembersAPI,
36
38
  MessageBuilder: () => MessageBuilder,
@@ -39,19 +41,25 @@ __export(index_exports, {
39
41
  NovaChannel: () => NovaChannel,
40
42
  NovaClient: () => NovaClient,
41
43
  NovaInteraction: () => NovaInteraction,
44
+ NovaInvite: () => NovaInvite,
42
45
  NovaMember: () => NovaMember,
43
46
  NovaMessage: () => NovaMessage,
47
+ NovaRole: () => NovaRole,
48
+ NovaServerWrapper: () => NovaServerWrapper,
49
+ NovaWebhook: () => NovaWebhook,
44
50
  Paginator: () => Paginator,
45
51
  Permissions: () => Permissions,
46
52
  PermissionsAPI: () => PermissionsAPI,
47
53
  PermissionsBitfield: () => PermissionsBitfield,
48
54
  PollBuilder: () => PollBuilder,
49
55
  ReactionsAPI: () => ReactionsAPI,
56
+ RolesAPI: () => RolesAPI,
50
57
  SelectMenuBuilder: () => SelectMenuBuilder,
51
58
  ServersAPI: () => ServersAPI,
52
59
  SlashCommandBuilder: () => SlashCommandBuilder,
53
60
  SlashCommandOptionBuilder: () => SlashCommandOptionBuilder,
54
61
  TextInputBuilder: () => TextInputBuilder,
62
+ WebhooksAPI: () => WebhooksAPI,
55
63
  countdown: () => countdown,
56
64
  formatDuration: () => formatDuration,
57
65
  formatRelative: () => formatRelative,
@@ -316,16 +324,33 @@ var MembersAPI = class {
316
324
  }
317
325
  /**
318
326
  * Fetch members of a server the bot is in.
327
+ * Supports filtering by role and searching by username/displayName.
319
328
  *
320
329
  * @example
321
330
  * const members = await client.members.list('server-id', { limit: 50 })
331
+ * const admins = await client.members.list('server-id', { role: 'ADMIN' })
332
+ * const found = await client.members.list('server-id', { search: 'john' })
322
333
  */
323
334
  list(serverId, options = {}) {
324
335
  const params = new URLSearchParams();
325
336
  if (options.limit) params.set("limit", String(options.limit));
337
+ if (options.role) params.set("role", options.role);
338
+ if (options.search) params.set("search", options.search);
326
339
  const qs = params.toString();
327
340
  return this.http.get(`/servers/${serverId}/members${qs ? `?${qs}` : ""}`);
328
341
  }
342
+ /**
343
+ * Fetch a single member from a server by their user ID.
344
+ * Returns the member's custom role if assigned.
345
+ * Requires the `members.read` scope.
346
+ *
347
+ * @example
348
+ * const member = await client.members.fetch('server-id', 'user-id')
349
+ * console.log(member.customRole?.name ?? 'No custom role')
350
+ */
351
+ fetch(serverId, userId) {
352
+ return this.http.get(`/servers/${serverId}/members/${userId}`);
353
+ }
329
354
  /**
330
355
  * Kick a member from a server.
331
356
  * Bots cannot kick owners or admins (403 will be thrown).
@@ -418,6 +443,27 @@ var ServersAPI = class {
418
443
  list() {
419
444
  return this.http.get("/servers");
420
445
  }
446
+ /**
447
+ * Fetch a single server by ID.
448
+ * The bot must be a member of the server.
449
+ *
450
+ * @example
451
+ * const server = await client.servers.fetch('server-id')
452
+ * console.log(`${server.name} — ${server.memberCount} members`)
453
+ */
454
+ fetch(serverId) {
455
+ return this.http.get(`/servers/${serverId}`);
456
+ }
457
+ /**
458
+ * Update a server's name, description, or icon.
459
+ * Requires the `server.manage` scope.
460
+ *
461
+ * @example
462
+ * await client.servers.update('server-id', { name: 'Better Name', description: 'A great place!' })
463
+ */
464
+ update(serverId, options) {
465
+ return this.http.patch(`/servers/${serverId}`, options);
466
+ }
421
467
  /**
422
468
  * Fetch all roles in a server.
423
469
  * Results are sorted by position (lowest first).
@@ -467,6 +513,26 @@ var InteractionsAPI = class {
467
513
  options
468
514
  );
469
515
  }
516
+ /**
517
+ * Respond to an autocomplete interaction with a list of suggested choices.
518
+ * The gateway fires `AUTOCOMPLETE` interactions when a user is typing in
519
+ * an option that has `autocomplete: true`. Call this within ~3 seconds.
520
+ *
521
+ * @example
522
+ * client.autocomplete('search', async (interaction) => {
523
+ * const query = interaction.autocomplete?.value ?? ''
524
+ * const results = await db.search(query)
525
+ * await client.interactions.autocomplete(interaction.id,
526
+ * results.map(r => ({ name: r.title, value: r.id }))
527
+ * )
528
+ * })
529
+ */
530
+ autocomplete(interactionId, choices) {
531
+ return this.http.post(
532
+ `/interactions/${interactionId}/autocomplete`,
533
+ { choices }
534
+ );
535
+ }
470
536
  /**
471
537
  * Poll for pending (unacknowledged) interactions.
472
538
  * Useful when not using the WebSocket gateway.
@@ -761,6 +827,239 @@ var ReactionsAPI = class {
761
827
  }
762
828
  };
763
829
 
830
+ // src/api/roles.ts
831
+ var RolesAPI = class {
832
+ constructor(http) {
833
+ this.http = http;
834
+ }
835
+ /**
836
+ * List all custom roles in a server, sorted by position.
837
+ *
838
+ * @example
839
+ * const roles = await client.roles.list('server-id')
840
+ * const adminRole = roles.find(r => r.name === 'Admin')
841
+ */
842
+ list(serverId) {
843
+ return this.http.get(`/servers/${serverId}/roles`);
844
+ }
845
+ /**
846
+ * Create a new custom role in a server.
847
+ * Requires the `roles.manage` scope.
848
+ *
849
+ * @example
850
+ * const role = await client.roles.create('server-id', {
851
+ * name: 'Verified',
852
+ * color: '#00d4ff',
853
+ * hoist: true,
854
+ * permissions: { sendMessages: true, addReactions: true },
855
+ * })
856
+ */
857
+ create(serverId, options) {
858
+ return this.http.post(`/servers/${serverId}/roles`, options);
859
+ }
860
+ /**
861
+ * Edit an existing role.
862
+ * Requires the `roles.manage` scope.
863
+ *
864
+ * @example
865
+ * await client.roles.edit('role-id', { color: '#ff0000', name: 'Danger' })
866
+ */
867
+ edit(roleId, options) {
868
+ return this.http.patch(`/roles/${roleId}`, options);
869
+ }
870
+ /**
871
+ * Delete a custom role from a server.
872
+ * Any member currently assigned this role will have it removed automatically.
873
+ * Requires the `roles.manage` scope.
874
+ *
875
+ * @example
876
+ * await client.roles.delete('role-id')
877
+ */
878
+ delete(roleId) {
879
+ return this.http.delete(`/roles/${roleId}`);
880
+ }
881
+ /**
882
+ * Assign a custom role to a server member.
883
+ * Requires the `members.roles` scope.
884
+ *
885
+ * @example
886
+ * await client.roles.assign('server-id', 'user-id', 'role-id')
887
+ */
888
+ assign(serverId, userId, roleId) {
889
+ return this.http.post(`/servers/${serverId}/members/${userId}/roles/${roleId}`);
890
+ }
891
+ /**
892
+ * Remove a custom role from a server member.
893
+ * Requires the `members.roles` scope.
894
+ *
895
+ * @example
896
+ * await client.roles.remove('server-id', 'user-id', 'role-id')
897
+ */
898
+ remove(serverId, userId, roleId) {
899
+ return this.http.delete(`/servers/${serverId}/members/${userId}/roles/${roleId}`);
900
+ }
901
+ };
902
+
903
+ // src/api/invites.ts
904
+ var InvitesAPI = class {
905
+ constructor(http) {
906
+ this.http = http;
907
+ }
908
+ /**
909
+ * List all active invites for a server.
910
+ *
911
+ * @example
912
+ * const invites = await client.invites.list('server-id')
913
+ * console.log(`${invites.length} active invites`)
914
+ */
915
+ list(serverId) {
916
+ return this.http.get(`/servers/${serverId}/invites`);
917
+ }
918
+ /**
919
+ * Create a new invite for a server.
920
+ * Requires the `invites.manage` scope.
921
+ *
922
+ * @example
923
+ * // A one-time invite that expires in 24 hours
924
+ * const invite = await client.invites.create('server-id', {
925
+ * maxUses: 1,
926
+ * expiresAt: new Date(Date.now() + 86_400_000).toISOString(),
927
+ * })
928
+ * console.log(`https://novachatapp.com/invite/${invite.code}`)
929
+ */
930
+ create(serverId, options = {}) {
931
+ return this.http.post(`/servers/${serverId}/invites`, options);
932
+ }
933
+ /**
934
+ * Fetch a single invite by its code.
935
+ *
936
+ * @example
937
+ * const invite = await client.invites.fetch('abc123')
938
+ * console.log(`${invite.uses} / ${invite.maxUses ?? '∞'} uses`)
939
+ */
940
+ fetch(code) {
941
+ return this.http.get(`/invites/${code}`);
942
+ }
943
+ /**
944
+ * Revoke (delete) an invite.
945
+ * Requires the `invites.manage` scope.
946
+ *
947
+ * @example
948
+ * await client.invites.revoke('abc123')
949
+ */
950
+ revoke(code) {
951
+ return this.http.delete(`/invites/${code}`);
952
+ }
953
+ };
954
+
955
+ // src/api/webhooks.ts
956
+ var WebhooksAPI = class {
957
+ constructor(http) {
958
+ this.http = http;
959
+ }
960
+ /**
961
+ * List all webhooks in a channel.
962
+ * Requires the `webhooks.manage` scope.
963
+ *
964
+ * @example
965
+ * const webhooks = await client.webhooks.list('channel-id')
966
+ */
967
+ list(channelId) {
968
+ return this.http.get(`/channels/${channelId}/webhooks`);
969
+ }
970
+ /**
971
+ * Create a webhook in a channel.
972
+ * Requires the `webhooks.manage` scope.
973
+ *
974
+ * @example
975
+ * const webhook = await client.webhooks.create('channel-id', { name: 'Announcements' })
976
+ * console.log('Token:', webhook.token)
977
+ */
978
+ create(channelId, options) {
979
+ return this.http.post(`/channels/${channelId}/webhooks`, options);
980
+ }
981
+ /**
982
+ * Fetch a webhook by its ID.
983
+ * Requires the `webhooks.manage` scope.
984
+ *
985
+ * @example
986
+ * const webhook = await client.webhooks.fetch('webhook-id')
987
+ */
988
+ fetch(webhookId) {
989
+ return this.http.get(`/webhooks/${webhookId}`);
990
+ }
991
+ /**
992
+ * Edit a webhook's name and/or target channel.
993
+ * Requires the `webhooks.manage` scope.
994
+ *
995
+ * @example
996
+ * await client.webhooks.edit('webhook-id', { name: 'New Name', channelId: 'other-channel' })
997
+ */
998
+ edit(webhookId, options) {
999
+ return this.http.patch(`/webhooks/${webhookId}`, options);
1000
+ }
1001
+ /**
1002
+ * Delete a webhook.
1003
+ * Requires the `webhooks.manage` scope.
1004
+ *
1005
+ * @example
1006
+ * await client.webhooks.delete('webhook-id')
1007
+ */
1008
+ delete(webhookId) {
1009
+ return this.http.delete(`/webhooks/${webhookId}`);
1010
+ }
1011
+ /**
1012
+ * Execute a webhook — post a message to the webhook's channel.
1013
+ * Does not require any extra scope (uses the webhook data already owned by
1014
+ * this bot application).
1015
+ *
1016
+ * @example
1017
+ * await client.webhooks.execute('webhook-id', {
1018
+ * content: '🚀 Deployment successful!',
1019
+ * username: 'Deploy Bot',
1020
+ * })
1021
+ */
1022
+ execute(webhookId, options) {
1023
+ return this.http.post(`/webhooks/${webhookId}/execute`, options);
1024
+ }
1025
+ };
1026
+
1027
+ // src/api/auditlog.ts
1028
+ var AuditLogAPI = class {
1029
+ constructor(http) {
1030
+ this.http = http;
1031
+ }
1032
+ /**
1033
+ * Fetch the audit log for a server.
1034
+ * Requires the `audit-log.read` scope.
1035
+ *
1036
+ * You can filter by action type, actor user ID, and paginate backwards
1037
+ * using the `before` cursor (an ISO timestamp).
1038
+ *
1039
+ * @example
1040
+ * // Most recent 50 entries
1041
+ * const entries = await client.auditLog.fetch('server-id')
1042
+ *
1043
+ * // Only kick and ban actions
1044
+ * const modActions = await client.auditLog.fetch('server-id', {
1045
+ * action: 'member.banned',
1046
+ * limit: 20,
1047
+ * })
1048
+ *
1049
+ * // All actions performed by a specific user
1050
+ * const byUser = await client.auditLog.fetch('server-id', { userId: 'user-id' })
1051
+ */
1052
+ fetch(serverId, options = {}) {
1053
+ const params = new URLSearchParams();
1054
+ if (options.limit) params.set("limit", String(options.limit));
1055
+ if (options.action) params.set("action", options.action);
1056
+ if (options.userId) params.set("userId", options.userId);
1057
+ if (options.before) params.set("before", options.before);
1058
+ const qs = params.toString();
1059
+ return this.http.get(`/servers/${serverId}/audit-logs${qs ? `?${qs}` : ""}`);
1060
+ }
1061
+ };
1062
+
764
1063
  // src/structures/NovaInteraction.ts
765
1064
  var InteractionOptions = class {
766
1065
  constructor(data) {
@@ -824,6 +1123,20 @@ var NovaInteraction = class _NovaInteraction {
824
1123
  this.createdAt = _raw.createdAt;
825
1124
  this.options = new InteractionOptions(_raw.data);
826
1125
  }
1126
+ /**
1127
+ * For `AUTOCOMPLETE` interactions — the option being completed.
1128
+ * Contains `name` (option name) and `value` (partial text typed so far).
1129
+ * `null` for all other interaction types.
1130
+ *
1131
+ * @example
1132
+ * client.autocomplete('search', async (interaction) => {
1133
+ * const query = interaction.autocomplete?.value ?? ''
1134
+ * await interaction.respondAutocomplete([{ name: query, value: query }])
1135
+ * })
1136
+ */
1137
+ get autocomplete() {
1138
+ return this._raw.autocomplete ?? null;
1139
+ }
827
1140
  // ── Type guards ─────────────────────────────────────────────────────────────
828
1141
  /** `true` when triggered by a `/slash` command. */
829
1142
  isSlashCommand() {
@@ -853,6 +1166,21 @@ var NovaInteraction = class _NovaInteraction {
853
1166
  isAutocomplete() {
854
1167
  return this.type === "AUTOCOMPLETE";
855
1168
  }
1169
+ /**
1170
+ * Send autocomplete suggestions back to the user.
1171
+ * Call this inside a `client.autocomplete()` handler.
1172
+ * Up to 25 choices are shown; each needs a `name` (displayed) and `value` (submitted).
1173
+ *
1174
+ * @example
1175
+ * client.autocomplete('color', async (interaction) => {
1176
+ * const query = interaction.autocomplete?.value ?? ''
1177
+ * const colors = ['red', 'green', 'blue'].filter(c => c.startsWith(query))
1178
+ * await interaction.respondAutocomplete(colors.map(c => ({ name: c, value: c })))
1179
+ * })
1180
+ */
1181
+ respondAutocomplete(choices) {
1182
+ return this._api.autocomplete(this.id, choices);
1183
+ }
856
1184
  /** `true` when triggered via a context-menu command. */
857
1185
  isContextMenu() {
858
1186
  return this.type === "CONTEXT_MENU";
@@ -1327,6 +1655,338 @@ var NovaMember = class {
1327
1655
  }
1328
1656
  };
1329
1657
 
1658
+ // src/structures/NovaRole.ts
1659
+ var NovaRole = class {
1660
+ constructor(raw, roles) {
1661
+ this.id = raw.id;
1662
+ this.name = raw.name;
1663
+ this.color = raw.color;
1664
+ this.position = raw.position;
1665
+ this.serverId = raw.serverId;
1666
+ this.hoist = raw.hoist;
1667
+ this.createdAt = new Date(raw.createdAt);
1668
+ this._roles = roles;
1669
+ }
1670
+ // ─── Convenience methods ──────────────────────────────────────────────────
1671
+ /**
1672
+ * Edit this role's name, colour, hoist flag, or permissions.
1673
+ *
1674
+ * @example
1675
+ * await role.edit({ color: '#ff0000', name: 'Red Team' })
1676
+ */
1677
+ edit(options) {
1678
+ return this._roles.edit(this.id, options);
1679
+ }
1680
+ /**
1681
+ * Delete this role from the server.
1682
+ * Any members currently assigned this role will have it removed.
1683
+ *
1684
+ * @example
1685
+ * await role.delete()
1686
+ */
1687
+ delete() {
1688
+ return this._roles.delete(this.id);
1689
+ }
1690
+ /**
1691
+ * Assign this role to a server member.
1692
+ *
1693
+ * @example
1694
+ * await role.assign('user-id')
1695
+ */
1696
+ assign(userId) {
1697
+ return this._roles.assign(this.serverId, userId, this.id);
1698
+ }
1699
+ /**
1700
+ * Remove this role from a server member.
1701
+ *
1702
+ * @example
1703
+ * await role.remove('user-id')
1704
+ */
1705
+ remove(userId) {
1706
+ return this._roles.remove(this.serverId, userId, this.id);
1707
+ }
1708
+ // ─── Helpers ─────────────────────────────────────────────────────────────
1709
+ /** Returns `true` if the role has a custom hex colour set. */
1710
+ hasColor() {
1711
+ return this.color !== null;
1712
+ }
1713
+ /** Returns the CSS-safe hex colour string. Falls back to `'#99aab5'` (grey). */
1714
+ toHex() {
1715
+ return this.color ?? "#99aab5";
1716
+ }
1717
+ toJSON() {
1718
+ return {
1719
+ id: this.id,
1720
+ name: this.name,
1721
+ color: this.color,
1722
+ position: this.position,
1723
+ serverId: this.serverId,
1724
+ hoist: this.hoist,
1725
+ permissions: {},
1726
+ createdAt: this.createdAt.toISOString()
1727
+ };
1728
+ }
1729
+ };
1730
+
1731
+ // src/structures/NovaServer.ts
1732
+ var NovaServerWrapper = class {
1733
+ constructor(raw, servers, channels, members, invites, roles, messages) {
1734
+ this.id = raw.id;
1735
+ this.name = raw.name;
1736
+ this.icon = raw.icon;
1737
+ this.description = raw.description;
1738
+ this.memberCount = raw.memberCount;
1739
+ this.channelCount = raw.channelCount;
1740
+ this.joinedAt = new Date(raw.joinedAt);
1741
+ this._servers = servers;
1742
+ this._channels = channels;
1743
+ this._members = members;
1744
+ this._invites = invites;
1745
+ this._roles = roles;
1746
+ this._messages = messages;
1747
+ }
1748
+ // ─── Server management ────────────────────────────────────────────────────
1749
+ /**
1750
+ * Update this server's name, description, or icon.
1751
+ * Requires the `server.manage` scope.
1752
+ *
1753
+ * @example
1754
+ * await server.update({ name: 'New Name' })
1755
+ */
1756
+ update(options) {
1757
+ return this._servers.update(this.id, options);
1758
+ }
1759
+ // ─── Channels ─────────────────────────────────────────────────────────────
1760
+ /**
1761
+ * Fetch all channels in this server.
1762
+ *
1763
+ * @example
1764
+ * const channels = await server.fetchChannels()
1765
+ * const text = channels.filter(c => c.type === 'TEXT')
1766
+ */
1767
+ fetchChannels() {
1768
+ return this._channels.list(this.id);
1769
+ }
1770
+ /**
1771
+ * Create a new channel in this server.
1772
+ * Requires the `channels.manage` scope.
1773
+ *
1774
+ * @example
1775
+ * const ch = await server.createChannel({ name: 'bot-logs', type: 'TEXT' })
1776
+ */
1777
+ createChannel(options) {
1778
+ return this._channels.create(this.id, options);
1779
+ }
1780
+ // ─── Members ─────────────────────────────────────────────────────────────
1781
+ /**
1782
+ * Fetch members in this server.
1783
+ *
1784
+ * @example
1785
+ * const members = await server.fetchMembers({ limit: 100 })
1786
+ */
1787
+ fetchMembers(options = {}) {
1788
+ return this._members.list(this.id, options);
1789
+ }
1790
+ /**
1791
+ * Fetch a single member by user ID.
1792
+ *
1793
+ * @example
1794
+ * const member = await server.fetchMember('user-id')
1795
+ */
1796
+ fetchMember(userId) {
1797
+ return this._members.fetch(this.id, userId);
1798
+ }
1799
+ /**
1800
+ * Kick a member from this server.
1801
+ *
1802
+ * @example
1803
+ * await server.kick('user-id')
1804
+ */
1805
+ kick(userId) {
1806
+ return this._members.kick(this.id, userId);
1807
+ }
1808
+ /**
1809
+ * Ban a member from this server.
1810
+ *
1811
+ * @example
1812
+ * await server.ban('user-id', 'Spamming')
1813
+ */
1814
+ ban(userId, reason) {
1815
+ return this._members.ban(this.id, userId, reason);
1816
+ }
1817
+ /**
1818
+ * Fetch the ban list for this server.
1819
+ */
1820
+ fetchBans() {
1821
+ return this._members.listBans(this.id);
1822
+ }
1823
+ // ─── Roles ────────────────────────────────────────────────────────────────
1824
+ /**
1825
+ * Fetch all custom roles in this server.
1826
+ *
1827
+ * @example
1828
+ * const roles = await server.fetchRoles()
1829
+ */
1830
+ fetchRoles() {
1831
+ return this._roles.list(this.id);
1832
+ }
1833
+ // ─── Invites ──────────────────────────────────────────────────────────────
1834
+ /**
1835
+ * Fetch all active invites for this server.
1836
+ *
1837
+ * @example
1838
+ * const invites = await server.fetchInvites()
1839
+ */
1840
+ fetchInvites() {
1841
+ return this._invites.list(this.id);
1842
+ }
1843
+ /**
1844
+ * Create an invite for this server.
1845
+ *
1846
+ * @example
1847
+ * const invite = await server.createInvite({ maxUses: 10 })
1848
+ * console.log(`https://novachatapp.com/invite/${invite.code}`)
1849
+ */
1850
+ createInvite(options = {}) {
1851
+ return this._invites.create(this.id, options);
1852
+ }
1853
+ // ─── Messaging shortcut ───────────────────────────────────────────────────
1854
+ /**
1855
+ * Send a message to a channel in this server by channel ID.
1856
+ *
1857
+ * @example
1858
+ * await server.send('channel-id', 'Hello, server!')
1859
+ */
1860
+ send(channelId, content) {
1861
+ return this._messages.send(channelId, { content });
1862
+ }
1863
+ // ─── Helpers ─────────────────────────────────────────────────────────────
1864
+ toJSON() {
1865
+ return {
1866
+ id: this.id,
1867
+ name: this.name,
1868
+ icon: this.icon,
1869
+ description: this.description,
1870
+ memberCount: this.memberCount,
1871
+ channelCount: this.channelCount,
1872
+ joinedAt: this.joinedAt.toISOString()
1873
+ };
1874
+ }
1875
+ };
1876
+
1877
+ // src/structures/NovaInvite.ts
1878
+ var NovaInvite = class {
1879
+ constructor(raw, invites) {
1880
+ this.code = raw.code;
1881
+ this.serverId = raw.serverId;
1882
+ this.creatorId = raw.creatorId;
1883
+ this.uses = raw.uses;
1884
+ this.maxUses = raw.maxUses;
1885
+ this.expiresAt = raw.expiresAt ? new Date(raw.expiresAt) : null;
1886
+ this.createdAt = new Date(raw.createdAt);
1887
+ this._invites = invites;
1888
+ }
1889
+ // ─── Helpers ─────────────────────────────────────────────────────────────
1890
+ /** The full URL users can follow to join the server. */
1891
+ get url() {
1892
+ return `https://novachatapp.com/invite/${this.code}`;
1893
+ }
1894
+ /**
1895
+ * Returns `true` if the invite has passed its expiry time.
1896
+ * Always `false` for invites with no expiry.
1897
+ */
1898
+ isExpired() {
1899
+ if (!this.expiresAt) return false;
1900
+ return this.expiresAt < /* @__PURE__ */ new Date();
1901
+ }
1902
+ /**
1903
+ * Returns `true` if the invite has reached its maximum use count.
1904
+ * Always `false` for unlimited invites.
1905
+ */
1906
+ isExhausted() {
1907
+ if (this.maxUses === null) return false;
1908
+ return this.uses >= this.maxUses;
1909
+ }
1910
+ /** Whether this invite is still usable (not expired and not exhausted). */
1911
+ isValid() {
1912
+ return !this.isExpired() && !this.isExhausted();
1913
+ }
1914
+ /**
1915
+ * Revoke (delete) this invite, making the code unusable.
1916
+ * Requires the `invites.manage` scope.
1917
+ *
1918
+ * @example
1919
+ * await invite.revoke()
1920
+ */
1921
+ revoke() {
1922
+ return this._invites.revoke(this.code);
1923
+ }
1924
+ toJSON() {
1925
+ return {
1926
+ code: this.code,
1927
+ serverId: this.serverId,
1928
+ creatorId: this.creatorId,
1929
+ uses: this.uses,
1930
+ maxUses: this.maxUses,
1931
+ expiresAt: this.expiresAt?.toISOString() ?? null,
1932
+ createdAt: this.createdAt.toISOString()
1933
+ };
1934
+ }
1935
+ };
1936
+
1937
+ // src/structures/NovaWebhook.ts
1938
+ var NovaWebhook = class {
1939
+ constructor(raw, webhooks) {
1940
+ this.id = raw.id;
1941
+ this.serverId = raw.serverId;
1942
+ this.channelId = raw.channelId;
1943
+ this.name = raw.name;
1944
+ this.token = raw.token;
1945
+ this.createdAt = new Date(raw.createdAt);
1946
+ this._webhooks = webhooks;
1947
+ }
1948
+ // ─── Convenience methods ──────────────────────────────────────────────────
1949
+ /**
1950
+ * Edit this webhook's name or target channel.
1951
+ * Requires the `webhooks.manage` scope.
1952
+ *
1953
+ * @example
1954
+ * await webhook.edit({ name: 'New Name', channelId: 'other-channel-id' })
1955
+ */
1956
+ edit(options) {
1957
+ return this._webhooks.edit(this.id, options);
1958
+ }
1959
+ /**
1960
+ * Delete this webhook.
1961
+ * Requires the `webhooks.manage` scope.
1962
+ *
1963
+ * @example
1964
+ * await webhook.delete()
1965
+ */
1966
+ delete() {
1967
+ return this._webhooks.delete(this.id);
1968
+ }
1969
+ /**
1970
+ * Post a message via this webhook.
1971
+ *
1972
+ * @example
1973
+ * await webhook.execute({ content: '❌ Tests failed on branch main', username: 'CI' })
1974
+ */
1975
+ execute(options) {
1976
+ return this._webhooks.execute(this.id, options);
1977
+ }
1978
+ toJSON() {
1979
+ return {
1980
+ id: this.id,
1981
+ serverId: this.serverId,
1982
+ channelId: this.channelId,
1983
+ name: this.name,
1984
+ token: this.token,
1985
+ createdAt: this.createdAt.toISOString()
1986
+ };
1987
+ }
1988
+ };
1989
+
1330
1990
  // src/client.ts
1331
1991
  var NovaClient = class extends import_node_events.EventEmitter {
1332
1992
  constructor(options) {
@@ -1335,11 +1995,12 @@ var NovaClient = class extends import_node_events.EventEmitter {
1335
1995
  this.botUser = null;
1336
1996
  this.socket = null;
1337
1997
  this._cronTimers = [];
1338
- // ── Command / component routing ───────────────────────────────────────────────────
1998
+ // ── Command / component routing ────────────────────────────────────────────
1339
1999
  this._commandHandlers = /* @__PURE__ */ new Map();
1340
2000
  this._buttonHandlers = /* @__PURE__ */ new Map();
1341
2001
  this._selectHandlers = /* @__PURE__ */ new Map();
1342
2002
  this._modalHandlers = /* @__PURE__ */ new Map();
2003
+ this._autocompleteHandlers = /* @__PURE__ */ new Map();
1343
2004
  if (!options.token) {
1344
2005
  throw new Error("[nova-bot-sdk] A bot token is required.");
1345
2006
  }
@@ -1359,6 +2020,10 @@ var NovaClient = class extends import_node_events.EventEmitter {
1359
2020
  this.permissions = new PermissionsAPI(this.http);
1360
2021
  this.channels = new ChannelsAPI(this.http);
1361
2022
  this.reactions = new ReactionsAPI(this.http);
2023
+ this.roles = new RolesAPI(this.http);
2024
+ this.invites = new InvitesAPI(this.http);
2025
+ this.webhooks = new WebhooksAPI(this.http);
2026
+ this.auditLog = new AuditLogAPI(this.http);
1362
2027
  this.on("error", () => {
1363
2028
  });
1364
2029
  const cleanup = () => this.disconnect();
@@ -1424,6 +2089,26 @@ var NovaClient = class extends import_node_events.EventEmitter {
1424
2089
  this._modalHandlers.set(customId, handler);
1425
2090
  return this;
1426
2091
  }
2092
+ /**
2093
+ * Register a handler for an autocomplete interaction by command name.
2094
+ * Called when the user is typing in an option with `autocomplete: true`.
2095
+ * The handler receives the interaction with `interaction.autocomplete.value`
2096
+ * containing the partial text, and should call `interaction.respondAutocomplete()`
2097
+ * to send completion suggestions.
2098
+ *
2099
+ * @example
2100
+ * client.autocomplete('search', async (interaction) => {
2101
+ * const query = interaction.autocomplete?.value ?? ''
2102
+ * const results = await myDB.search(query)
2103
+ * await interaction.respondAutocomplete(
2104
+ * results.map(r => ({ name: r.label, value: r.id }))
2105
+ * )
2106
+ * })
2107
+ */
2108
+ autocomplete(commandName, handler) {
2109
+ this._autocompleteHandlers.set(commandName, handler);
2110
+ return this;
2111
+ }
1427
2112
  /**
1428
2113
  * Connect to the Nova WebSocket gateway.
1429
2114
  * Resolves when the `ready` event is received.
@@ -1475,6 +2160,8 @@ var NovaClient = class extends import_node_events.EventEmitter {
1475
2160
  run(this._selectHandlers.get(interaction.customId));
1476
2161
  } else if (interaction.isModalSubmit() && interaction.customId) {
1477
2162
  run(this._modalHandlers.get(interaction.customId));
2163
+ } else if (interaction.isAutocomplete() && interaction.commandName) {
2164
+ run(this._autocompleteHandlers.get(interaction.commandName));
1478
2165
  }
1479
2166
  });
1480
2167
  this.socket.on("bot:event", (event) => {
@@ -1539,6 +2226,15 @@ var NovaClient = class extends import_node_events.EventEmitter {
1539
2226
  case "user.updated_profile":
1540
2227
  this.emit("memberUpdate", event.data);
1541
2228
  break;
2229
+ case "user.role_added":
2230
+ this.emit("memberRoleAdded", event.data);
2231
+ break;
2232
+ case "user.role_removed":
2233
+ this.emit("memberRoleRemoved", event.data);
2234
+ break;
2235
+ case "server.updated":
2236
+ this.emit("serverUpdate", event.data);
2237
+ break;
1542
2238
  }
1543
2239
  });
1544
2240
  this.socket.on("bot:error", (err) => {
@@ -1631,18 +2327,92 @@ var NovaClient = class extends import_node_events.EventEmitter {
1631
2327
  }
1632
2328
  /**
1633
2329
  * Fetch a single member from a server and return them as a `NovaMember` wrapper.
1634
- * Throws if the user is not found in the server.
2330
+ * Uses the dedicated single-member endpoint (more efficient than listing all members).
1635
2331
  *
1636
2332
  * @example
1637
2333
  * const member = await client.fetchMember('server-id', 'user-id')
1638
2334
  * await member.dm('Welcome!')
1639
2335
  */
1640
2336
  async fetchMember(serverId, userId) {
1641
- const list = await this.members.list(serverId);
1642
- const raw = list.find((m) => m.user.id === userId);
1643
- if (!raw) throw new Error(`[nova-bot-sdk] Member ${userId} not found in server ${serverId}`);
2337
+ const raw = await this.members.fetch(serverId, userId);
1644
2338
  return new NovaMember(raw, serverId, this.members);
1645
2339
  }
2340
+ /**
2341
+ * Fetch a single server by ID and return it as a `NovaServerWrapper`.
2342
+ *
2343
+ * @example
2344
+ * const server = await client.fetchServer('server-id')
2345
+ * console.log(`${server.name} — ${server.memberCount} members`)
2346
+ */
2347
+ async fetchServer(serverId) {
2348
+ const raw = await this.servers.fetch(serverId);
2349
+ return new NovaServerWrapper(raw, this.servers, this.channels, this.members, this.invites, this.roles, this.messages);
2350
+ }
2351
+ /**
2352
+ * Fetch all servers the bot is in and return them as `NovaServerWrapper` objects.
2353
+ *
2354
+ * @example
2355
+ * const servers = await client.fetchServers()
2356
+ * for (const s of servers) console.log(s.name)
2357
+ */
2358
+ async fetchServers() {
2359
+ const list = await this.servers.list();
2360
+ return list.map((raw) => new NovaServerWrapper(raw, this.servers, this.channels, this.members, this.invites, this.roles, this.messages));
2361
+ }
2362
+ /**
2363
+ * Fetch all custom roles in a server and return them as `NovaRole` wrappers.
2364
+ *
2365
+ * @example
2366
+ * const roles = await client.fetchRoles('server-id')
2367
+ * const mod = roles.find(r => r.name === 'Moderator')
2368
+ */
2369
+ async fetchRoles(serverId) {
2370
+ const list = await this.roles.list(serverId);
2371
+ return list.map((raw) => new NovaRole(raw, this.roles));
2372
+ }
2373
+ /**
2374
+ * Fetch all active invites for a server and return them as `NovaInvite` wrappers.
2375
+ *
2376
+ * @example
2377
+ * const invites = await client.fetchInvites('server-id')
2378
+ * const active = invites.filter(i => i.isValid())
2379
+ */
2380
+ async fetchInvites(serverId) {
2381
+ const list = await this.invites.list(serverId);
2382
+ return list.map((raw) => new NovaInvite(raw, this.invites));
2383
+ }
2384
+ /**
2385
+ * Fetch a single invite by code and return it as a `NovaInvite` wrapper.
2386
+ *
2387
+ * @example
2388
+ * const invite = await client.fetchInvite('abc123')
2389
+ * if (invite.isExpired()) await invite.revoke()
2390
+ */
2391
+ async fetchInvite(code) {
2392
+ const raw = await this.invites.fetch(code);
2393
+ return new NovaInvite(raw, this.invites);
2394
+ }
2395
+ /**
2396
+ * Fetch all webhooks in a channel and return them as `NovaWebhook` wrappers.
2397
+ *
2398
+ * @example
2399
+ * const webhooks = await client.fetchWebhooks('channel-id')
2400
+ */
2401
+ async fetchWebhooks(channelId) {
2402
+ const list = await this.webhooks.list(channelId);
2403
+ return list.map((raw) => new NovaWebhook(raw, this.webhooks));
2404
+ }
2405
+ /**
2406
+ * Fetch a single webhook by ID and return it as a `NovaWebhook` wrapper.
2407
+ *
2408
+ * @example
2409
+ * const webhook = await client.fetchWebhook('webhook-id')
2410
+ * await webhook.execute({ content: 'Build passed! ✅' })
2411
+ */
2412
+ async fetchWebhook(webhookId) {
2413
+ const raw = await this.webhooks.fetch(webhookId);
2414
+ return new NovaWebhook(raw, this.webhooks);
2415
+ }
1646
2416
  // ─── Event fence ──────────────────────────────────────────────────────────────
1647
2417
  /**
1648
2418
  * Wait for a specific event to be emitted, optionally filtered.
@@ -3042,6 +3812,7 @@ function countdown(target) {
3042
3812
  // Annotate the CommonJS export names for ESM import in node:
3043
3813
  0 && (module.exports = {
3044
3814
  ActionRowBuilder,
3815
+ AuditLogAPI,
3045
3816
  ButtonBuilder,
3046
3817
  ChannelsAPI,
3047
3818
  Collection,
@@ -3052,6 +3823,7 @@ function countdown(target) {
3052
3823
  HttpClient,
3053
3824
  InteractionOptions,
3054
3825
  InteractionsAPI,
3826
+ InvitesAPI,
3055
3827
  Logger,
3056
3828
  MembersAPI,
3057
3829
  MessageBuilder,
@@ -3060,19 +3832,25 @@ function countdown(target) {
3060
3832
  NovaChannel,
3061
3833
  NovaClient,
3062
3834
  NovaInteraction,
3835
+ NovaInvite,
3063
3836
  NovaMember,
3064
3837
  NovaMessage,
3838
+ NovaRole,
3839
+ NovaServerWrapper,
3840
+ NovaWebhook,
3065
3841
  Paginator,
3066
3842
  Permissions,
3067
3843
  PermissionsAPI,
3068
3844
  PermissionsBitfield,
3069
3845
  PollBuilder,
3070
3846
  ReactionsAPI,
3847
+ RolesAPI,
3071
3848
  SelectMenuBuilder,
3072
3849
  ServersAPI,
3073
3850
  SlashCommandBuilder,
3074
3851
  SlashCommandOptionBuilder,
3075
3852
  TextInputBuilder,
3853
+ WebhooksAPI,
3076
3854
  countdown,
3077
3855
  formatDuration,
3078
3856
  formatRelative,