seyfert 0.1.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 (345) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +57 -0
  3. package/lib/api/CDN.d.ts +220 -0
  4. package/lib/api/CDN.js +236 -0
  5. package/lib/api/REST.d.ts +127 -0
  6. package/lib/api/REST.js +424 -0
  7. package/lib/api/Router.d.ts +17 -0
  8. package/lib/api/Router.js +63 -0
  9. package/lib/api/Routes/applications.d.ts +46 -0
  10. package/lib/api/Routes/applications.js +2 -0
  11. package/lib/api/Routes/cdn.d.ts +66 -0
  12. package/lib/api/Routes/cdn.js +2 -0
  13. package/lib/api/Routes/channels.d.ts +109 -0
  14. package/lib/api/Routes/channels.js +2 -0
  15. package/lib/api/Routes/gateway.d.ts +11 -0
  16. package/lib/api/Routes/gateway.js +2 -0
  17. package/lib/api/Routes/guilds.d.ts +171 -0
  18. package/lib/api/Routes/guilds.js +2 -0
  19. package/lib/api/Routes/index.d.ts +13 -0
  20. package/lib/api/Routes/index.js +17 -0
  21. package/lib/api/Routes/interactions.d.ts +14 -0
  22. package/lib/api/Routes/interactions.js +2 -0
  23. package/lib/api/Routes/invites.d.ts +9 -0
  24. package/lib/api/Routes/invites.js +2 -0
  25. package/lib/api/Routes/stage-instances.d.ts +13 -0
  26. package/lib/api/Routes/stage-instances.js +2 -0
  27. package/lib/api/Routes/stickers.d.ts +11 -0
  28. package/lib/api/Routes/stickers.js +2 -0
  29. package/lib/api/Routes/users.d.ts +35 -0
  30. package/lib/api/Routes/users.js +2 -0
  31. package/lib/api/Routes/voice.d.ts +10 -0
  32. package/lib/api/Routes/voice.js +2 -0
  33. package/lib/api/Routes/webhooks.d.ts +29 -0
  34. package/lib/api/Routes/webhooks.js +2 -0
  35. package/lib/api/errors/DiscordAPIError.d.ts +51 -0
  36. package/lib/api/errors/DiscordAPIError.js +81 -0
  37. package/lib/api/errors/HTTPError.d.ts +20 -0
  38. package/lib/api/errors/HTTPError.js +28 -0
  39. package/lib/api/errors/RateLimitError.d.ts +19 -0
  40. package/lib/api/errors/RateLimitError.js +37 -0
  41. package/lib/api/handlers/BurstHandler.d.ts +51 -0
  42. package/lib/api/handlers/BurstHandler.js +124 -0
  43. package/lib/api/handlers/SequentialHandler.d.ts +81 -0
  44. package/lib/api/handlers/SequentialHandler.js +365 -0
  45. package/lib/api/handlers/Shared.d.ts +14 -0
  46. package/lib/api/handlers/Shared.js +125 -0
  47. package/lib/api/index.d.ts +5 -0
  48. package/lib/api/index.js +21 -0
  49. package/lib/api/interfaces/Handler.d.ts +21 -0
  50. package/lib/api/interfaces/Handler.js +2 -0
  51. package/lib/api/shared.d.ts +7 -0
  52. package/lib/api/shared.js +27 -0
  53. package/lib/api/utils/constants.d.ts +39 -0
  54. package/lib/api/utils/constants.js +50 -0
  55. package/lib/api/utils/types.d.ts +335 -0
  56. package/lib/api/utils/types.js +14 -0
  57. package/lib/api/utils/utils.d.ts +52 -0
  58. package/lib/api/utils/utils.js +159 -0
  59. package/lib/builders/ActionRow.d.ts +40 -0
  60. package/lib/builders/ActionRow.js +58 -0
  61. package/lib/builders/Attachment.d.ts +106 -0
  62. package/lib/builders/Attachment.js +196 -0
  63. package/lib/builders/Base.d.ts +10 -0
  64. package/lib/builders/Base.js +13 -0
  65. package/lib/builders/Button.d.ts +59 -0
  66. package/lib/builders/Button.js +94 -0
  67. package/lib/builders/MessageEmbed.d.ts +116 -0
  68. package/lib/builders/MessageEmbed.js +159 -0
  69. package/lib/builders/Modal.d.ts +111 -0
  70. package/lib/builders/Modal.js +162 -0
  71. package/lib/builders/SelectMenu.d.ts +201 -0
  72. package/lib/builders/SelectMenu.js +293 -0
  73. package/lib/builders/index.d.ts +12 -0
  74. package/lib/builders/index.js +54 -0
  75. package/lib/builders/types.d.ts +21 -0
  76. package/lib/builders/types.js +2 -0
  77. package/lib/cache/adapters/default.d.ts +24 -0
  78. package/lib/cache/adapters/default.js +118 -0
  79. package/lib/cache/adapters/index.d.ts +4 -0
  80. package/lib/cache/adapters/index.js +20 -0
  81. package/lib/cache/adapters/redis.d.ts +35 -0
  82. package/lib/cache/adapters/redis.js +180 -0
  83. package/lib/cache/adapters/types.d.ts +25 -0
  84. package/lib/cache/adapters/types.js +2 -0
  85. package/lib/cache/adapters/workeradapter.d.ts +24 -0
  86. package/lib/cache/adapters/workeradapter.js +76 -0
  87. package/lib/cache/index.d.ts +97 -0
  88. package/lib/cache/index.js +394 -0
  89. package/lib/cache/resources/channels.d.ts +7 -0
  90. package/lib/cache/resources/channels.js +20 -0
  91. package/lib/cache/resources/default/base.d.ts +25 -0
  92. package/lib/cache/resources/default/base.js +75 -0
  93. package/lib/cache/resources/default/guild-based.d.ts +33 -0
  94. package/lib/cache/resources/default/guild-based.js +91 -0
  95. package/lib/cache/resources/default/guild-related.d.ts +32 -0
  96. package/lib/cache/resources/default/guild-related.js +102 -0
  97. package/lib/cache/resources/emojis.d.ts +7 -0
  98. package/lib/cache/resources/emojis.js +17 -0
  99. package/lib/cache/resources/guilds.d.ts +10 -0
  100. package/lib/cache/resources/guilds.js +117 -0
  101. package/lib/cache/resources/members.d.ts +10 -0
  102. package/lib/cache/resources/members.js +41 -0
  103. package/lib/cache/resources/presence.d.ts +9 -0
  104. package/lib/cache/resources/presence.js +14 -0
  105. package/lib/cache/resources/roles.d.ts +7 -0
  106. package/lib/cache/resources/roles.js +17 -0
  107. package/lib/cache/resources/stage-instances.d.ts +5 -0
  108. package/lib/cache/resources/stage-instances.js +8 -0
  109. package/lib/cache/resources/stickers.d.ts +7 -0
  110. package/lib/cache/resources/stickers.js +17 -0
  111. package/lib/cache/resources/threads.d.ts +7 -0
  112. package/lib/cache/resources/threads.js +17 -0
  113. package/lib/cache/resources/users.d.ts +7 -0
  114. package/lib/cache/resources/users.js +17 -0
  115. package/lib/cache/resources/voice-states.d.ts +9 -0
  116. package/lib/cache/resources/voice-states.js +13 -0
  117. package/lib/client/base.d.ts +244 -0
  118. package/lib/client/base.js +178 -0
  119. package/lib/client/client.d.ts +32 -0
  120. package/lib/client/client.js +156 -0
  121. package/lib/client/httpclient.d.ts +21 -0
  122. package/lib/client/httpclient.js +143 -0
  123. package/lib/client/index.d.ts +4 -0
  124. package/lib/client/index.js +19 -0
  125. package/lib/client/oninteraction.d.ts +4 -0
  126. package/lib/client/oninteraction.js +180 -0
  127. package/lib/client/workerclient.d.ts +28 -0
  128. package/lib/client/workerclient.js +213 -0
  129. package/lib/collection.d.ts +233 -0
  130. package/lib/collection.js +371 -0
  131. package/lib/commands/applications/chat.d.ts +139 -0
  132. package/lib/commands/applications/chat.js +173 -0
  133. package/lib/commands/applications/chatcontext.d.ts +28 -0
  134. package/lib/commands/applications/chatcontext.js +53 -0
  135. package/lib/commands/applications/menu.d.ts +39 -0
  136. package/lib/commands/applications/menu.js +87 -0
  137. package/lib/commands/applications/menucontext.d.ts +25 -0
  138. package/lib/commands/applications/menucontext.js +64 -0
  139. package/lib/commands/applications/options.d.ts +67 -0
  140. package/lib/commands/applications/options.js +44 -0
  141. package/lib/commands/applications/shared.d.ts +35 -0
  142. package/lib/commands/applications/shared.js +2 -0
  143. package/lib/commands/decorators.d.ts +107 -0
  144. package/lib/commands/decorators.js +85 -0
  145. package/lib/commands/handler.d.ts +15 -0
  146. package/lib/commands/handler.js +140 -0
  147. package/lib/commands/index.d.ts +8 -0
  148. package/lib/commands/index.js +24 -0
  149. package/lib/commands/optionresolver.d.ts +49 -0
  150. package/lib/commands/optionresolver.js +146 -0
  151. package/lib/common/bot/watcher.d.ts +53 -0
  152. package/lib/common/bot/watcher.js +104 -0
  153. package/lib/common/index.d.ts +13 -0
  154. package/lib/common/index.js +30 -0
  155. package/lib/common/it/colors.d.ts +274 -0
  156. package/lib/common/it/colors.js +453 -0
  157. package/lib/common/it/constants.d.ts +36 -0
  158. package/lib/common/it/constants.js +40 -0
  159. package/lib/common/it/logger.d.ts +114 -0
  160. package/lib/common/it/logger.js +189 -0
  161. package/lib/common/it/utils.d.ts +107 -0
  162. package/lib/common/it/utils.js +275 -0
  163. package/lib/common/shorters/base.d.ts +5 -0
  164. package/lib/common/shorters/base.js +10 -0
  165. package/lib/common/shorters/channels.d.ts +90 -0
  166. package/lib/common/shorters/channels.js +95 -0
  167. package/lib/common/shorters/guilds.d.ts +389 -0
  168. package/lib/common/shorters/guilds.js +350 -0
  169. package/lib/common/shorters/members.d.ts +115 -0
  170. package/lib/common/shorters/members.js +179 -0
  171. package/lib/common/shorters/messages.d.ts +27 -0
  172. package/lib/common/shorters/messages.js +117 -0
  173. package/lib/common/shorters/roles.d.ts +12 -0
  174. package/lib/common/shorters/roles.js +51 -0
  175. package/lib/common/shorters/templates.d.ts +12 -0
  176. package/lib/common/shorters/templates.js +29 -0
  177. package/lib/common/shorters/users.d.ts +11 -0
  178. package/lib/common/shorters/users.js +42 -0
  179. package/lib/common/shorters/webhook.d.ts +33 -0
  180. package/lib/common/shorters/webhook.js +69 -0
  181. package/lib/common/types/options.d.ts +10 -0
  182. package/lib/common/types/options.js +2 -0
  183. package/lib/common/types/resolvables.d.ts +10 -0
  184. package/lib/common/types/resolvables.js +2 -0
  185. package/lib/common/types/util.d.ts +90 -0
  186. package/lib/common/types/util.js +2 -0
  187. package/lib/common/types/write.d.ts +21 -0
  188. package/lib/common/types/write.js +2 -0
  189. package/lib/components/ActionRow.d.ts +10 -0
  190. package/lib/components/ActionRow.js +13 -0
  191. package/lib/components/ButtonComponent.d.ts +19 -0
  192. package/lib/components/ButtonComponent.js +34 -0
  193. package/lib/components/ChannelSelectMenuComponent.d.ts +6 -0
  194. package/lib/components/ChannelSelectMenuComponent.js +12 -0
  195. package/lib/components/MentionableSelectMenuComponent.d.ts +4 -0
  196. package/lib/components/MentionableSelectMenuComponent.js +7 -0
  197. package/lib/components/RoleSelectMenuComponent.d.ts +4 -0
  198. package/lib/components/RoleSelectMenuComponent.js +7 -0
  199. package/lib/components/StringSelectMenuComponent.d.ts +6 -0
  200. package/lib/components/StringSelectMenuComponent.js +12 -0
  201. package/lib/components/TextInputComponent.d.ts +7 -0
  202. package/lib/components/TextInputComponent.js +14 -0
  203. package/lib/components/UserSelectMenuComponent.d.ts +4 -0
  204. package/lib/components/UserSelectMenuComponent.js +7 -0
  205. package/lib/components/command.d.ts +23 -0
  206. package/lib/components/command.js +15 -0
  207. package/lib/components/handler.d.ts +48 -0
  208. package/lib/components/handler.js +231 -0
  209. package/lib/components/index.d.ts +20 -0
  210. package/lib/components/index.js +55 -0
  211. package/lib/components/listener.d.ts +11 -0
  212. package/lib/components/listener.js +18 -0
  213. package/lib/events/event.d.ts +23 -0
  214. package/lib/events/event.js +2 -0
  215. package/lib/events/handler.d.ts +19 -0
  216. package/lib/events/handler.js +112 -0
  217. package/lib/events/hooks/application_command.d.ts +12 -0
  218. package/lib/events/hooks/application_command.js +8 -0
  219. package/lib/events/hooks/auto_moderation.d.ts +22 -0
  220. package/lib/events/hooks/auto_moderation.js +21 -0
  221. package/lib/events/hooks/channel.d.ts +11 -0
  222. package/lib/events/hooks/channel.js +24 -0
  223. package/lib/events/hooks/custom.d.ts +4 -0
  224. package/lib/events/hooks/custom.js +11 -0
  225. package/lib/events/hooks/dispatch.d.ts +5 -0
  226. package/lib/events/hooks/dispatch.js +12 -0
  227. package/lib/events/hooks/entitlement.d.ts +35 -0
  228. package/lib/events/hooks/entitlement.js +16 -0
  229. package/lib/events/hooks/guild.d.ts +228 -0
  230. package/lib/events/hooks/guild.js +101 -0
  231. package/lib/events/hooks/index.d.ts +23 -0
  232. package/lib/events/hooks/index.js +34 -0
  233. package/lib/events/hooks/integration.d.ts +94 -0
  234. package/lib/events/hooks/integration.js +27 -0
  235. package/lib/events/hooks/interactions.d.ts +4 -0
  236. package/lib/events/hooks/interactions.js +8 -0
  237. package/lib/events/hooks/invite.d.ts +21 -0
  238. package/lib/events/hooks/invite.js +12 -0
  239. package/lib/events/hooks/message.d.ts +69 -0
  240. package/lib/events/hooks/message.js +37 -0
  241. package/lib/events/hooks/presence.d.ts +27 -0
  242. package/lib/events/hooks/presence.js +8 -0
  243. package/lib/events/hooks/stage.d.ts +29 -0
  244. package/lib/events/hooks/stage.js +16 -0
  245. package/lib/events/hooks/thread.d.ts +198 -0
  246. package/lib/events/hooks/thread.js +29 -0
  247. package/lib/events/hooks/typing.d.ts +16 -0
  248. package/lib/events/hooks/typing.js +14 -0
  249. package/lib/events/hooks/user.d.ts +4 -0
  250. package/lib/events/hooks/user.js +8 -0
  251. package/lib/events/hooks/voice.d.ts +37 -0
  252. package/lib/events/hooks/voice.js +18 -0
  253. package/lib/events/hooks/webhook.d.ts +6 -0
  254. package/lib/events/hooks/webhook.js +8 -0
  255. package/lib/events/index.d.ts +2 -0
  256. package/lib/events/index.js +18 -0
  257. package/lib/index.d.ts +79 -0
  258. package/lib/index.js +104 -0
  259. package/lib/langs/handler.d.ts +11 -0
  260. package/lib/langs/handler.js +34 -0
  261. package/lib/langs/index.d.ts +2 -0
  262. package/lib/langs/index.js +18 -0
  263. package/lib/langs/router.d.ts +18 -0
  264. package/lib/langs/router.js +42 -0
  265. package/lib/structures/AnonymousGuild.d.ts +7 -0
  266. package/lib/structures/AnonymousGuild.js +11 -0
  267. package/lib/structures/AutoModerationRule.d.ts +22 -0
  268. package/lib/structures/AutoModerationRule.js +34 -0
  269. package/lib/structures/ClientUser.d.ts +25 -0
  270. package/lib/structures/ClientUser.js +52 -0
  271. package/lib/structures/Guild.d.ts +86 -0
  272. package/lib/structures/Guild.js +66 -0
  273. package/lib/structures/GuildEmoji.d.ts +29 -0
  274. package/lib/structures/GuildEmoji.js +47 -0
  275. package/lib/structures/GuildMember.d.ts +92 -0
  276. package/lib/structures/GuildMember.js +137 -0
  277. package/lib/structures/GuildPreview.d.ts +10 -0
  278. package/lib/structures/GuildPreview.js +14 -0
  279. package/lib/structures/GuildRole.d.ts +21 -0
  280. package/lib/structures/GuildRole.js +32 -0
  281. package/lib/structures/GuildTemplate.d.ts +23 -0
  282. package/lib/structures/GuildTemplate.js +36 -0
  283. package/lib/structures/Interaction.d.ts +152 -0
  284. package/lib/structures/Interaction.js +409 -0
  285. package/lib/structures/Message.d.ts +53 -0
  286. package/lib/structures/Message.js +123 -0
  287. package/lib/structures/Sticker.d.ts +27 -0
  288. package/lib/structures/Sticker.js +44 -0
  289. package/lib/structures/User.d.ts +20 -0
  290. package/lib/structures/User.js +37 -0
  291. package/lib/structures/Webhook.d.ts +42 -0
  292. package/lib/structures/Webhook.js +63 -0
  293. package/lib/structures/channels.d.ts +232 -0
  294. package/lib/structures/channels.js +366 -0
  295. package/lib/structures/extra/Base.d.ts +7 -0
  296. package/lib/structures/extra/Base.js +39 -0
  297. package/lib/structures/extra/BaseComponent.d.ts +9 -0
  298. package/lib/structures/extra/BaseComponent.js +12 -0
  299. package/lib/structures/extra/BaseGuild.d.ts +40 -0
  300. package/lib/structures/extra/BaseGuild.js +71 -0
  301. package/lib/structures/extra/BaseSelectMenuComponent.d.ts +9 -0
  302. package/lib/structures/extra/BaseSelectMenuComponent.js +13 -0
  303. package/lib/structures/extra/BitField.d.ts +14 -0
  304. package/lib/structures/extra/BitField.js +56 -0
  305. package/lib/structures/extra/DiscordBase.d.ts +18 -0
  306. package/lib/structures/extra/DiscordBase.js +28 -0
  307. package/lib/structures/extra/Permissions.d.ts +54 -0
  308. package/lib/structures/extra/Permissions.js +9 -0
  309. package/lib/structures/extra/functions.d.ts +11 -0
  310. package/lib/structures/extra/functions.js +69 -0
  311. package/lib/structures/index.d.ts +15 -0
  312. package/lib/structures/index.js +31 -0
  313. package/lib/websocket/SharedTypes.d.ts +128 -0
  314. package/lib/websocket/SharedTypes.js +2 -0
  315. package/lib/websocket/constants/index.d.ts +26 -0
  316. package/lib/websocket/constants/index.js +31 -0
  317. package/lib/websocket/discord/basesocket.d.ts +12 -0
  318. package/lib/websocket/discord/basesocket.js +37 -0
  319. package/lib/websocket/discord/events/memberUpdate.d.ts +16 -0
  320. package/lib/websocket/discord/events/memberUpdate.js +47 -0
  321. package/lib/websocket/discord/events/presenceUpdate.d.ts +24 -0
  322. package/lib/websocket/discord/events/presenceUpdate.js +46 -0
  323. package/lib/websocket/discord/handlemessage.d.ts +0 -0
  324. package/lib/websocket/discord/handlemessage.js +1 -0
  325. package/lib/websocket/discord/index.d.ts +4 -0
  326. package/lib/websocket/discord/index.js +20 -0
  327. package/lib/websocket/discord/memberUpdate.d.ts +16 -0
  328. package/lib/websocket/discord/memberUpdate.js +47 -0
  329. package/lib/websocket/discord/shard.d.ts +46 -0
  330. package/lib/websocket/discord/shard.js +278 -0
  331. package/lib/websocket/discord/sharder.d.ts +25 -0
  332. package/lib/websocket/discord/sharder.js +153 -0
  333. package/lib/websocket/discord/shared.d.ts +99 -0
  334. package/lib/websocket/discord/shared.js +8 -0
  335. package/lib/websocket/discord/worker.d.ts +43 -0
  336. package/lib/websocket/discord/worker.js +2 -0
  337. package/lib/websocket/discord/workermanager.d.ts +69 -0
  338. package/lib/websocket/discord/workermanager.js +273 -0
  339. package/lib/websocket/index.d.ts +3 -0
  340. package/lib/websocket/index.js +19 -0
  341. package/lib/websocket/structures/index.d.ts +117 -0
  342. package/lib/websocket/structures/index.js +261 -0
  343. package/lib/websocket/structures/timeout.d.ts +20 -0
  344. package/lib/websocket/structures/timeout.js +75 -0
  345. package/package.json +70 -0
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.HttpClient = void 0;
7
+ const form_data_1 = __importDefault(require("form-data"));
8
+ const common_1 = require("../common");
9
+ const base_1 = require("./base");
10
+ const oninteraction_1 = require("./oninteraction");
11
+ let UWS;
12
+ let nacl;
13
+ try {
14
+ UWS = require('uWebSockets.js');
15
+ }
16
+ catch {
17
+ // easter egg #1
18
+ }
19
+ try {
20
+ nacl = require('tweetnacl');
21
+ }
22
+ catch {
23
+ // I always cum
24
+ }
25
+ class HttpClient extends base_1.BaseClient {
26
+ app;
27
+ publicKey;
28
+ publicKeyHex;
29
+ constructor() {
30
+ super();
31
+ if (!UWS) {
32
+ throw new Error('No uws installed.');
33
+ }
34
+ if (!nacl) {
35
+ throw new Error('No tweetnacl installed.');
36
+ }
37
+ }
38
+ static readJson(res) {
39
+ return new Promise((cb, err) => {
40
+ let buffer;
41
+ res.onData((ab, isLast) => {
42
+ const chunk = Buffer.from(ab);
43
+ if (isLast) {
44
+ let json;
45
+ try {
46
+ json = JSON.parse(buffer ? Buffer.concat([buffer, chunk]).toString() : chunk.toString());
47
+ }
48
+ catch (e) {
49
+ res.close();
50
+ return;
51
+ }
52
+ cb(json);
53
+ }
54
+ else {
55
+ buffer = Buffer.concat(buffer ? [buffer, chunk] : [chunk]);
56
+ }
57
+ });
58
+ res.onAborted(err);
59
+ });
60
+ }
61
+ async execute(options) {
62
+ await super.execute();
63
+ const { publicKey: publicKeyRC, port: portRC, applicationId: applicationIdRC, } = await this.getRC();
64
+ const publicKey = options?.publicKey ?? publicKeyRC;
65
+ const port = options?.port ?? portRC;
66
+ if (!publicKey) {
67
+ throw new Error('Expected a publicKey, check your config file');
68
+ }
69
+ if (!port) {
70
+ throw new Error('Expected a port, check your config file');
71
+ }
72
+ if (applicationIdRC) {
73
+ this.applicationId = applicationIdRC;
74
+ }
75
+ this.publicKey = publicKey;
76
+ this.publicKeyHex = Buffer.from(this.publicKey, 'hex');
77
+ this.app = UWS.App();
78
+ this.app.post('/interactions', (res, req) => {
79
+ return this.onPacket(res, req);
80
+ });
81
+ this.app.listen(port, () => {
82
+ this.logger.info(`Listening to port ${port}`);
83
+ });
84
+ }
85
+ async start(options = {}) {
86
+ await super.start(options);
87
+ return this.execute(options.httpConnection);
88
+ }
89
+ // https://discord.com/developers/docs/interactions/receiving-and-responding#security-and-authorization
90
+ async verifySignature(res, req) {
91
+ const body = await HttpClient.readJson(res);
92
+ const timestamp = req.getHeader('x-signature-timestamp');
93
+ const ed25519 = req.getHeader('x-signature-ed25519');
94
+ if (nacl.sign.detached.verify(Buffer.from(timestamp + JSON.stringify(body)), Buffer.from(ed25519, 'hex'), this.publicKeyHex)) {
95
+ return body;
96
+ }
97
+ return;
98
+ }
99
+ async onPacket(res, req) {
100
+ const rawBody = await this.verifySignature(res, req);
101
+ if (!rawBody) {
102
+ this.debugger?.debug('Invalid request/No info, returning 418 status.');
103
+ // I'm a teapot
104
+ res.writeStatus('418').end();
105
+ }
106
+ else {
107
+ switch (rawBody.type) {
108
+ case common_1.InteractionType.Ping:
109
+ this.debugger?.debug('Ping interaction received, responding.');
110
+ res
111
+ .writeHeader('Content-Type', 'application/json')
112
+ .end(JSON.stringify({ type: common_1.InteractionResponseType.Pong }));
113
+ break;
114
+ default:
115
+ await (0, oninteraction_1.onInteraction)(-1, rawBody, this, async ({ body, files }) => {
116
+ let response;
117
+ let headers = {};
118
+ if (files?.length) {
119
+ response = new form_data_1.default();
120
+ for (const key in files) {
121
+ const file = files[key];
122
+ response.append(key, file.data, file);
123
+ }
124
+ if (body) {
125
+ response.append('payload_json', JSON.stringify(body));
126
+ }
127
+ headers = Object.assign(headers, response.getHeaders());
128
+ }
129
+ else {
130
+ response = body ?? {};
131
+ headers['Content-Type'] = 'application/json';
132
+ }
133
+ for (const i in headers) {
134
+ res.writeHeader(i, headers[i]);
135
+ }
136
+ return res.end(JSON.stringify(response));
137
+ });
138
+ break;
139
+ }
140
+ }
141
+ }
142
+ }
143
+ exports.HttpClient = HttpClient;
@@ -0,0 +1,4 @@
1
+ export type { RuntimeConfig, RuntimeConfigHTTP } from './base';
2
+ export * from './client';
3
+ export * from './httpclient';
4
+ export * from './workerclient';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./client"), exports);
18
+ __exportStar(require("./httpclient"), exports);
19
+ __exportStar(require("./workerclient"), exports);
@@ -0,0 +1,4 @@
1
+ import { type APIInteraction } from 'discord-api-types/v10';
2
+ import type { __InternalReplyFunction } from '../structures';
3
+ import type { BaseClient } from './base';
4
+ export declare function onInteraction(shardId: number, body: APIInteraction, self: BaseClient, __reply?: __InternalReplyFunction): Promise<any>;
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.onInteraction = void 0;
4
+ const v10_1 = require("discord-api-types/v10");
5
+ const commands_1 = require("../commands");
6
+ const structures_1 = require("../structures");
7
+ async function onInteraction(shardId, body, self, __reply) {
8
+ self.debugger?.debug(`[${v10_1.InteractionType[body.type] ?? body.type}] Interaction received.`);
9
+ switch (body.type) {
10
+ case v10_1.InteractionType.ApplicationCommandAutocomplete:
11
+ {
12
+ const parentCommand = self.commands.values.find(x => {
13
+ if (x.guild_id && !x.guild_id.includes(body.data.guild_id ?? '')) {
14
+ return false;
15
+ }
16
+ return x.name === body.data.name;
17
+ });
18
+ const optionsResolver = new commands_1.OptionResolver(self, body.data.options ?? [], parentCommand, body.data.guild_id, body.data.resolved);
19
+ const interaction = new structures_1.AutocompleteInteraction(self, body, __reply);
20
+ const command = optionsResolver.getAutocomplete();
21
+ // idc, is a YOU problem
22
+ if (!command?.autocomplete)
23
+ return self.logger.warn(`${optionsResolver.fullCommandName} ${command?.name} command does not have 'autocomplete' callback`);
24
+ try {
25
+ try {
26
+ await command.autocomplete(interaction);
27
+ }
28
+ catch (error) {
29
+ self.logger.error(`${optionsResolver.fullCommandName} ${command.name} just threw an error, ${error ? (typeof error === 'object' && 'message' in error ? error.message : error) : 'Unknown'}`);
30
+ await command.onAutocompleteError?.(interaction, error);
31
+ }
32
+ }
33
+ catch (error) {
34
+ try {
35
+ await optionsResolver.getCommand()?.onInternalError(self, error);
36
+ }
37
+ catch {
38
+ // supress error
39
+ }
40
+ }
41
+ }
42
+ break;
43
+ case v10_1.InteractionType.ApplicationCommand:
44
+ {
45
+ switch (body.data.type) {
46
+ case v10_1.ApplicationCommandType.Message:
47
+ case v10_1.ApplicationCommandType.User:
48
+ {
49
+ const command = self.commands.values.find(x => {
50
+ if (x.guild_id && !x.guild_id.includes(body.data.guild_id ?? '')) {
51
+ return false;
52
+ }
53
+ return x.name === body.data.name;
54
+ });
55
+ const interaction = structures_1.BaseInteraction.from(self, body, __reply);
56
+ // idc, is a YOU problem
57
+ if (!command?.run)
58
+ return self.logger.warn(`${command.name ?? 'Unknown'} command does not have 'run' callback`);
59
+ const context = new commands_1.MenuCommandContext(self, interaction, shardId);
60
+ const extendContext = self.options?.context?.(interaction) ?? {};
61
+ Object.assign(context, extendContext);
62
+ try {
63
+ const resultRunGlobalMiddlewares = await command.__runGlobalMiddlewares(context);
64
+ if (resultRunGlobalMiddlewares === 'pass') {
65
+ return;
66
+ }
67
+ if (resultRunGlobalMiddlewares) {
68
+ return command.onMiddlewaresError?.(context, resultRunGlobalMiddlewares);
69
+ }
70
+ const resultRunMiddlewares = await command.__runMiddlewares(context);
71
+ if (resultRunMiddlewares === 'pass') {
72
+ return;
73
+ }
74
+ if (resultRunGlobalMiddlewares) {
75
+ return command.onMiddlewaresError?.(context, resultRunGlobalMiddlewares);
76
+ }
77
+ try {
78
+ await command.run(context);
79
+ await command.onAfterRun?.(context, undefined);
80
+ }
81
+ catch (error) {
82
+ self.logger.error(`${command.name} just threw an error, ${error ? (typeof error === 'object' && 'message' in error ? error.message : error) : 'Unknown'}`);
83
+ await command.onRunError?.(context, error);
84
+ await command.onAfterRun?.(context, error);
85
+ }
86
+ }
87
+ catch (error) {
88
+ try {
89
+ await command.onInternalError(self, error);
90
+ }
91
+ catch {
92
+ // supress error
93
+ }
94
+ }
95
+ }
96
+ break;
97
+ case v10_1.ApplicationCommandType.ChatInput:
98
+ {
99
+ const packetData = body.data;
100
+ const parentCommand = self.commands.values.find(x => {
101
+ if (x.guild_id && !x.guild_id.includes(packetData.guild_id ?? '')) {
102
+ return false;
103
+ }
104
+ return x.name === packetData.name;
105
+ });
106
+ const optionsResolver = new commands_1.OptionResolver(self, packetData.options ?? [], parentCommand, packetData.guild_id, packetData.resolved);
107
+ const interaction = structures_1.BaseInteraction.from(self, body, __reply);
108
+ const command = optionsResolver.getCommand();
109
+ if (!command?.run)
110
+ return self.logger.warn(`${optionsResolver.fullCommandName} command does not have 'run' callback`);
111
+ const context = new commands_1.CommandContext(self, interaction, optionsResolver, shardId);
112
+ const extendContext = self.options?.context?.(interaction) ?? {};
113
+ Object.assign(context, extendContext);
114
+ try {
115
+ const [erroredOptions, result] = await command.__runOptions(context, optionsResolver);
116
+ if (erroredOptions) {
117
+ return command.onOptionsError?.(context, result);
118
+ }
119
+ const resultRunGlobalMiddlewares = await command.__runGlobalMiddlewares(context);
120
+ if (resultRunGlobalMiddlewares === 'pass') {
121
+ return;
122
+ }
123
+ if (resultRunGlobalMiddlewares) {
124
+ return command.onMiddlewaresError?.(context, resultRunGlobalMiddlewares);
125
+ }
126
+ const resultRunMiddlewares = await command.__runMiddlewares(context);
127
+ if (resultRunMiddlewares === 'pass') {
128
+ return;
129
+ }
130
+ if (resultRunMiddlewares) {
131
+ return command.onMiddlewaresError?.(context, resultRunMiddlewares);
132
+ }
133
+ try {
134
+ await command.run(context);
135
+ await command.onAfterRun?.(context, undefined);
136
+ }
137
+ catch (error) {
138
+ self.logger.error(`${optionsResolver.fullCommandName} just threw an error, ${error ? (typeof error === 'object' && 'message' in error ? error.message : error) : 'Unknown'}`);
139
+ await command.onRunError?.(context, error);
140
+ await command.onAfterRun?.(context, error);
141
+ }
142
+ }
143
+ catch (error) {
144
+ try {
145
+ await command.onInternalError(self, error);
146
+ }
147
+ catch {
148
+ // supress error
149
+ }
150
+ }
151
+ }
152
+ break;
153
+ }
154
+ }
155
+ break;
156
+ case v10_1.InteractionType.ModalSubmit:
157
+ {
158
+ const interaction = structures_1.BaseInteraction.from(self, body, __reply);
159
+ if (self.components.hasModal(interaction)) {
160
+ await self.components.onModalSubmit(interaction);
161
+ }
162
+ else {
163
+ await self.components.executeModal(interaction);
164
+ }
165
+ }
166
+ break;
167
+ case v10_1.InteractionType.MessageComponent:
168
+ {
169
+ const interaction = structures_1.BaseInteraction.from(self, body, __reply);
170
+ if (self.components.hasComponent(body.message.interaction.id, interaction.customId)) {
171
+ await self.components.onComponent(body.message.interaction.id, interaction);
172
+ }
173
+ else {
174
+ await self.components.executeComponent(interaction);
175
+ }
176
+ }
177
+ break;
178
+ }
179
+ }
180
+ exports.onInteraction = onInteraction;
@@ -0,0 +1,28 @@
1
+ import type { Cache } from '../cache';
2
+ import type { GatewayDispatchPayload, When } from '../common';
3
+ import { Logger, type DeepPartial } from '../common';
4
+ import { EventHandler } from '../events';
5
+ import { ClientUser } from '../structures';
6
+ import { Shard } from '../websocket';
7
+ import type { WorkerShardInfo } from '../websocket/discord/worker';
8
+ import type { ManagerMessages } from '../websocket/discord/workermanager';
9
+ import type { BaseClientOptions, StartOptions } from './base';
10
+ import { BaseClient } from './base';
11
+ export declare class WorkerClient<Ready extends boolean = boolean> extends BaseClient {
12
+ logger: Logger;
13
+ events: EventHandler;
14
+ me: When<Ready, ClientUser>;
15
+ shards: Map<number, Shard>;
16
+ options: WorkerClientOptions | undefined;
17
+ constructor(options?: WorkerClientOptions);
18
+ get workerId(): number;
19
+ start(options?: Omit<DeepPartial<StartOptions>, 'httpConnection' | 'token' | 'connection'>): Promise<void>;
20
+ loadEvents(dir?: string): Promise<void>;
21
+ protected handleManagerMessages(data: ManagerMessages): Promise<void>;
22
+ protected onPacket(packet: GatewayDispatchPayload, shardId: number): Promise<void>;
23
+ }
24
+ export declare function generateShardInfo(shard: Shard): WorkerShardInfo;
25
+ interface WorkerClientOptions extends BaseClientOptions {
26
+ disabledCache: Cache['disabledCache'];
27
+ }
28
+ export {};
@@ -0,0 +1,213 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateShardInfo = exports.WorkerClient = void 0;
4
+ const node_worker_threads_1 = require("node:worker_threads");
5
+ const cache_1 = require("../cache");
6
+ const common_1 = require("../common");
7
+ const events_1 = require("../events");
8
+ const structures_1 = require("../structures");
9
+ const websocket_1 = require("../websocket");
10
+ const base_1 = require("./base");
11
+ const oninteraction_1 = require("./oninteraction");
12
+ const workerData = node_worker_threads_1.workerData;
13
+ class WorkerClient extends base_1.BaseClient {
14
+ logger = new common_1.Logger({
15
+ name: `[Worker #${workerData.workerId}]`,
16
+ });
17
+ events = new events_1.EventHandler(this.logger);
18
+ me;
19
+ shards = new Map();
20
+ constructor(options) {
21
+ super(options);
22
+ if (!node_worker_threads_1.parentPort) {
23
+ throw new Error('WorkerClient cannot spawn without manager');
24
+ }
25
+ node_worker_threads_1.parentPort.on('message', data => this.handleManagerMessages(data));
26
+ this.setServices({
27
+ cache: {
28
+ adapter: new cache_1.WorkerAdapter(node_worker_threads_1.parentPort),
29
+ disabledCache: options?.disabledCache,
30
+ },
31
+ });
32
+ if (workerData.debug) {
33
+ this.debugger = new common_1.Logger({
34
+ name: `[Worker #${workerData.workerId}]`,
35
+ logLevel: common_1.LogLevels.Debug,
36
+ });
37
+ }
38
+ }
39
+ get workerId() {
40
+ return workerData.workerId;
41
+ }
42
+ async start(options = {}) {
43
+ await super.start(options);
44
+ await this.loadEvents(options.eventsDir);
45
+ this.cache.intents = workerData.intents;
46
+ }
47
+ async loadEvents(dir) {
48
+ dir ??= await this.getRC().then(x => x.events);
49
+ if (dir) {
50
+ await this.events.load(dir);
51
+ this.logger.info('EventHandler loaded');
52
+ }
53
+ }
54
+ async handleManagerMessages(data) {
55
+ switch (data.type) {
56
+ case 'CACHE_RESULT':
57
+ if (this.cache.adapter.promises.has(data.nonce)) {
58
+ this.cache.adapter.promises.get(data.nonce)?.(data.result);
59
+ this.cache.adapter.promises.delete(data.nonce);
60
+ }
61
+ break;
62
+ case 'SEND_PAYLOAD':
63
+ {
64
+ const shard = this.shards.get(data.shardId);
65
+ if (!shard) {
66
+ this.logger.fatal('Worker trying send payload by non-existent shard');
67
+ return;
68
+ }
69
+ await shard.send(0, {
70
+ ...data,
71
+ });
72
+ node_worker_threads_1.parentPort.postMessage({
73
+ type: 'RESULT_PAYLOAD',
74
+ nonce: data.nonce,
75
+ });
76
+ }
77
+ break;
78
+ case 'ALLOW_CONNECT':
79
+ {
80
+ const shard = this.shards.get(data.shardId);
81
+ if (!shard) {
82
+ this.logger.fatal('Worker trying connect non-existent shard');
83
+ return;
84
+ }
85
+ shard.options.presence = data.presence;
86
+ await shard.connect();
87
+ }
88
+ break;
89
+ case 'SPAWN_SHARDS':
90
+ {
91
+ const cache = this.cache;
92
+ const onPacket = this.onPacket.bind(this);
93
+ for (const id of workerData.shards) {
94
+ let shard = this.shards.get(id);
95
+ if (!shard) {
96
+ shard = new websocket_1.Shard(id, {
97
+ token: workerData.token,
98
+ intents: workerData.intents,
99
+ info: data.info,
100
+ compress: data.compress,
101
+ debugger: this.debugger,
102
+ async handlePayload(shardId, payload) {
103
+ await cache.onPacket(payload);
104
+ await onPacket?.(payload, shardId);
105
+ node_worker_threads_1.parentPort.postMessage({
106
+ workerId: workerData.workerId,
107
+ shardId,
108
+ type: 'RECEIVE_PAYLOAD',
109
+ payload,
110
+ });
111
+ },
112
+ });
113
+ this.shards.set(id, shard);
114
+ }
115
+ node_worker_threads_1.parentPort.postMessage({
116
+ type: 'CONNECT_QUEUE',
117
+ shardId: id,
118
+ workerId: workerData.workerId,
119
+ });
120
+ }
121
+ }
122
+ break;
123
+ case 'SHARD_INFO':
124
+ {
125
+ const shard = this.shards.get(data.shardId);
126
+ if (!shard) {
127
+ this.logger.fatal('Worker trying get non-existent shard');
128
+ return;
129
+ }
130
+ node_worker_threads_1.parentPort.postMessage({
131
+ ...generateShardInfo(shard),
132
+ nonce: data.nonce,
133
+ type: 'SHARD_INFO',
134
+ });
135
+ }
136
+ break;
137
+ case 'WORKER_INFO':
138
+ {
139
+ node_worker_threads_1.parentPort.postMessage({
140
+ shards: [...this.shards.values()].map(generateShardInfo),
141
+ workerId: workerData.workerId,
142
+ type: 'WORKER_INFO',
143
+ nonce: data.nonce,
144
+ });
145
+ }
146
+ break;
147
+ case 'BOT_READY':
148
+ if (this.events.values.BOT_READY &&
149
+ (this.events.values.BOT_READY.fired ? !this.events.values.BOT_READY.data.once : true)) {
150
+ this.events.values.BOT_READY.fired = true;
151
+ await this.events.values.BOT_READY.run(this.me, this, -1);
152
+ }
153
+ break;
154
+ }
155
+ }
156
+ async onPacket(packet, shardId) {
157
+ switch (packet.t) {
158
+ case 'READY':
159
+ for (const g of packet.d.guilds) {
160
+ this.__handleGuilds.add(g.id);
161
+ }
162
+ this.botId = packet.d.user.id;
163
+ this.applicationId = packet.d.application.id;
164
+ this.me = new structures_1.ClientUser(this, packet.d.user, packet.d.application);
165
+ if (!this.__handleGuilds.size) {
166
+ if ([...this.shards.values()].every(shard => shard.data.session_id) &&
167
+ this.events.values.WORKER_READY &&
168
+ (this.events.values.WORKER_READY.fired ? !this.events.values.WORKER_READY.data.once : true)) {
169
+ node_worker_threads_1.parentPort.postMessage({
170
+ type: 'WORKER_READY',
171
+ workerId: this.workerId,
172
+ });
173
+ this.events.values.WORKER_READY.fired = true;
174
+ await this.events.values.WORKER_READY.run(this.me, this, -1);
175
+ }
176
+ }
177
+ this.debugger?.debug(`#${shardId} [${packet.d.user.username}](${this.botId}) is online...`);
178
+ break;
179
+ case 'INTERACTION_CREATE': {
180
+ await (0, oninteraction_1.onInteraction)(shardId, packet.d, this);
181
+ break;
182
+ }
183
+ case 'GUILD_CREATE': {
184
+ if (this.__handleGuilds.has(packet.d.id)) {
185
+ this.__handleGuilds.delete(packet.d.id);
186
+ if (!this.__handleGuilds.size &&
187
+ [...this.shards.values()].every(shard => shard.data.session_id) &&
188
+ this.events.values.WORKER_READY &&
189
+ (this.events.values.WORKER_READY.fired ? !this.events.values.WORKER_READY.data.once : true)) {
190
+ node_worker_threads_1.parentPort.postMessage({
191
+ type: 'WORKER_READY',
192
+ workerId: this.workerId,
193
+ });
194
+ this.events.values.WORKER_READY.fired = true;
195
+ await this.events.values.WORKER_READY.run(this.me, this, -1);
196
+ }
197
+ return;
198
+ }
199
+ }
200
+ }
201
+ await this.events.execute(packet.t, packet, this, shardId);
202
+ }
203
+ }
204
+ exports.WorkerClient = WorkerClient;
205
+ function generateShardInfo(shard) {
206
+ return {
207
+ open: shard.isOpen,
208
+ shardId: shard.id,
209
+ latency: shard.latency,
210
+ resumable: shard.resumable,
211
+ };
212
+ }
213
+ exports.generateShardInfo = generateShardInfo;