@buape/carbon 0.11.0 → 0.13.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 (245) hide show
  1. package/README.md +1 -1
  2. package/dist/package.json +3 -3
  3. package/dist/src/abstracts/AnySelectMenu.d.ts +7 -0
  4. package/dist/src/abstracts/AnySelectMenu.d.ts.map +1 -1
  5. package/dist/src/abstracts/AnySelectMenu.js +8 -0
  6. package/dist/src/abstracts/AnySelectMenu.js.map +1 -1
  7. package/dist/src/abstracts/BaseGuildChannel.d.ts +1 -2
  8. package/dist/src/abstracts/BaseGuildChannel.d.ts.map +1 -1
  9. package/dist/src/abstracts/BaseGuildChannel.js.map +1 -1
  10. package/dist/src/abstracts/BaseInteraction.d.ts.map +1 -1
  11. package/dist/src/abstracts/BaseInteraction.js +1 -1
  12. package/dist/src/abstracts/BaseInteraction.js.map +1 -1
  13. package/dist/src/abstracts/BaseListener.d.ts +3 -3
  14. package/dist/src/abstracts/BaseListener.d.ts.map +1 -1
  15. package/dist/src/abstracts/BaseListener.js.map +1 -1
  16. package/dist/src/abstracts/BaseModalComponent.d.ts +10 -2
  17. package/dist/src/abstracts/BaseModalComponent.d.ts.map +1 -1
  18. package/dist/src/abstracts/BaseModalComponent.js +1 -1
  19. package/dist/src/abstracts/BaseModalComponent.js.map +1 -1
  20. package/dist/src/abstracts/GuildThreadOnlyChannel.d.ts +1 -2
  21. package/dist/src/abstracts/GuildThreadOnlyChannel.d.ts.map +1 -1
  22. package/dist/src/abstracts/GuildThreadOnlyChannel.js.map +1 -1
  23. package/dist/src/adapters/bun/index.d.ts +4 -3
  24. package/dist/src/adapters/bun/index.d.ts.map +1 -1
  25. package/dist/src/adapters/bun/index.js +2 -2
  26. package/dist/src/adapters/bun/index.js.map +1 -1
  27. package/dist/src/adapters/fetch/index.d.ts +4 -3
  28. package/dist/src/adapters/fetch/index.d.ts.map +1 -1
  29. package/dist/src/adapters/fetch/index.js +7 -2
  30. package/dist/src/adapters/fetch/index.js.map +1 -1
  31. package/dist/src/adapters/node/index.d.ts +4 -3
  32. package/dist/src/adapters/node/index.d.ts.map +1 -1
  33. package/dist/src/adapters/node/index.js +2 -2
  34. package/dist/src/adapters/node/index.js.map +1 -1
  35. package/dist/src/classes/ApplicationManager.d.ts +88 -0
  36. package/dist/src/classes/ApplicationManager.d.ts.map +1 -0
  37. package/dist/src/classes/ApplicationManager.js +179 -0
  38. package/dist/src/classes/ApplicationManager.js.map +1 -0
  39. package/dist/src/classes/Client.d.ts +14 -0
  40. package/dist/src/classes/Client.d.ts.map +1 -1
  41. package/dist/src/classes/Client.js +20 -4
  42. package/dist/src/classes/Client.js.map +1 -1
  43. package/dist/src/classes/CommandWithSubcommandGroups.d.ts.map +1 -1
  44. package/dist/src/classes/CommandWithSubcommandGroups.js +4 -8
  45. package/dist/src/classes/CommandWithSubcommandGroups.js.map +1 -1
  46. package/dist/src/classes/CommandWithSubcommands.d.ts.map +1 -1
  47. package/dist/src/classes/CommandWithSubcommands.js +2 -4
  48. package/dist/src/classes/CommandWithSubcommands.js.map +1 -1
  49. package/dist/src/classes/Listener.d.ts +13 -0
  50. package/dist/src/classes/Listener.d.ts.map +1 -1
  51. package/dist/src/classes/Listener.js +27 -6
  52. package/dist/src/classes/Listener.js.map +1 -1
  53. package/dist/src/classes/Modal.d.ts +2 -1
  54. package/dist/src/classes/Modal.d.ts.map +1 -1
  55. package/dist/src/classes/Modal.js.map +1 -1
  56. package/dist/src/classes/RequestClient.d.ts.map +1 -1
  57. package/dist/src/classes/RequestClient.js +5 -3
  58. package/dist/src/classes/RequestClient.js.map +1 -1
  59. package/dist/src/classes/components/Button.d.ts.map +1 -1
  60. package/dist/src/classes/components/Button.js.map +1 -1
  61. package/dist/src/classes/components/FileUpload.d.ts +22 -0
  62. package/dist/src/classes/components/FileUpload.d.ts.map +1 -0
  63. package/dist/src/classes/components/FileUpload.js +36 -0
  64. package/dist/src/classes/components/FileUpload.js.map +1 -0
  65. package/dist/src/classes/components/Label.d.ts +4 -4
  66. package/dist/src/classes/components/Label.d.ts.map +1 -1
  67. package/dist/src/classes/components/Label.js +7 -3
  68. package/dist/src/classes/components/Label.js.map +1 -1
  69. package/dist/src/classes/components/ModalChannelSelectMenu.d.ts +62 -0
  70. package/dist/src/classes/components/ModalChannelSelectMenu.d.ts.map +1 -0
  71. package/dist/src/classes/components/ModalChannelSelectMenu.js +73 -0
  72. package/dist/src/classes/components/ModalChannelSelectMenu.js.map +1 -0
  73. package/dist/src/classes/components/ModalMentionableSelectMenu.d.ts +58 -0
  74. package/dist/src/classes/components/ModalMentionableSelectMenu.d.ts.map +1 -0
  75. package/dist/src/classes/components/ModalMentionableSelectMenu.js +68 -0
  76. package/dist/src/classes/components/ModalMentionableSelectMenu.js.map +1 -0
  77. package/dist/src/classes/components/ModalRoleSelectMenu.d.ts +58 -0
  78. package/dist/src/classes/components/ModalRoleSelectMenu.d.ts.map +1 -0
  79. package/dist/src/classes/components/ModalRoleSelectMenu.js +68 -0
  80. package/dist/src/classes/components/ModalRoleSelectMenu.js.map +1 -0
  81. package/dist/src/classes/components/ModalStringSelectMenu.d.ts +56 -8
  82. package/dist/src/classes/components/ModalStringSelectMenu.d.ts.map +1 -1
  83. package/dist/src/classes/components/ModalStringSelectMenu.js +59 -10
  84. package/dist/src/classes/components/ModalStringSelectMenu.js.map +1 -1
  85. package/dist/src/classes/components/ModalUserSelectMenu.d.ts +58 -0
  86. package/dist/src/classes/components/ModalUserSelectMenu.d.ts.map +1 -0
  87. package/dist/src/classes/components/ModalUserSelectMenu.js +68 -0
  88. package/dist/src/classes/components/ModalUserSelectMenu.js.map +1 -0
  89. package/dist/src/classes/components/TextInput.d.ts +0 -1
  90. package/dist/src/classes/components/TextInput.d.ts.map +1 -1
  91. package/dist/src/classes/components/TextInput.js +0 -1
  92. package/dist/src/classes/components/TextInput.js.map +1 -1
  93. package/dist/src/errors/DiscordError.d.ts.map +1 -1
  94. package/dist/src/errors/DiscordError.js.map +1 -1
  95. package/dist/src/index.d.ts +7 -0
  96. package/dist/src/index.d.ts.map +1 -1
  97. package/dist/src/index.js +6 -0
  98. package/dist/src/index.js.map +1 -1
  99. package/dist/src/internals/CommandInteraction.d.ts.map +1 -1
  100. package/dist/src/internals/CommandInteraction.js +2 -1
  101. package/dist/src/internals/CommandInteraction.js.map +1 -1
  102. package/dist/src/internals/ComponentHandler.d.ts.map +1 -1
  103. package/dist/src/internals/ComponentHandler.js +7 -3
  104. package/dist/src/internals/ComponentHandler.js.map +1 -1
  105. package/dist/src/internals/EmojiHandler.d.ts +19 -0
  106. package/dist/src/internals/EmojiHandler.d.ts.map +1 -0
  107. package/dist/src/internals/EmojiHandler.js +35 -0
  108. package/dist/src/internals/EmojiHandler.js.map +1 -0
  109. package/dist/src/internals/EventHandler.d.ts +2 -2
  110. package/dist/src/internals/EventHandler.d.ts.map +1 -1
  111. package/dist/src/internals/EventHandler.js +3 -1
  112. package/dist/src/internals/EventHandler.js.map +1 -1
  113. package/dist/src/internals/FieldsHandler.d.ts +49 -16
  114. package/dist/src/internals/FieldsHandler.d.ts.map +1 -1
  115. package/dist/src/internals/FieldsHandler.js +110 -26
  116. package/dist/src/internals/FieldsHandler.js.map +1 -1
  117. package/dist/src/internals/ModalHandler.d.ts.map +1 -1
  118. package/dist/src/internals/ModalHandler.js +7 -1
  119. package/dist/src/internals/ModalHandler.js.map +1 -1
  120. package/dist/src/internals/OptionsHandler.d.ts +20 -12
  121. package/dist/src/internals/OptionsHandler.d.ts.map +1 -1
  122. package/dist/src/internals/OptionsHandler.js +48 -15
  123. package/dist/src/internals/OptionsHandler.js.map +1 -1
  124. package/dist/src/plugins/client-manager/ClientManager.d.ts +151 -0
  125. package/dist/src/plugins/client-manager/ClientManager.d.ts.map +1 -0
  126. package/dist/src/plugins/client-manager/ClientManager.js +246 -0
  127. package/dist/src/plugins/client-manager/ClientManager.js.map +1 -0
  128. package/dist/src/plugins/client-manager/index.d.ts +2 -0
  129. package/dist/src/plugins/client-manager/index.d.ts.map +1 -0
  130. package/dist/src/plugins/client-manager/index.js +2 -0
  131. package/dist/src/plugins/client-manager/index.js.map +1 -0
  132. package/dist/src/plugins/command-data/CommandDataPlugin.d.ts.map +1 -1
  133. package/dist/src/plugins/command-data/CommandDataPlugin.js +3 -6
  134. package/dist/src/plugins/command-data/CommandDataPlugin.js.map +1 -1
  135. package/dist/src/plugins/gateway/BabyCache.d.ts +7 -0
  136. package/dist/src/plugins/gateway/BabyCache.d.ts.map +1 -0
  137. package/dist/src/plugins/gateway/BabyCache.js +6 -0
  138. package/dist/src/plugins/gateway/BabyCache.js.map +1 -0
  139. package/dist/src/plugins/gateway/GatewayPlugin.d.ts +4 -2
  140. package/dist/src/plugins/gateway/GatewayPlugin.d.ts.map +1 -1
  141. package/dist/src/plugins/gateway/GatewayPlugin.js +68 -22
  142. package/dist/src/plugins/gateway/GatewayPlugin.js.map +1 -1
  143. package/dist/src/plugins/gateway/InteractionEventListener.d.ts +8 -0
  144. package/dist/src/plugins/gateway/InteractionEventListener.d.ts.map +1 -0
  145. package/dist/src/plugins/gateway/InteractionEventListener.js +9 -0
  146. package/dist/src/plugins/gateway/InteractionEventListener.js.map +1 -0
  147. package/dist/src/plugins/gateway/index.d.ts +1 -0
  148. package/dist/src/plugins/gateway/index.d.ts.map +1 -1
  149. package/dist/src/plugins/gateway/index.js +1 -0
  150. package/dist/src/plugins/gateway/index.js.map +1 -1
  151. package/dist/src/plugins/gateway/types.d.ts +5 -0
  152. package/dist/src/plugins/gateway/types.d.ts.map +1 -1
  153. package/dist/src/plugins/gateway/types.js.map +1 -1
  154. package/dist/src/plugins/gateway-forwarder/GatewayForwarderPlugin.d.ts +5 -1
  155. package/dist/src/plugins/gateway-forwarder/GatewayForwarderPlugin.d.ts.map +1 -1
  156. package/dist/src/plugins/gateway-forwarder/GatewayForwarderPlugin.js +7 -5
  157. package/dist/src/plugins/gateway-forwarder/GatewayForwarderPlugin.js.map +1 -1
  158. package/dist/src/plugins/gateway-forwarder/ShardedGatewayForwarderPlugin.d.ts +0 -1
  159. package/dist/src/plugins/gateway-forwarder/ShardedGatewayForwarderPlugin.d.ts.map +1 -1
  160. package/dist/src/plugins/gateway-forwarder/ShardedGatewayForwarderPlugin.js +0 -4
  161. package/dist/src/plugins/gateway-forwarder/ShardedGatewayForwarderPlugin.js.map +1 -1
  162. package/dist/src/plugins/gateway-forwarder/index.d.ts +1 -1
  163. package/dist/src/plugins/gateway-forwarder/index.d.ts.map +1 -1
  164. package/dist/src/plugins/gateway-forwarder/index.js +1 -1
  165. package/dist/src/plugins/gateway-forwarder/index.js.map +1 -1
  166. package/dist/src/plugins/multi-app/ApplicationManager.d.ts +120 -0
  167. package/dist/src/plugins/multi-app/ApplicationManager.d.ts.map +1 -0
  168. package/dist/src/plugins/multi-app/ApplicationManager.js +207 -0
  169. package/dist/src/plugins/multi-app/ApplicationManager.js.map +1 -0
  170. package/dist/src/plugins/multi-app/index.d.ts +2 -0
  171. package/dist/src/plugins/multi-app/index.d.ts.map +1 -0
  172. package/dist/src/plugins/multi-app/index.js +2 -0
  173. package/dist/src/plugins/multi-app/index.js.map +1 -0
  174. package/dist/src/plugins/paginator/GoToPageModal.d.ts +1 -1
  175. package/dist/src/plugins/paginator/GoToPageModal.d.ts.map +1 -1
  176. package/dist/src/plugins/paginator/GoToPageModal.js +2 -2
  177. package/dist/src/plugins/paginator/GoToPageModal.js.map +1 -1
  178. package/dist/src/plugins/paginator/Paginator.d.ts.map +1 -1
  179. package/dist/src/plugins/paginator/Paginator.js +1 -1
  180. package/dist/src/plugins/paginator/Paginator.js.map +1 -1
  181. package/dist/src/plugins/paginator/index.d.ts +2 -0
  182. package/dist/src/plugins/paginator/index.d.ts.map +1 -1
  183. package/dist/src/plugins/paginator/index.js +2 -0
  184. package/dist/src/plugins/paginator/index.js.map +1 -1
  185. package/dist/src/plugins/sharding/index.d.ts +1 -1
  186. package/dist/src/plugins/sharding/index.js +1 -1
  187. package/dist/src/structures/DmChannel.d.ts.map +1 -1
  188. package/dist/src/structures/DmChannel.js.map +1 -1
  189. package/dist/src/structures/Emoji.d.ts +75 -0
  190. package/dist/src/structures/Emoji.d.ts.map +1 -0
  191. package/dist/src/structures/Emoji.js +156 -0
  192. package/dist/src/structures/Emoji.js.map +1 -0
  193. package/dist/src/structures/GroupDmChannel.d.ts +8 -1
  194. package/dist/src/structures/GroupDmChannel.d.ts.map +1 -1
  195. package/dist/src/structures/GroupDmChannel.js +13 -4
  196. package/dist/src/structures/GroupDmChannel.js.map +1 -1
  197. package/dist/src/structures/Guild.d.ts +83 -6
  198. package/dist/src/structures/Guild.d.ts.map +1 -1
  199. package/dist/src/structures/Guild.js +177 -22
  200. package/dist/src/structures/Guild.js.map +1 -1
  201. package/dist/src/structures/GuildMember.d.ts +23 -1
  202. package/dist/src/structures/GuildMember.d.ts.map +1 -1
  203. package/dist/src/structures/GuildMember.js +38 -9
  204. package/dist/src/structures/GuildMember.js.map +1 -1
  205. package/dist/src/structures/GuildScheduledEvent.d.ts +121 -0
  206. package/dist/src/structures/GuildScheduledEvent.d.ts.map +1 -0
  207. package/dist/src/structures/GuildScheduledEvent.js +228 -0
  208. package/dist/src/structures/GuildScheduledEvent.js.map +1 -0
  209. package/dist/src/structures/GuildThreadChannel.d.ts +1 -1
  210. package/dist/src/structures/GuildThreadChannel.d.ts.map +1 -1
  211. package/dist/src/structures/Role.d.ts +33 -12
  212. package/dist/src/structures/Role.d.ts.map +1 -1
  213. package/dist/src/structures/Role.js +58 -24
  214. package/dist/src/structures/Role.js.map +1 -1
  215. package/dist/src/structures/ThreadMember.d.ts.map +1 -1
  216. package/dist/src/structures/ThreadMember.js +0 -1
  217. package/dist/src/structures/ThreadMember.js.map +1 -1
  218. package/dist/src/structures/User.d.ts +16 -4
  219. package/dist/src/structures/User.d.ts.map +1 -1
  220. package/dist/src/structures/User.js +25 -9
  221. package/dist/src/structures/User.js.map +1 -1
  222. package/dist/src/structures/Webhook.d.ts +40 -19
  223. package/dist/src/structures/Webhook.d.ts.map +1 -1
  224. package/dist/src/structures/Webhook.js +70 -30
  225. package/dist/src/structures/Webhook.js.map +1 -1
  226. package/dist/src/types/index.d.ts +5 -1
  227. package/dist/src/types/index.d.ts.map +1 -1
  228. package/dist/src/types/index.js.map +1 -1
  229. package/dist/src/types/listeners.d.ts +12 -7
  230. package/dist/src/types/listeners.d.ts.map +1 -1
  231. package/dist/src/types/listeners.js +3 -1
  232. package/dist/src/types/listeners.js.map +1 -1
  233. package/dist/src/utils/cdn.d.ts +31 -0
  234. package/dist/src/utils/cdn.d.ts.map +1 -0
  235. package/dist/src/utils/cdn.js +18 -0
  236. package/dist/src/utils/cdn.js.map +1 -0
  237. package/dist/src/utils/index.d.ts +1 -0
  238. package/dist/src/utils/index.d.ts.map +1 -1
  239. package/dist/src/utils/index.js +1 -0
  240. package/dist/src/utils/index.js.map +1 -1
  241. package/dist/src/utils/payload.d.ts.map +1 -1
  242. package/dist/src/utils/payload.js +20 -5
  243. package/dist/src/utils/payload.js.map +1 -1
  244. package/dist/tsconfig.tsbuildinfo +1 -1
  245. package/package.json +3 -3
@@ -0,0 +1,246 @@
1
+ import { Routes } from "discord-api-types/v10";
2
+ import { Client } from "../../classes/Client.js";
3
+ /**
4
+ * Manages multiple Discord applications, routing requests to the appropriate client
5
+ * based on the client ID in the URL path (/:clientId/*)
6
+ *
7
+ * To use with a database, extend this class and override:
8
+ * - getClient(clientId) - Return the client for a specific ID (or create it)
9
+ * - getAllClients() - Return all available clients
10
+ * - getClientIds() - Return all available client IDs
11
+ *
12
+ * Then call setupClient(credentials) to create clients on-demand.
13
+ */
14
+ export class ClientManager {
15
+ /**
16
+ * The routes that the application manager will handle
17
+ */
18
+ routes = [];
19
+ /**
20
+ * The shared deploy secret used for all applications
21
+ */
22
+ deploySecret;
23
+ /**
24
+ * The base URL of the applications to mount the proxy at
25
+ */
26
+ baseUrl;
27
+ /**
28
+ * Shared options that apply to all applications
29
+ * Protected to allow subclasses to use it when creating clients
30
+ */
31
+ sharedOptions;
32
+ clients = new Map();
33
+ staticApplications;
34
+ initialHandlers;
35
+ initialPlugins;
36
+ /**
37
+ * Creates a new ClientManager
38
+ * @param options Configuration options including shared settings and per-app credentials
39
+ */
40
+ constructor(options, handlers, plugins) {
41
+ this.sharedOptions = options.sharedOptions;
42
+ this.deploySecret = options.deploySecret;
43
+ this.baseUrl = options.baseUrl;
44
+ this.staticApplications = options.applications ?? [];
45
+ this.initialHandlers = handlers;
46
+ this.initialPlugins = plugins;
47
+ this.setupRoutes();
48
+ this.getApplications().then(async (applications) => {
49
+ applications.map(async (application) => {
50
+ this.setupClient({
51
+ clientId: application.clientId,
52
+ publicKey: application.publicKey,
53
+ token: application.token
54
+ }, options.initialSetupOptions);
55
+ });
56
+ });
57
+ }
58
+ /**
59
+ * Setup a client from credentials.
60
+ *
61
+ * @param credentials The application credentials
62
+ * @param options The setup options for the client
63
+ * @returns A configured Client instance
64
+ */
65
+ async setupClient(credentials, options = {
66
+ recreate: false,
67
+ setInteractionsUrlOnDevPortal: false,
68
+ setEventsUrlOnDevPortal: false
69
+ }) {
70
+ const existing = this.getClient(credentials.clientId);
71
+ if (existing && !options.recreate) {
72
+ throw new Error(`Client ${credentials.clientId} already exists. If you want to recreate it, pass true to the recreate parameter.`);
73
+ }
74
+ if (existing && options.recreate) {
75
+ this.clients.delete(credentials.clientId);
76
+ }
77
+ if (!this.isValidClientId(credentials.clientId)) {
78
+ throw new Error(`Invalid client ID: ${credentials.clientId}. Client ID must be a valid Discord snowflake (17-19 digits).`);
79
+ }
80
+ const clientOptions = {
81
+ ...this.sharedOptions,
82
+ baseUrl: `${this.baseUrl}/${credentials.clientId}`,
83
+ deploySecret: this.deploySecret,
84
+ clientId: credentials.clientId,
85
+ publicKey: credentials.publicKey,
86
+ token: credentials.token
87
+ };
88
+ const client = new Client(clientOptions, this.initialHandlers, this.initialPlugins);
89
+ this.clients.set(credentials.clientId, client);
90
+ if (options.setInteractionsUrlOnDevPortal ||
91
+ options.setEventsUrlOnDevPortal) {
92
+ await client.rest.patch(Routes.currentApplication(), {
93
+ body: {
94
+ interactions_endpoint_url: options.setInteractionsUrlOnDevPortal
95
+ ? `${this.baseUrl}/${credentials.clientId}/interactions`
96
+ : undefined,
97
+ event_webhooks_url: options.setEventsUrlOnDevPortal
98
+ ? `${this.baseUrl}/${credentials.clientId}/events`
99
+ : undefined
100
+ }
101
+ });
102
+ }
103
+ return client;
104
+ }
105
+ /**
106
+ * Set up the routing for the application manager
107
+ */
108
+ setupRoutes() {
109
+ this.routes.push({
110
+ method: "GET",
111
+ path: "/deploy",
112
+ handler: this.handleGlobalDeploy.bind(this),
113
+ protected: true,
114
+ disabled: !this.deploySecret
115
+ });
116
+ this.routes.push({
117
+ method: "POST",
118
+ path: "/:clientId/*",
119
+ handler: this.handleProxyRequest.bind(this)
120
+ });
121
+ this.routes.push({
122
+ method: "GET",
123
+ path: "/:clientId/*",
124
+ handler: this.handleProxyRequest.bind(this)
125
+ });
126
+ }
127
+ /**
128
+ * Deploy all applications
129
+ */
130
+ async handleGlobalDeploy(req) {
131
+ if (this.deploySecret) {
132
+ const url = new URL(req.url);
133
+ const secret = url.searchParams.get("secret");
134
+ if (secret !== this.deploySecret) {
135
+ return new Response("Unauthorized", { status: 401 });
136
+ }
137
+ }
138
+ const results = [];
139
+ const clientIds = this.getClientIds();
140
+ for (const clientId of clientIds) {
141
+ const client = this.getClient(clientId);
142
+ if (!client)
143
+ continue;
144
+ try {
145
+ await client.handleDeployRequest();
146
+ results.push({ clientId, status: "success" });
147
+ }
148
+ catch (error) {
149
+ results.push({
150
+ clientId,
151
+ status: `error: ${error instanceof Error ? error.message : String(error)}`
152
+ });
153
+ }
154
+ }
155
+ return Response.json(results, { status: 200 });
156
+ }
157
+ /**
158
+ * Handle a request and route it to the appropriate client
159
+ * @param req The incoming request
160
+ * @param ctx Optional context (for Cloudflare Workers, etc.)
161
+ */
162
+ async handleRequest(req, ctx) {
163
+ const url = new URL(req.url);
164
+ const baseUrl = new URL(this.baseUrl);
165
+ const basePathname = baseUrl.pathname.replace(/\/$/, "");
166
+ const reqPathname = url.pathname.replace(/\/$/, "");
167
+ if (!reqPathname.startsWith(basePathname)) {
168
+ return new Response("Not Found: Invalid base URL", { status: 404 });
169
+ }
170
+ const truePathname = reqPathname.slice(basePathname.length);
171
+ if (truePathname === "/deploy" && req.method === "GET") {
172
+ return this.handleGlobalDeploy(req);
173
+ }
174
+ const pathParts = truePathname.split("/").filter(Boolean);
175
+ if (pathParts.length < 2) {
176
+ return new Response("Bad Request: Invalid path format", { status: 400 });
177
+ }
178
+ const clientId = pathParts[0];
179
+ if (!clientId) {
180
+ return new Response("Bad Request: Missing client ID", { status: 400 });
181
+ }
182
+ const client = this.getClient(clientId);
183
+ if (!client) {
184
+ return new Response(`Not Found: No application with client ID ${clientId}`, {
185
+ status: 404
186
+ });
187
+ }
188
+ const remainingPath = `/${pathParts.slice(1).join("/")}`;
189
+ const route = client.routes.find((r) => r.path === remainingPath && r.method === req.method && !r.disabled);
190
+ if (!route) {
191
+ return new Response(`Not Found: No route ${req.method} ${remainingPath}`, {
192
+ status: 404
193
+ });
194
+ }
195
+ if (route.protected) {
196
+ const secret = url.searchParams.get("secret");
197
+ if (secret !== client.options.deploySecret) {
198
+ return new Response("Unauthorized", { status: 401 });
199
+ }
200
+ }
201
+ return route.handler(req, ctx);
202
+ }
203
+ async handleProxyRequest(req, ctx) {
204
+ return this.handleRequest(req, ctx);
205
+ }
206
+ /**
207
+ * Get a client by its client ID
208
+ * @param clientId The client ID to look up
209
+ */
210
+ getClient(clientId) {
211
+ return this.clients.get(clientId);
212
+ }
213
+ /**
214
+ * Get all clients that the manager is managing
215
+ */
216
+ getClients() {
217
+ return Array.from(this.clients.values());
218
+ }
219
+ /**
220
+ * Get all client IDs that the manager is managing
221
+ */
222
+ getClientIds() {
223
+ return Array.from(this.clients.keys());
224
+ }
225
+ /**
226
+ * Get all applications
227
+ * You can override this in an extended class to return dynamic applications
228
+ */
229
+ async getApplications() {
230
+ return this.staticApplications;
231
+ }
232
+ /**
233
+ * Get an application by its client ID
234
+ * You can override this in an extended class to return dynamic applications
235
+ */
236
+ async getApplication(clientId) {
237
+ return this.staticApplications.find((app) => app.clientId === clientId);
238
+ }
239
+ /**
240
+ * Validate if a string is a valid Discord snowflake
241
+ */
242
+ isValidClientId(id) {
243
+ return /^\d{17,19}$/.test(id);
244
+ }
245
+ }
246
+ //# sourceMappingURL=ClientManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ClientManager.js","sourceRoot":"","sources":["../../../../src/plugins/client-manager/ClientManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAE9C,OAAO,EAAE,MAAM,EAAsB,MAAM,yBAAyB,CAAA;AAmEpE;;;;;;;;;;GAUG;AACH,MAAM,OAAO,aAAa;IACzB;;OAEG;IACH,MAAM,GAAY,EAAE,CAAA;IAEpB;;OAEG;IACO,YAAY,CAAS;IAE/B;;OAEG;IACO,OAAO,CAAQ;IAEzB;;;OAGG;IACO,aAAa,CAGtB;IAES,OAAO,GAAwB,IAAI,GAAG,EAAE,CAAA;IACxC,kBAAkB,CAA0B;IAC5C,eAAe,CAAyC;IACxD,cAAc,CAAyC;IAEjE;;;OAGG;IACH,YACC,OAA6B,EAC7B,QAAiD,EACjD,OAAgD;QAEhD,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAA;QAC1C,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAA;QACxC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAA;QAC9B,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAC,YAAY,IAAI,EAAE,CAAA;QACpD,IAAI,CAAC,eAAe,GAAG,QAAQ,CAAA;QAC/B,IAAI,CAAC,cAAc,GAAG,OAAO,CAAA;QAE7B,IAAI,CAAC,WAAW,EAAE,CAAA;QAElB,IAAI,CAAC,eAAe,EAAE,CAAC,I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CACjC,GAAY,EACZ,GAAa;QAEb,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;IACpC,CAAC;IAED;;;OAGG;IACH,SAAS,CAAC,QAAgB;QACzB,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;IAClC,CAAC;IAED;;OAEG;IACH,UAAU;QACT,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;IACzC,CAAC;IAED;;OAEG;IACH,YAAY;QACX,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAA;IACvC,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,eAAe;QACpB,OAAO,IAAI,CAAC,kBAAkB,CAAA;IAC/B,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,cAAc,CACnB,QAAgB;QAEhB,OAAO,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAA;IACxE,CAAC;IAED;;OAEG;IACO,eAAe,CAAC,EAAU;QACnC,OAAO,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAC9B,CAAC;CACD"}
@@ -0,0 +1,2 @@
1
+ export * from "./ClientManager.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/client-manager/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from "./ClientManager.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/plugins/client-manager/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"CommandDataPlugin.d.ts","sourceRoot":"","sources":["../../../../src/plugins/command-data/CommandDataPlugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAClD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAErD;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,MAAM;IAC5C,QAAQ,CAAC,EAAE,kBAAiB;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAA;IAER,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAIpC,cAAc,CAAC,MAAM,EAAE,MAAM;IAepC,OAAO,CAAC,kBAAkB,CAAuC;IACpD,4BAA4B;IAe5B,wBAAwB;CAQrC"}
1
+ {"version":3,"file":"CommandDataPlugin.d.ts","sourceRoot":"","sources":["../../../../src/plugins/command-data/CommandDataPlugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAClD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAErD;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,MAAM;IAC5C,QAAQ,CAAC,EAAE,kBAAiB;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAA;IAER,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAIpC,cAAc,CAAC,MAAM,EAAE,MAAM;IAepC,OAAO,CAAC,kBAAkB,CAAuC;IACpD,4BAA4B;IAW5B,wBAAwB;CAQrC"}
@@ -26,13 +26,10 @@ export class CommandDataPlugin extends Plugin {
26
26
  if (!this.client)
27
27
  return new Response("Client not registered", { status: 500 });
28
28
  if (this.discordCommandData)
29
- return new Response(JSON.stringify(this.discordCommandData), {
30
- status: 200,
31
- headers: { "Content-Type": "application/json" }
32
- });
29
+ return Response.json(this.discordCommandData);
33
30
  const commands = (await this.client.rest.get(Routes.applicationCommands(this.client.options.clientId)));
34
31
  this.discordCommandData = commands;
35
- return new Response(JSON.stringify(commands), { status: 200 });
32
+ return Response.json(commands);
36
33
  }
37
34
  async handleCommandDataRequest() {
38
35
  if (!this.client)
@@ -40,7 +37,7 @@ export class CommandDataPlugin extends Plugin {
40
37
  const commands = this.client?.commands
41
38
  .filter((c) => c.name !== "*")
42
39
  .map((c) => c.serialize());
43
- return new Response(JSON.stringify(commands), { status: 200 });
40
+ return Response.json(commands);
44
41
  }
45
42
  }
46
43
  //# sourceMappingURL=CommandDataPlugin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CommandDataPlugin.js","sourceRoot":"","sources":["../../../../src/plugins/command-data/CommandDataPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAC1E,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAGlD;;;GAGG;AACH,MAAM,OAAO,iBAAkB,SAAQ,MAAM;IACnC,EAAE,GAAG,cAAc,CAAA;IAC5B,MAAM,CAAS;IAER,cAAc,CAAC,MAAc;QACnC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACrB,CAAC;IAEM,cAAc,CAAC,MAAc;QACnC,MAAM,CAAC,MAAM,CAAC,IAAI,CACjB;YACC,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,WAAW;YACjB,OAAO,EAAE,IAAI,CAAC,wBAAwB,CAAC,IAAI,CAAC,IAAI,CAAC;SACjD,EACD;YACC,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,gBAAgB;YACtB,OAAO,EAAE,IAAI,CAAC,4BAA4B,CAAC,IAAI,CAAC,IAAI,CAAC;SACrD,CACD,CAAA;IACF,CAAC;IAEO,kBAAkB,GAAmC,IAAI,CAAA;IAC1D,KAAK,CAAC,4BAA4B;QACxC,IAAI,CAAC,IAAI,CAAC,MAAM;YACf,OAAO,IAAI,QAAQ,CAAC,uBAAuB,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAA;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,IAAI,QAAQ,CAAC,uBAAuB,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAA;QAC9D,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,EAAE,QAAQ;aACpC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC;aAC7B,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAA;QAC3B,OAAO,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IAC/B,CAAC;CACD"}
@@ -0,0 +1,7 @@
1
+ export declare class BabyCache {
2
+ guildCache: Map<string, {
3
+ available: boolean;
4
+ lastEvent: number;
5
+ }>;
6
+ }
7
+ //# sourceMappingURL=BabyCache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BabyCache.d.ts","sourceRoot":"","sources":["../../../../src/plugins/gateway/BabyCache.ts"],"names":[],"mappings":"AAGA,qBAAa,SAAS;IACrB,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE;QAAE,SAAS,EAAE,OAAO,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC,CAAY;CAC9E"}
@@ -0,0 +1,6 @@
1
+ // I called this the BabyCache because eventually, one way, carbon will have a more
2
+ // proper caching setup. For now, this is the toddler of that cache.
3
+ export class BabyCache {
4
+ guildCache = new Map();
5
+ }
6
+ //# sourceMappingURL=BabyCache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BabyCache.js","sourceRoot":"","sources":["../../../../src/plugins/gateway/BabyCache.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,oEAAoE;AAEpE,MAAM,OAAO,SAAS;IACrB,UAAU,GAA2D,IAAI,GAAG,EAAE,CAAA;CAC9E"}
@@ -2,13 +2,14 @@ import { EventEmitter } from "node:events";
2
2
  import WebSocket from "ws";
3
3
  import { Plugin } from "../../abstracts/Plugin.js";
4
4
  import type { Client } from "../../classes/Client.js";
5
+ import { BabyCache } from "./BabyCache.js";
5
6
  import { type APIGatewayBotInfo, type GatewayPayload, type GatewayPluginOptions, type GatewayState, type RequestGuildMembersData, type UpdatePresenceData, type UpdateVoiceStateData } from "./types.js";
6
7
  import { ConnectionMonitor } from "./utils/monitor.js";
7
8
  import { GatewayRateLimit } from "./utils/rateLimit.js";
8
9
  export declare class GatewayPlugin extends Plugin {
9
10
  readonly id = "gateway";
10
11
  protected client?: Client;
11
- protected config: GatewayPluginOptions;
12
+ readonly options: GatewayPluginOptions;
12
13
  protected state: GatewayState;
13
14
  protected ws: WebSocket | null;
14
15
  protected monitor: ConnectionMonitor;
@@ -23,6 +24,7 @@ export declare class GatewayPlugin extends Plugin {
23
24
  protected gatewayInfo?: APIGatewayBotInfo;
24
25
  isConnected: boolean;
25
26
  protected pings: number[];
27
+ protected babyCache: BabyCache;
26
28
  constructor(options: GatewayPluginOptions, gatewayInfo?: APIGatewayBotInfo);
27
29
  get ping(): number | null;
28
30
  registerClient(client: Client): Promise<void>;
@@ -66,7 +68,7 @@ export declare class GatewayPlugin extends Plugin {
66
68
  currentEventCount: number;
67
69
  };
68
70
  /**
69
- * Get information about configured intents
71
+ * Get information about optionsured intents
70
72
  */
71
73
  getIntentsInfo(): {
72
74
  intents: number;
@@ -1 +1 @@
1
- {"version":3,"file":"GatewayPlugin.d.ts","sourceRoot":"","sources":["../../../../src/plugins/gateway/GatewayPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1C,OAAO,SAAS,MAAM,IAAI,CAAA;AAC1B,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAClD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAErD,OAAO,EACN,KAAK,iBAAiB,EAItB,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,KAAK,YAAY,EAEjB,KAAK,uBAAuB,EAC5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CAAC,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS;IAOjD,SAAS,CAAC,cAAc,IAAI,IAAI;IAkMhC,SAAS,CAAC,yBAAyB,CAAC,OAAO,EAAE;QAC5C,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,kBAAkB,CAAC,EAAE,OAAO,CAAA;QAC5B,aAAa,CAAC,EAAE,OAAO,CAAA;KACvB,GAAG,IAAI;IAoER,SAAS,CAAC,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAIzC,SAAS,CAAC,sBAAsB,IAAI,IAAI;IAIxC,SAAS,CAAC,eAAe,IAAI,IAAI;IAIjC,SAAS,CAAC,SAAS,IAAI,OAAO;IAI9B,SAAS,CAAC,MAAM,IAAI,IAAI;IAWjB,IAAI,CAAC,OAAO,EAAE,cAAc,EAAE,aAAa,UAAQ,GAAG,IAAI;IA2BjE,SAAS,CAAC,QAAQ,IAAI,IAAI;IAe1B;;;OAGG;IACI,cAAc,CAAC,IAAI,EAAE,kBAAkB,GAAG,IAAI;IAQrD;;;OAGG;IACI,gBAAgB,CAAC,IAAI,EAAE,oBAAoB,GAAG,IAAI;IASzD;;;OAGG;IACI,mBAAmB,CAAC,IAAI,EAAE,uBAAuB,GAAG,IAAI;IAiC/D;;OAEG;IACI,kBAAkB;;;;;IAQzB;;OAEG;IACI,cAAc;;;;;;;;IAerB;;;OAGG;IACI,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;CAGzC"}
@@ -2,6 +2,8 @@ import { EventEmitter } from "node:events";
2
2
  import WebSocket from "ws";
3
3
  import { Plugin } from "../../abstracts/Plugin.js";
4
4
  import { ListenerEvent } from "../../types/index.js";
5
+ import { BabyCache } from "./BabyCache.js";
6
+ import { InteractionEventListener } from "./InteractionEventListener.js";
5
7
  import { GatewayCloseCodes, GatewayIntents, GatewayOpcodes } from "./types.js";
6
8
  import { startHeartbeat, stopHeartbeat } from "./utils/heartbeat.js";
7
9
  import { ConnectionMonitor } from "./utils/monitor.js";
@@ -10,7 +12,7 @@ import { GatewayRateLimit } from "./utils/rateLimit.js";
10
12
  export class GatewayPlugin extends Plugin {
11
13
  id = "gateway";
12
14
  client;
13
- config;
15
+ options;
14
16
  state;
15
17
  ws = null;
16
18
  monitor;
@@ -25,9 +27,10 @@ export class GatewayPlugin extends Plugin {
25
27
  gatewayInfo;
26
28
  isConnected = false;
27
29
  pings = [];
30
+ babyCache;
28
31
  constructor(options, gatewayInfo) {
29
32
  super();
30
- this.config = {
33
+ this.options = {
31
34
  reconnect: {
32
35
  maxAttempts: 5,
33
36
  baseDelay: 1000,
@@ -44,6 +47,7 @@ export class GatewayPlugin extends Plugin {
44
47
  this.rateLimit = new GatewayRateLimit();
45
48
  this.emitter = new EventEmitter();
46
49
  this.gatewayInfo = gatewayInfo;
50
+ this.babyCache = new BabyCache();
47
51
  this.monitor.on("metrics", (metrics) => this.emitter.emit("metrics", metrics));
48
52
  this.monitor.on("warning", (warning) => this.emitter.emit("warning", warning));
49
53
  }
@@ -68,9 +72,12 @@ export class GatewayPlugin extends Plugin {
68
72
  }
69
73
  }
70
74
  // Set shard information on the client
71
- if (this.config.shard) {
72
- client.shardId = this.config.shard[0];
73
- client.totalShards = this.config.shard[1];
75
+ if (this.options.shard) {
76
+ client.shardId = this.options.shard[0];
77
+ client.totalShards = this.options.shard[1];
78
+ }
79
+ if (this.options.autoInteractions) {
80
+ this.client?.listeners.push(new InteractionEventListener());
74
81
  }
75
82
  this.connect();
76
83
  }
@@ -79,7 +86,7 @@ export class GatewayPlugin extends Plugin {
79
86
  const url = resume && this.state.resumeGatewayUrl
80
87
  ? this.state.resumeGatewayUrl
81
88
  : (this.gatewayInfo?.url ??
82
- this.config.url ??
89
+ this.options.url ??
83
90
  "wss://gateway.discord.gg/?v=10&encoding=json");
84
91
  this.ws = this.createWebSocket(url);
85
92
  this.setupWebSocket();
@@ -159,7 +166,7 @@ export class GatewayPlugin extends Plugin {
159
166
  const t1 = payload1.t;
160
167
  try {
161
168
  if (!Object.values(ListenerEvent).includes(t1)) {
162
- throw new Error(`Unknown event type: ${t1}`);
169
+ break;
163
170
  }
164
171
  if (t1 === "READY") {
165
172
  const readyData = d;
@@ -167,8 +174,47 @@ export class GatewayPlugin extends Plugin {
167
174
  this.state.resumeGatewayUrl = readyData.resume_gateway_url;
168
175
  }
169
176
  if (t && this.client) {
170
- if (!this.config.eventFilter || this.config.eventFilter?.(t1)) {
171
- this.client.eventHandler.handleEvent(payload1.d, t1);
177
+ if (!this.options.eventFilter || this.options.eventFilter?.(t1)) {
178
+ if (t1 === "READY") {
179
+ const readyData = d;
180
+ readyData.guilds.forEach((guild) => {
181
+ this.babyCache.guildCache.set(guild.id, {
182
+ available: false,
183
+ lastEvent: Date.now()
184
+ });
185
+ });
186
+ }
187
+ if (t1 === "GUILD_CREATE") {
188
+ const guildCreateData = d;
189
+ const existingGuild = this.babyCache.guildCache.get(guildCreateData.id);
190
+ if (existingGuild && !existingGuild.available) {
191
+ this.babyCache.guildCache.set(guildCreateData.id, {
192
+ available: true,
193
+ lastEvent: Date.now()
194
+ });
195
+ this.client.eventHandler.handleEvent({
196
+ ...guildCreateData,
197
+ clientId: this.client.options.clientId
198
+ }, "GUILD_AVAILABLE");
199
+ break;
200
+ }
201
+ }
202
+ if (t1 === "GUILD_DELETE") {
203
+ const guildDeleteData = d;
204
+ const existingGuild = this.babyCache.guildCache.get(guildDeleteData.id);
205
+ if (existingGuild?.available && guildDeleteData.unavailable) {
206
+ this.babyCache.guildCache.set(guildDeleteData.id, {
207
+ available: false,
208
+ lastEvent: Date.now()
209
+ });
210
+ this.client.eventHandler.handleEvent({
211
+ ...guildDeleteData,
212
+ clientId: this.client.options.clientId
213
+ }, "GUILD_UNAVAILABLE");
214
+ break;
215
+ }
216
+ }
217
+ this.client.eventHandler.handleEvent({ ...payload1.d, clientId: this.client.options.clientId }, t1);
172
218
  }
173
219
  }
174
220
  }
@@ -220,7 +266,7 @@ export class GatewayPlugin extends Plugin {
220
266
  });
221
267
  }
222
268
  handleReconnectionAttempt(options) {
223
- const { maxAttempts = 5, baseDelay = 1000, maxDelay = 30000 } = this.config.reconnect ?? {};
269
+ const { maxAttempts = 5, baseDelay = 1000, maxDelay = 30000 } = this.options.reconnect ?? {};
224
270
  this.disconnect();
225
271
  if (this.reconnectAttempts >= maxAttempts) {
226
272
  this.emitter.emit("error", new Error(`Max reconnect attempts (${maxAttempts}) reached${options.code ? ` after code ${options.code}` : ""}`));
@@ -306,13 +352,13 @@ export class GatewayPlugin extends Plugin {
306
352
  return;
307
353
  const payload = createIdentifyPayload({
308
354
  token: this.client.options.token,
309
- intents: this.config.intents,
355
+ intents: this.options.intents,
310
356
  properties: {
311
357
  os: process.platform,
312
358
  browser: "@buape/carbon - https://carbon.buape.com",
313
359
  device: "@buape/carbon - https://carbon.buape.com"
314
360
  },
315
- ...(this.config.shard ? { shard: this.config.shard } : {})
361
+ ...(this.options.shard ? { shard: this.options.shard } : {})
316
362
  });
317
363
  this.send(payload, true);
318
364
  }
@@ -346,12 +392,12 @@ export class GatewayPlugin extends Plugin {
346
392
  if (!this.isConnected) {
347
393
  throw new Error("Gateway is not connected");
348
394
  }
349
- const hasGuildMembersIntent = (this.config.intents & GatewayIntents.GuildMembers) !== 0;
395
+ const hasGuildMembersIntent = (this.options.intents & GatewayIntents.GuildMembers) !== 0;
350
396
  if (!hasGuildMembersIntent) {
351
397
  throw new Error("GUILD_MEMBERS intent is required for requestGuildMembers operation");
352
398
  }
353
399
  if (data.presences) {
354
- const hasPresencesIntent = (this.config.intents & GatewayIntents.GuildPresences) !== 0;
400
+ const hasPresencesIntent = (this.options.intents & GatewayIntents.GuildPresences) !== 0;
355
401
  if (!hasPresencesIntent) {
356
402
  throw new Error("GUILD_PRESENCES intent is required when requesting presences");
357
403
  }
@@ -373,16 +419,16 @@ export class GatewayPlugin extends Plugin {
373
419
  };
374
420
  }
375
421
  /**
376
- * Get information about configured intents
422
+ * Get information about optionsured intents
377
423
  */
378
424
  getIntentsInfo() {
379
425
  return {
380
- intents: this.config.intents,
381
- hasGuilds: (this.config.intents & GatewayIntents.Guilds) !== 0,
382
- hasGuildMembers: (this.config.intents & GatewayIntents.GuildMembers) !== 0,
383
- hasGuildPresences: (this.config.intents & GatewayIntents.GuildPresences) !== 0,
384
- hasGuildMessages: (this.config.intents & GatewayIntents.GuildMessages) !== 0,
385
- hasMessageContent: (this.config.intents & GatewayIntents.MessageContent) !== 0
426
+ intents: this.options.intents,
427
+ hasGuilds: (this.options.intents & GatewayIntents.Guilds) !== 0,
428
+ hasGuildMembers: (this.options.intents & GatewayIntents.GuildMembers) !== 0,
429
+ hasGuildPresences: (this.options.intents & GatewayIntents.GuildPresences) !== 0,
430
+ hasGuildMessages: (this.options.intents & GatewayIntents.GuildMessages) !== 0,
431
+ hasMessageContent: (this.options.intents & GatewayIntents.MessageContent) !== 0
386
432
  };
387
433
  }
388
434
  /**
@@ -390,7 +436,7 @@ export class GatewayPlugin extends Plugin {
390
436
  * @param intent The intent to check
391
437
  */
392
438
  hasIntent(intent) {
393
- return (this.config.intents & intent) !== 0;
439
+ return (this.options.intents & intent) !== 0;
394
440
  }
395
441
  }
396
442
  //# sourceMappingURL=GatewayPlugin.js.map