@buape/carbon 0.2.0 → 0.3.1

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 (275) hide show
  1. package/dist/package.json +7 -2
  2. package/dist/src/abstracts/BaseComponentInteraction.d.ts +6 -1
  3. package/dist/src/abstracts/BaseComponentInteraction.d.ts.map +1 -1
  4. package/dist/src/abstracts/BaseComponentInteraction.js +12 -0
  5. package/dist/src/abstracts/BaseComponentInteraction.js.map +1 -1
  6. package/dist/src/abstracts/BaseInteraction.d.ts +10 -1
  7. package/dist/src/abstracts/BaseInteraction.d.ts.map +1 -1
  8. package/dist/src/abstracts/BaseInteraction.js +10 -1
  9. package/dist/src/abstracts/BaseInteraction.js.map +1 -1
  10. package/dist/src/classes/Client.d.ts.map +1 -1
  11. package/dist/src/classes/Client.js +21 -11
  12. package/dist/src/classes/Client.js.map +1 -1
  13. package/dist/src/classes/Embed.d.ts +60 -0
  14. package/dist/src/classes/Embed.d.ts.map +1 -0
  15. package/dist/src/classes/Embed.js +73 -0
  16. package/dist/src/classes/Embed.js.map +1 -0
  17. package/dist/src/index.d.ts +4 -1
  18. package/dist/src/index.d.ts.map +1 -1
  19. package/dist/src/index.js +4 -1
  20. package/dist/src/index.js.map +1 -1
  21. package/dist/src/internals/AutocompleteInteraction.d.ts +1 -1
  22. package/dist/src/internals/FieldsHandler.d.ts +27 -0
  23. package/dist/src/internals/FieldsHandler.d.ts.map +1 -0
  24. package/dist/src/internals/FieldsHandler.js +37 -0
  25. package/dist/src/internals/FieldsHandler.js.map +1 -0
  26. package/dist/src/internals/ModalInteraction.d.ts +3 -4
  27. package/dist/src/internals/ModalInteraction.d.ts.map +1 -1
  28. package/dist/src/internals/ModalInteraction.js +3 -10
  29. package/dist/src/internals/ModalInteraction.js.map +1 -1
  30. package/dist/src/internals/OptionsHandler.d.ts +33 -17
  31. package/dist/src/internals/OptionsHandler.d.ts.map +1 -1
  32. package/dist/src/internals/OptionsHandler.js +52 -58
  33. package/dist/src/internals/OptionsHandler.js.map +1 -1
  34. package/dist/src/utils.d.ts +3 -0
  35. package/dist/src/utils.d.ts.map +1 -1
  36. package/dist/src/utils.js +54 -0
  37. package/dist/src/utils.js.map +1 -1
  38. package/dist/tsconfig.tsbuildinfo +1 -1
  39. package/package.json +6 -1
  40. package/.turbo/turbo-build.log +0 -5
  41. package/.turbo/turbo-dev.log +0 -8
  42. package/.turbo/turbo-docs.log +0 -12
  43. package/CHANGELOG.md +0 -44
  44. package/dist/src/abstracts/ButtonInteraction.d.ts +0 -8
  45. package/dist/src/abstracts/ButtonInteraction.d.ts.map +0 -1
  46. package/dist/src/abstracts/ButtonInteraction.js +0 -18
  47. package/dist/src/abstracts/ButtonInteraction.js.map +0 -1
  48. package/dist/src/abstracts/ChannelSelectMenuInteraction.d.ts +0 -7
  49. package/dist/src/abstracts/ChannelSelectMenuInteraction.d.ts.map +0 -1
  50. package/dist/src/abstracts/ChannelSelectMenuInteraction.js +0 -11
  51. package/dist/src/abstracts/ChannelSelectMenuInteraction.js.map +0 -1
  52. package/dist/src/abstracts/CommandHandler.d.ts +0 -6
  53. package/dist/src/abstracts/CommandHandler.d.ts.map +0 -1
  54. package/dist/src/abstracts/CommandHandler.js +0 -65
  55. package/dist/src/abstracts/CommandHandler.js.map +0 -1
  56. package/dist/src/abstracts/CommandInteraction.d.ts +0 -15
  57. package/dist/src/abstracts/CommandInteraction.d.ts.map +0 -1
  58. package/dist/src/abstracts/CommandInteraction.js +0 -60
  59. package/dist/src/abstracts/CommandInteraction.js.map +0 -1
  60. package/dist/src/abstracts/ComponentHandler.d.ts +0 -6
  61. package/dist/src/abstracts/ComponentHandler.d.ts.map +0 -1
  62. package/dist/src/abstracts/ComponentHandler.js +0 -64
  63. package/dist/src/abstracts/ComponentHandler.js.map +0 -1
  64. package/dist/src/abstracts/MentionableSelectMenuInteraction.d.ts +0 -8
  65. package/dist/src/abstracts/MentionableSelectMenuInteraction.d.ts.map +0 -1
  66. package/dist/src/abstracts/MentionableSelectMenuInteraction.js +0 -15
  67. package/dist/src/abstracts/MentionableSelectMenuInteraction.js.map +0 -1
  68. package/dist/src/abstracts/RoleSelectMenuInteraction.d.ts +0 -8
  69. package/dist/src/abstracts/RoleSelectMenuInteraction.d.ts.map +0 -1
  70. package/dist/src/abstracts/RoleSelectMenuInteraction.js +0 -14
  71. package/dist/src/abstracts/RoleSelectMenuInteraction.js.map +0 -1
  72. package/dist/src/abstracts/StringSelectMenuInteraction.d.ts +0 -8
  73. package/dist/src/abstracts/StringSelectMenuInteraction.d.ts.map +0 -1
  74. package/dist/src/abstracts/StringSelectMenuInteraction.js +0 -14
  75. package/dist/src/abstracts/StringSelectMenuInteraction.js.map +0 -1
  76. package/dist/src/abstracts/UserSelectMenuInteraction.d.ts +0 -8
  77. package/dist/src/abstracts/UserSelectMenuInteraction.d.ts.map +0 -1
  78. package/dist/src/abstracts/UserSelectMenuInteraction.js +0 -14
  79. package/dist/src/abstracts/UserSelectMenuInteraction.js.map +0 -1
  80. package/dist/src/classes/Paginator.d.ts +0 -3
  81. package/dist/src/classes/Paginator.d.ts.map +0 -1
  82. package/dist/src/classes/Paginator.js +0 -3
  83. package/dist/src/classes/Paginator.js.map +0 -1
  84. package/dist/src/internals/ComponentHandler copy.d.ts +0 -17
  85. package/dist/src/internals/ComponentHandler copy.d.ts.map +0 -1
  86. package/dist/src/internals/ComponentHandler copy.js +0 -75
  87. package/dist/src/internals/ComponentHandler copy.js.map +0 -1
  88. package/dist/src/structures/AnySelectMenu.d.ts +0 -31
  89. package/dist/src/structures/AnySelectMenu.d.ts.map +0 -1
  90. package/dist/src/structures/AnySelectMenu.js +0 -19
  91. package/dist/src/structures/AnySelectMenu.js.map +0 -1
  92. package/dist/src/structures/AnySelectMenuInteraction.d.ts +0 -12
  93. package/dist/src/structures/AnySelectMenuInteraction.d.ts.map +0 -1
  94. package/dist/src/structures/AnySelectMenuInteraction.js +0 -21
  95. package/dist/src/structures/AnySelectMenuInteraction.js.map +0 -1
  96. package/dist/src/structures/Base.d.ts +0 -10
  97. package/dist/src/structures/Base.d.ts.map +0 -1
  98. package/dist/src/structures/Base.js +0 -11
  99. package/dist/src/structures/Base.js.map +0 -1
  100. package/dist/src/structures/BaseCommand.d.ts +0 -64
  101. package/dist/src/structures/BaseCommand.d.ts.map +0 -1
  102. package/dist/src/structures/BaseCommand.js +0 -58
  103. package/dist/src/structures/BaseCommand.js.map +0 -1
  104. package/dist/src/structures/BaseComponent.d.ts +0 -34
  105. package/dist/src/structures/BaseComponent.d.ts.map +0 -1
  106. package/dist/src/structures/BaseComponent.js +0 -30
  107. package/dist/src/structures/BaseComponent.js.map +0 -1
  108. package/dist/src/structures/BaseComponentInteraction.d.ts +0 -9
  109. package/dist/src/structures/BaseComponentInteraction.d.ts.map +0 -1
  110. package/dist/src/structures/BaseComponentInteraction.js +0 -14
  111. package/dist/src/structures/BaseComponentInteraction.js.map +0 -1
  112. package/dist/src/structures/BaseInteraction.d.ts +0 -81
  113. package/dist/src/structures/BaseInteraction.d.ts.map +0 -1
  114. package/dist/src/structures/BaseInteraction.js +0 -99
  115. package/dist/src/structures/BaseInteraction.js.map +0 -1
  116. package/dist/src/structures/ButtonInteraction.d.ts +0 -8
  117. package/dist/src/structures/ButtonInteraction.d.ts.map +0 -1
  118. package/dist/src/structures/ButtonInteraction.js +0 -18
  119. package/dist/src/structures/ButtonInteraction.js.map +0 -1
  120. package/dist/src/structures/ChannelSelectMenuInteraction.d.ts +0 -7
  121. package/dist/src/structures/ChannelSelectMenuInteraction.d.ts.map +0 -1
  122. package/dist/src/structures/ChannelSelectMenuInteraction.js +0 -11
  123. package/dist/src/structures/ChannelSelectMenuInteraction.js.map +0 -1
  124. package/dist/src/structures/CommandHandler.d.ts +0 -6
  125. package/dist/src/structures/CommandHandler.d.ts.map +0 -1
  126. package/dist/src/structures/CommandHandler.js +0 -70
  127. package/dist/src/structures/CommandHandler.js.map +0 -1
  128. package/dist/src/structures/CommandInteraction.d.ts +0 -15
  129. package/dist/src/structures/CommandInteraction.d.ts.map +0 -1
  130. package/dist/src/structures/CommandInteraction.js +0 -60
  131. package/dist/src/structures/CommandInteraction.js.map +0 -1
  132. package/dist/src/structures/ComponentHandler.d.ts +0 -6
  133. package/dist/src/structures/ComponentHandler.d.ts.map +0 -1
  134. package/dist/src/structures/ComponentHandler.js +0 -64
  135. package/dist/src/structures/ComponentHandler.js.map +0 -1
  136. package/dist/src/structures/MentionableSelectMenuInteraction.d.ts +0 -8
  137. package/dist/src/structures/MentionableSelectMenuInteraction.d.ts.map +0 -1
  138. package/dist/src/structures/MentionableSelectMenuInteraction.js +0 -15
  139. package/dist/src/structures/MentionableSelectMenuInteraction.js.map +0 -1
  140. package/dist/src/structures/RoleSelectMenuInteraction.d.ts +0 -8
  141. package/dist/src/structures/RoleSelectMenuInteraction.d.ts.map +0 -1
  142. package/dist/src/structures/RoleSelectMenuInteraction.js +0 -14
  143. package/dist/src/structures/RoleSelectMenuInteraction.js.map +0 -1
  144. package/dist/src/structures/StringSelectMenuInteraction.d.ts +0 -8
  145. package/dist/src/structures/StringSelectMenuInteraction.d.ts.map +0 -1
  146. package/dist/src/structures/StringSelectMenuInteraction.js +0 -14
  147. package/dist/src/structures/StringSelectMenuInteraction.js.map +0 -1
  148. package/dist/src/structures/UserSelectMenuInteraction.d.ts +0 -8
  149. package/dist/src/structures/UserSelectMenuInteraction.d.ts.map +0 -1
  150. package/dist/src/structures/UserSelectMenuInteraction.js +0 -14
  151. package/dist/src/structures/UserSelectMenuInteraction.js.map +0 -1
  152. package/dist/src/types.d.ts +0 -31
  153. package/dist/src/types.d.ts.map +0 -1
  154. package/dist/src/types.js +0 -33
  155. package/dist/src/types.js.map +0 -1
  156. package/docs/classes/AnySelectMenu.mdx +0 -114
  157. package/docs/classes/AnySelectMenuInteraction.mdx +0 -175
  158. package/docs/classes/AutocompleteInteraction.mdx +0 -166
  159. package/docs/classes/AutocompleteOptionsHandler.mdx +0 -243
  160. package/docs/classes/BaseChannel.mdx +0 -97
  161. package/docs/classes/BaseCommand.mdx +0 -61
  162. package/docs/classes/BaseComponent.mdx +0 -55
  163. package/docs/classes/BaseComponentInteraction.mdx +0 -160
  164. package/docs/classes/BaseGuildChannel.mdx +0 -262
  165. package/docs/classes/BaseGuildTextChannel.mdx +0 -360
  166. package/docs/classes/BaseInteraction.mdx +0 -137
  167. package/docs/classes/Button.mdx +0 -99
  168. package/docs/classes/ButtonInteraction.mdx +0 -155
  169. package/docs/classes/ChannelSelectMenu.mdx +0 -122
  170. package/docs/classes/ChannelSelectMenuInteraction.mdx +0 -171
  171. package/docs/classes/Client.mdx +0 -48
  172. package/docs/classes/Command.mdx +0 -111
  173. package/docs/classes/CommandHandler.mdx +0 -65
  174. package/docs/classes/CommandInteraction.mdx +0 -155
  175. package/docs/classes/CommandWithSubcommandGroups.mdx +0 -73
  176. package/docs/classes/CommandWithSubcommands.mdx +0 -76
  177. package/docs/classes/ComponentHandler.mdx +0 -49
  178. package/docs/classes/DmChannel.mdx +0 -118
  179. package/docs/classes/GroupDmChannel.mdx +0 -197
  180. package/docs/classes/Guild.mdx +0 -157
  181. package/docs/classes/GuildAnnouncementChannel.mdx +0 -377
  182. package/docs/classes/GuildCategoryChannel.mdx +0 -272
  183. package/docs/classes/GuildForumChannel.mdx +0 -333
  184. package/docs/classes/GuildMediaChannel.mdx +0 -327
  185. package/docs/classes/GuildStageChannel.mdx +0 -276
  186. package/docs/classes/GuildStageOrVoiceChannel.mdx +0 -292
  187. package/docs/classes/GuildTextChannel.mdx +0 -367
  188. package/docs/classes/GuildThreadChannel.mdx +0 -425
  189. package/docs/classes/GuildThreadOnlyChannel.mdx +0 -333
  190. package/docs/classes/GuildVoiceChannel.mdx +0 -276
  191. package/docs/classes/LinkButton.mdx +0 -84
  192. package/docs/classes/MentionableSelectMenu.mdx +0 -120
  193. package/docs/classes/MentionableSelectMenuInteraction.mdx +0 -171
  194. package/docs/classes/Message.mdx +0 -126
  195. package/docs/classes/OptionsHandler.mdx +0 -203
  196. package/docs/classes/PremiumButton.mdx +0 -84
  197. package/docs/classes/Role.mdx +0 -228
  198. package/docs/classes/RoleSelectMenu.mdx +0 -120
  199. package/docs/classes/RoleSelectMenuInteraction.mdx +0 -171
  200. package/docs/classes/Row.mdx +0 -88
  201. package/docs/classes/StringSelectMenu.mdx +0 -120
  202. package/docs/classes/StringSelectMenuInteraction.mdx +0 -171
  203. package/docs/classes/User.mdx +0 -119
  204. package/docs/classes/UserSelectMenu.mdx +0 -120
  205. package/docs/classes/UserSelectMenuInteraction.mdx +0 -171
  206. package/docs/enumerations/ClientMode.mdx +0 -16
  207. package/docs/functions/channelFactory.mdx +0 -16
  208. package/docs/index.mdx +0 -83
  209. package/docs/type-aliases/AnySelectMenuComponentType.mdx +0 -5
  210. package/docs/type-aliases/ClientOptions.mdx +0 -20
  211. package/docs/type-aliases/CommandOptions.mdx +0 -5
  212. package/docs/type-aliases/ComponentAdditionalData.mdx +0 -9
  213. package/docs/type-aliases/InteractionFileData.mdx +0 -15
  214. package/docs/type-aliases/InteractionReplyData.mdx +0 -14
  215. package/docs/type-aliases/InteractionReplyOptions.mdx +0 -13
  216. package/docs/type-aliases/RawOptions.mdx +0 -9
  217. package/docs/type-aliases/meta.json +0 -3
  218. package/src/README.md +0 -7
  219. package/src/abstracts/AnySelectMenu.ts +0 -63
  220. package/src/abstracts/AnySelectMenuInteraction.ts +0 -29
  221. package/src/abstracts/Base.ts +0 -12
  222. package/src/abstracts/BaseChannel.ts +0 -73
  223. package/src/abstracts/BaseCommand.ts +0 -89
  224. package/src/abstracts/BaseComponent.ts +0 -49
  225. package/src/abstracts/BaseComponentInteraction.ts +0 -19
  226. package/src/abstracts/BaseGuildChannel.ts +0 -152
  227. package/src/abstracts/BaseGuildTextChannel.ts +0 -77
  228. package/src/abstracts/BaseInteraction.ts +0 -209
  229. package/src/abstracts/GuildThreadOnlyChannel.ts +0 -71
  230. package/src/classes/Button.ts +0 -95
  231. package/src/classes/ChannelSelectMenu.ts +0 -21
  232. package/src/classes/Client.ts +0 -277
  233. package/src/classes/Command.ts +0 -53
  234. package/src/classes/CommandWithSubcommandGroups.ts +0 -47
  235. package/src/classes/CommandWithSubcommands.ts +0 -35
  236. package/src/classes/MentionableSelectMenu.ts +0 -19
  237. package/src/classes/Modal.ts +0 -38
  238. package/src/classes/RoleSelectMenu.ts +0 -19
  239. package/src/classes/Row.ts +0 -50
  240. package/src/classes/StringSelectMenu.ts +0 -19
  241. package/src/classes/TextInput.ts +0 -65
  242. package/src/classes/UserSelectMenu.ts +0 -19
  243. package/src/factories/channelFactory.ts +0 -43
  244. package/src/index.ts +0 -62
  245. package/src/internals/AutocompleteInteraction.ts +0 -107
  246. package/src/internals/ButtonInteraction.ts +0 -26
  247. package/src/internals/ChannelSelectMenuInteraction.ts +0 -15
  248. package/src/internals/CommandHandler.ts +0 -127
  249. package/src/internals/CommandInteraction.ts +0 -49
  250. package/src/internals/ComponentHandler.ts +0 -92
  251. package/src/internals/MentionableSelectMenuInteraction.ts +0 -21
  252. package/src/internals/ModalHandler.ts +0 -27
  253. package/src/internals/ModalInteraction.ts +0 -25
  254. package/src/internals/OptionsHandler.ts +0 -148
  255. package/src/internals/RoleSelectMenuInteraction.ts +0 -20
  256. package/src/internals/StringSelectMenuInteraction.ts +0 -20
  257. package/src/internals/UserSelectMenuInteraction.ts +0 -20
  258. package/src/structures/DmChannel.ts +0 -31
  259. package/src/structures/GroupDmChannel.ts +0 -132
  260. package/src/structures/Guild.ts +0 -154
  261. package/src/structures/GuildAnnouncementChannel.ts +0 -20
  262. package/src/structures/GuildCategoryChannel.ts +0 -16
  263. package/src/structures/GuildForumChannel.ts +0 -20
  264. package/src/structures/GuildMediaChannel.ts +0 -13
  265. package/src/structures/GuildMember.ts +0 -231
  266. package/src/structures/GuildStageOrVoiceChannel.ts +0 -46
  267. package/src/structures/GuildTextChannel.ts +0 -21
  268. package/src/structures/GuildThreadChannel.ts +0 -150
  269. package/src/structures/Message.ts +0 -124
  270. package/src/structures/Role.ts +0 -201
  271. package/src/structures/User.ts +0 -153
  272. package/src/utils.ts +0 -13
  273. package/tests/index.test.ts +0 -4
  274. package/tsconfig.json +0 -12
  275. package/typedoc.json +0 -9
@@ -1,6 +1,6 @@
1
1
  import { type APIApplicationCommandInteractionDataBasicOption } from "discord-api-types/v10";
2
2
  import { Base } from "../abstracts/Base.js";
3
- import { type Client, Role, User } from "../index.js";
3
+ import { type Client, Role, User, channelFactory } from "../index.js";
4
4
  export type RawOptions = {
5
5
  [key: string]: APIApplicationCommandInteractionDataBasicOption["value"] | undefined;
6
6
  };
@@ -21,50 +21,66 @@ export declare class OptionsHandler extends Base {
21
21
  /**
22
22
  * Get the value of a string option.
23
23
  * @param key The name of the option to get the value of.
24
- * @returns The value of the option, or undefined if the option was not provided.
24
+ * @param required Whether the option is required.
25
+ * @returns The value of the option, or undefined if the option was not provided and it is not required.
25
26
  */
26
- getString(key: string): string | undefined;
27
+ getString(key: string, required?: false): string | undefined;
28
+ getString(key: string, required: true): string;
27
29
  /**
28
30
  * Get the value of an integer option.
29
31
  * @param key The name of the option to get the value of.
30
- * @returns The value of the option, or undefined if the option was not provided.
32
+ * @param required Whether the option is required.
33
+ * @returns The value of the option, or undefined if the option was not provided and it is not required.
31
34
  */
32
- getInteger(key: string): number | undefined;
35
+ getInteger(key: string, required?: false): number | undefined;
36
+ getInteger(key: string, required: true): number;
33
37
  /**
34
38
  * Get the value of a number option.
35
39
  * @param key The name of the option to get the value of.
36
- * @returns The value of the option, or undefined if the option was not provided.
40
+ * @param required Whether the option is required.
41
+ * @returns The value of the option, or undefined if the option was not provided and it is not required.
37
42
  */
38
- getNumber(key: string): number | undefined;
43
+ getNumber(key: string, required?: false): number | undefined;
44
+ getNumber(key: string, required: true): number;
39
45
  /**
40
46
  * Get the value of a boolean option.
41
47
  * @param key The name of the option to get the value of.
42
- * @returns The value of the option, or undefined if the option was not provided.
48
+ * @param required Whether the option is required.
49
+ * @returns The value of the option, or undefined if the option was not provided and it is not required.
43
50
  */
44
- getBoolean(key: string): true | undefined;
51
+ getBoolean(key: string, required?: false): boolean | undefined;
52
+ getBoolean(key: string, required: true): boolean;
45
53
  /**
46
54
  * Get the value of a user option.
47
55
  * @param key The name of the option to get the value of.
48
- * @returns The value of the option, or undefined if the option was not provided.
56
+ * @param required Whether the option is required.
57
+ * @returns The value of the option, or undefined if the option was not provided and it is not required.
49
58
  */
50
- getUser(key: string): User | undefined;
59
+ getUser(key: string, required?: false): User | undefined;
60
+ getUser(key: string, required: true): User;
51
61
  /**
52
62
  * Get the value of a channel option.
53
63
  * @param key The name of the option to get the value of.
54
- * @returns The value of the option, or undefined if the option was not provided.
64
+ * @param required Whether the option is required.
65
+ * @returns The value of the option, or undefined if the option was not provided and it is not required.
55
66
  */
56
- getChannel(key: string): Promise<import("../index.js").DmChannel | import("../index.js").GroupDmChannel | import("../index.js").GuildTextChannel | import("../index.js").GuildVoiceChannel | import("../index.js").GuildCategoryChannel | import("../index.js").GuildAnnouncementChannel | import("../index.js").GuildThreadChannel<import("discord-api-types/v10").ThreadChannelType> | import("../index.js").GuildStageChannel | import("../index.js").GuildForumChannel | import("../index.js").GuildMediaChannel | null | undefined>;
67
+ getChannel(key: string, required?: false): Promise<ReturnType<typeof channelFactory> | undefined>;
68
+ getChannel(key: string, required: true): Promise<ReturnType<typeof channelFactory>>;
57
69
  /**
58
70
  * Get the value of a role option.
59
71
  * @param key The name of the option to get the value of.
60
- * @returns The value of the option, or undefined if the option was not provided.
72
+ * @param required Whether the option is required.
73
+ * @returns The value of the option, or undefined if the option was not provided and it is not required.
61
74
  */
62
- getRole(key: string): Role | undefined;
75
+ getRole(key: string, required?: false): Role | undefined;
76
+ getRole(key: string, required: true): Role;
63
77
  /**
64
78
  * Get the value of a mentionable option.
65
79
  * @param key The name of the option to get the value of.
66
- * @returns The value of the option, or undefined if the option was not provided.
80
+ * @param required Whether the option is required.
81
+ * @returns The value of the option, or undefined if the option was not provided and it is not required.
67
82
  */
68
- getMentionable(key: string): Promise<User | Role | undefined>;
83
+ getMentionable(key: string, required?: false): Promise<User | Role | undefined>;
84
+ getMentionable(key: string, required: true): Promise<User | Role>;
69
85
  }
70
86
  //# sourceMappingURL=OptionsHandler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"OptionsHandler.d.ts","sourceRoot":"","sources":["../../../src/internals/OptionsHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,+CAA+C,EAIpD,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAA;AAC3C,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,IAAI,EAAkB,MAAM,aAAa,CAAA;AAErE,MAAM,MAAM,UAAU,GAAG;IACxB,CAAC,GAAG,EAAE,MAAM,GACT,+CAA+C,CAAC,OAAO,CAAC,GACxD,SAAS,CAAA;CACZ,CAAA;AAED;;;GAGG;AACH,qBAAa,cAAe,SAAQ,IAAI;IACvC;;OAEG;IACH,QAAQ,CAAC,GAAG,EAAE,+CAA+C,EAAE,CAAA;IAC/D;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAK;gBAGlC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,+CAA+C,EAAE;IAM3D;;;;OAIG;IACI,SAAS,CAAC,GAAG,EAAE,MAAM;IAQ5B;;;;OAIG;IACI,UAAU,CAAC,GAAG,EAAE,MAAM;IAS7B;;;;OAIG;IACI,SAAS,CAAC,GAAG,EAAE,MAAM;IAQ5B;;;;OAIG;IACI,UAAU,CAAC,GAAG,EAAE,MAAM;IAQ7B;;;;OAIG;IACI,OAAO,CAAC,GAAG,EAAE,MAAM;IAQ1B;;;;OAIG;IACU,UAAU,CAAC,GAAG,EAAE,MAAM;IASnC;;;;OAIG;IACI,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;IAQ7C;;;;OAIG;IACU,cAAc,CAAC,GAAG,EAAE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,EAAE,QAAQ,EAAE,IAAI,GAAG,MAAM;IAYrD;;;;;OAKG;IACI,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,KAAK,GAAG,OAAO,GAAG,SAAS;IAC9D,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,GAAG,OAAO;IAYvD;;;;;OAKG;IACI,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,KAAK,GAAG,IAAI,GAAG,SAAS;IACxD,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,GAAG,IAAI;IAYjD;;;;;OAKG;IACU,UAAU,CACtB,GAAG,EAAE,MAAM,EACX,QAAQ,CAAC,EAAE,KAAK,GACd,OAAO,CAAC,UAAU,CAAC,OAAO,cAAc,CAAC,GAAG,SAAS,CAAC;IAC5C,UAAU,CACtB,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,IAAI,GACZ,OAAO,CAAC,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;IAgB7C;;;;;OAKG;IACI,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,KAAK,GAAG,IAAI,GAAG,SAAS;IACxD,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,GAAG,IAAI;IAYjD;;;;;OAKG;IACU,cAAc,CAC1B,GAAG,EAAE,MAAM,EACX,QAAQ,CAAC,EAAE,KAAK,GACd,OAAO,CAAC,IAAI,GAAG,IAAI,GAAG,SAAS,CAAC;IACtB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;CAmB9E"}
@@ -18,92 +18,86 @@ export class OptionsHandler extends Base {
18
18
  super(client);
19
19
  this.raw = options;
20
20
  }
21
- /**
22
- * Get the value of a string option.
23
- * @param key The name of the option to get the value of.
24
- * @returns The value of the option, or undefined if the option was not provided.
25
- */
26
- getString(key) {
21
+ getString(key, required = false) {
27
22
  const value = this.raw.find((x) => x.name === key && x.type === ApplicationCommandOptionType.String)?.value;
28
- if (!value || typeof value !== "string")
23
+ if (required) {
24
+ if (!value || typeof value !== "string")
25
+ throw new Error(`Missing required option: ${key}`);
26
+ }
27
+ else if (!value || typeof value !== "string")
29
28
  return undefined;
30
29
  return value;
31
30
  }
32
- /**
33
- * Get the value of an integer option.
34
- * @param key The name of the option to get the value of.
35
- * @returns The value of the option, or undefined if the option was not provided.
36
- */
37
- getInteger(key) {
38
- const num = this.raw.find((x) => x.name === key && x.type === ApplicationCommandOptionType.Integer)?.value;
39
- if (!num || typeof num !== "number" || !Number.isSafeInteger(num))
31
+ getInteger(key, required = false) {
32
+ const value = this.raw.find((x) => x.name === key && x.type === ApplicationCommandOptionType.Integer)?.value;
33
+ if (required) {
34
+ if (!value || typeof value !== "number" || !Number.isSafeInteger(value))
35
+ throw new Error(`Missing required option: ${key}`);
36
+ }
37
+ else if (!value ||
38
+ typeof value !== "number" ||
39
+ !Number.isSafeInteger(value))
40
40
  return undefined;
41
- return num;
41
+ return value;
42
42
  }
43
- /**
44
- * Get the value of a number option.
45
- * @param key The name of the option to get the value of.
46
- * @returns The value of the option, or undefined if the option was not provided.
47
- */
48
- getNumber(key) {
43
+ getNumber(key, required = false) {
49
44
  const value = this.raw.find((x) => x.name === key && x.type === ApplicationCommandOptionType.Number)?.value;
50
- if (!value || typeof value !== "number")
45
+ if (required) {
46
+ if (!value || typeof value !== "number")
47
+ throw new Error(`Missing required option: ${key}`);
48
+ }
49
+ else if (!value || typeof value !== "number")
51
50
  return undefined;
52
51
  return value;
53
52
  }
54
- /**
55
- * Get the value of a boolean option.
56
- * @param key The name of the option to get the value of.
57
- * @returns The value of the option, or undefined if the option was not provided.
58
- */
59
- getBoolean(key) {
53
+ getBoolean(key, required = false) {
60
54
  const value = this.raw.find((x) => x.name === key && x.type === ApplicationCommandOptionType.Boolean)?.value;
61
- if (!value || typeof value !== "boolean")
55
+ if (required) {
56
+ if (!value || typeof value !== "boolean")
57
+ throw new Error(`Missing required option: ${key}`);
58
+ }
59
+ else if (!value || typeof value !== "boolean")
62
60
  return undefined;
63
61
  return value;
64
62
  }
65
- /**
66
- * Get the value of a user option.
67
- * @param key The name of the option to get the value of.
68
- * @returns The value of the option, or undefined if the option was not provided.
69
- */
70
- getUser(key) {
63
+ getUser(key, required = false) {
71
64
  const id = this.raw.find((x) => x.name === key && x.type === ApplicationCommandOptionType.User)?.value;
72
- if (!id || typeof id !== "string")
65
+ if (required) {
66
+ if (!id || typeof id !== "string")
67
+ throw new Error(`Missing required option: ${key}`);
68
+ }
69
+ else if (!id || typeof id !== "string")
73
70
  return undefined;
74
71
  return new User(this.client, id);
75
72
  }
76
- /**
77
- * Get the value of a channel option.
78
- * @param key The name of the option to get the value of.
79
- * @returns The value of the option, or undefined if the option was not provided.
80
- */
81
- async getChannel(key) {
73
+ async getChannel(key, required = false) {
82
74
  const id = this.raw.find((x) => x.name === key && x.type === ApplicationCommandOptionType.Channel)?.value;
83
- if (!id || typeof id !== "string")
75
+ if (required) {
76
+ if (!id || typeof id !== "string")
77
+ throw new Error(`Missing required option: ${key}`);
78
+ }
79
+ else if (!id || typeof id !== "string")
84
80
  return undefined;
85
81
  const data = (await this.client.rest.get(Routes.channel(id)));
86
82
  return channelFactory(this.client, data);
87
83
  }
88
- /**
89
- * Get the value of a role option.
90
- * @param key The name of the option to get the value of.
91
- * @returns The value of the option, or undefined if the option was not provided.
92
- */
93
- getRole(key) {
84
+ getRole(key, required = false) {
94
85
  const id = this.raw.find((x) => x.name === key && x.type === ApplicationCommandOptionType.Role)?.value;
95
- if (!id || typeof id !== "string")
86
+ if (required) {
87
+ if (!id || typeof id !== "string")
88
+ throw new Error(`Missing required option: ${key}`);
89
+ }
90
+ else if (!id || typeof id !== "string")
96
91
  return undefined;
97
92
  return new Role(this.client, id);
98
93
  }
99
- /**
100
- * Get the value of a mentionable option.
101
- * @param key The name of the option to get the value of.
102
- * @returns The value of the option, or undefined if the option was not provided.
103
- */
104
- async getMentionable(key) {
94
+ async getMentionable(key, required = false) {
105
95
  const id = this.raw.find((x) => x.name === key && x.type === ApplicationCommandOptionType.Mentionable)?.value;
106
- if (!id || typeof id !== "string")
96
+ if (required) {
97
+ if (!id || typeof id !== "string")
98
+ throw new Error(`Missing required option: ${key}`);
99
+ }
100
+ else if (!id || typeof id !== "string")
107
101
  return undefined;
108
102
  const user = new User(this.client, id);
109
103
  await user.fetch().catch(() => {
@@ -1 +1 @@
1
- {"version":3,"file":"OptionsHandler.js","sourceRoot":"","sources":["../../../src/internals/OptionsHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,4BAA4B,EAC5B,MAAM,EACN,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAA;AAC3C,OAAO,EAAe,IAAI,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAQrE;;;GAGG;AACH,MAAM,OAAO,cAAe,SAAQ,IAAI;IACvC;;OAEG;IACM,GAAG,CAAmD;IAC/D;;OAEG;IACM,MAAM,GAAkB,EAAE,CAAA;IAEnC,YACC,MAAc,EACd,OAA0D;QAE1D,KAAK,CAAC,MAAM,CAAC,CAAA;QACb,IAAI,CAAC,GAAG,GAAG,OAAO,CAAA;IACnB,CAAC;IAED;;;;OAIG;IACI,SAAS,CAAC,GAAW;QAC3B,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAC1B,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,GAAG,IAAI,CAAC,CAAC,IAAI,KAAK,4BAA4B,CAAC,MAAM,CACvE,EAAE,KAAK,CAAA;QACR,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;YAAE,OAAO,SAAS,CAAA;QACzD,OAAO,KAAK,CAAA;IACb,CAAC;IAED;;;;O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AAA;QACpD,CAAC;aAAM,IAAI,CAAC,EAAE,IAAI,OAAO,EAAE,KAAK,QAAQ;YAAE,OAAO,SAAS,CAAA;QAC1D,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;IACjC,CAAC;IAaM,KAAK,CAAC,cAAc,CAC1B,GAAW,EACX,QAAQ,GAAG,KAAK;QAEhB,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CACvB,CAAC,CAAC,EAAE,EAAE,CACL,CAAC,CAAC,IAAI,KAAK,GAAG,IAAI,CAAC,CAAC,IAAI,KAAK,4BAA4B,CAAC,WAAW,CACtE,EAAE,KAAK,CAAA;QACR,IAAI,QAAQ,EAAE,CAAC;YACd,IAAI,CAAC,EAAE,IAAI,OAAO,EAAE,KAAK,QAAQ;gBAChC,MAAM,IAAI,KAAK,CAAC,4BAA4B,GAAG,EAAE,CAAC,CAAA;QACpD,CAAC;aAAM,IAAI,CAAC,EAAE,IAAI,OAAO,EAAE,KAAK,QAAQ;YAAE,OAAO,SAAS,CAAA;QAC1D,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;QACtC,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE;YAC7B,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;QACjC,CAAC,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACZ,CAAC;CACD"}
@@ -1,2 +1,5 @@
1
1
  export declare const splitCustomId: (customId: string) => [string, Record<string, string>];
2
+ export declare const subtleCrypto: SubtleCrypto;
3
+ export declare function valueToUint8Array(value: Uint8Array | ArrayBuffer | Buffer | string, format?: string): Uint8Array;
4
+ export declare function concatUint8Arrays(arr1: Uint8Array, arr2: Uint8Array): Uint8Array;
2
5
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,aACf,MAAM,KACd,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAUjC,CAAA"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,aACf,MAAM,KACd,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAUjC,CAAA;AAsBD,eAAO,MAAM,YAAY,cAAoB,CAAA;AAE7C,wBAAgB,iBAAiB,CAChC,KAAK,EAAE,UAAU,GAAG,WAAW,GAAG,MAAM,GAAG,MAAM,EACjD,MAAM,CAAC,EAAE,MAAM,GACb,UAAU,CA8BZ;AAED,wBAAgB,iBAAiB,CAChC,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,UAAU,GACd,UAAU,CAKZ"}
package/dist/src/utils.js CHANGED
@@ -8,4 +8,58 @@ export const splitCustomId = (customId) => {
8
8
  }));
9
9
  return [id, data];
10
10
  };
11
+ // Used from https://github.com/discord/discord-interactions-js
12
+ function getSubtleCrypto() {
13
+ if (typeof window !== "undefined" && window.crypto) {
14
+ return window.crypto.subtle;
15
+ }
16
+ if (typeof globalThis !== "undefined" && globalThis.crypto) {
17
+ return globalThis.crypto.subtle;
18
+ }
19
+ if (typeof crypto !== "undefined") {
20
+ return crypto.subtle;
21
+ }
22
+ if (typeof require === "function") {
23
+ const cryptoPackage = "node:crypto";
24
+ const crypto = require(cryptoPackage);
25
+ return crypto.webcrypto.subtle;
26
+ }
27
+ throw new Error("No Web Crypto API implementation found");
28
+ }
29
+ export const subtleCrypto = getSubtleCrypto();
30
+ export function valueToUint8Array(value, format) {
31
+ if (value == null) {
32
+ return new Uint8Array();
33
+ }
34
+ if (typeof value === "string") {
35
+ if (format === "hex") {
36
+ const matches = value.match(/.{1,2}/g);
37
+ if (matches == null) {
38
+ throw new Error("Value is not a valid hex string");
39
+ }
40
+ const hexVal = matches.map((byte) => Number.parseInt(byte, 16));
41
+ return new Uint8Array(hexVal);
42
+ }
43
+ return new TextEncoder().encode(value);
44
+ }
45
+ try {
46
+ if (Buffer.isBuffer(value)) {
47
+ return new Uint8Array(value);
48
+ }
49
+ }
50
+ catch (_) { }
51
+ if (value instanceof ArrayBuffer) {
52
+ return new Uint8Array(value);
53
+ }
54
+ if (value instanceof Uint8Array) {
55
+ return value;
56
+ }
57
+ throw new Error("Unrecognized value type, must be one of: string, Buffer, ArrayBuffer, Uint8Array");
58
+ }
59
+ export function concatUint8Arrays(arr1, arr2) {
60
+ const merged = new Uint8Array(arr1.length + arr2.length);
61
+ merged.set(arr1);
62
+ merged.set(arr2, arr1.length);
63
+ return merged;
64
+ }
11
65
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG,CAC5B,QAAgB,EACmB,EAAE;IACrC,MAAM,CAAC,EAAE,EAAE,GAAG,IAAI,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IACzC,IAAI,CAAC,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAA;IAC1D,MAAM,IAAI,GAAG,MAAM,CAAC,WAAW,CAC9B,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;QAChB,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QACnC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;IACpB,CAAC,CAAC,CACF,CAAA;IACD,OAAO,CAAC,EAAE,EAAE,IAAI,CAAC,CAAA;AAClB,CAAC,CAAA"}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.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