chapterjs 0.1.1 → 0.1.4

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 (320) hide show
  1. package/dist/assets/asset.d.ts +46 -0
  2. package/dist/assets/asset.js +86 -0
  3. package/dist/assets/public.d.ts +19 -0
  4. package/dist/assets/public.js +120 -0
  5. package/dist/cache/cache.d.ts +62 -0
  6. package/dist/cache/cache.js +80 -0
  7. package/dist/cache/store.d.ts +45 -0
  8. package/dist/cache/store.js +53 -0
  9. package/dist/cli/build.d.ts +41 -0
  10. package/dist/cli/build.js +206 -0
  11. package/dist/cli/cli.js +108 -25
  12. package/dist/cli/cluster.d.ts +70 -0
  13. package/dist/cli/cluster.js +213 -0
  14. package/dist/cli/dev.d.ts +18 -1
  15. package/dist/cli/dev.js +252 -198
  16. package/dist/cli/env.d.ts +31 -0
  17. package/dist/cli/env.js +93 -0
  18. package/dist/cli/log.d.ts +13 -0
  19. package/dist/cli/log.js +17 -0
  20. package/dist/cli/node-version.d.ts +8 -0
  21. package/dist/cli/node-version.js +13 -0
  22. package/dist/cli/preflight.d.ts +36 -0
  23. package/dist/cli/preflight.js +122 -0
  24. package/dist/cli/project.d.ts +122 -0
  25. package/dist/cli/project.js +452 -0
  26. package/dist/cli/start.d.ts +25 -0
  27. package/dist/cli/start.js +225 -0
  28. package/dist/commands/autocomplete.d.ts +13 -0
  29. package/dist/commands/autocomplete.js +159 -0
  30. package/dist/commands/command.d.ts +346 -0
  31. package/dist/commands/command.js +28 -0
  32. package/dist/commands/convention.d.ts +64 -0
  33. package/dist/commands/convention.js +464 -0
  34. package/dist/commands/register.d.ts +18 -0
  35. package/dist/commands/register.js +42 -0
  36. package/dist/commands/router.d.ts +20 -0
  37. package/dist/commands/router.js +228 -0
  38. package/dist/commands/tree.d.ts +43 -0
  39. package/dist/commands/tree.js +206 -0
  40. package/dist/commands/twins.d.ts +15 -0
  41. package/dist/commands/twins.js +78 -0
  42. package/dist/components/button.d.ts +79 -0
  43. package/dist/components/button.js +108 -0
  44. package/dist/components/component.d.ts +140 -0
  45. package/dist/components/component.js +39 -0
  46. package/dist/components/convention.d.ts +35 -0
  47. package/dist/components/convention.js +339 -0
  48. package/dist/components/custom-id.d.ts +72 -0
  49. package/dist/components/custom-id.js +128 -0
  50. package/dist/components/embed.d.ts +28 -0
  51. package/dist/components/embed.js +11 -0
  52. package/dist/components/file.d.ts +30 -0
  53. package/dist/components/file.js +52 -0
  54. package/dist/components/instance.d.ts +100 -0
  55. package/dist/components/instance.js +86 -0
  56. package/dist/components/layout.d.ts +103 -0
  57. package/dist/components/layout.js +279 -0
  58. package/dist/components/modal.d.ts +244 -0
  59. package/dist/components/modal.js +399 -0
  60. package/dist/components/options.d.ts +41 -0
  61. package/dist/components/options.js +101 -0
  62. package/dist/components/render.d.ts +12 -0
  63. package/dist/components/render.js +58 -0
  64. package/dist/components/router.d.ts +18 -0
  65. package/dist/components/router.js +256 -0
  66. package/dist/components/select.d.ts +144 -0
  67. package/dist/components/select.js +179 -0
  68. package/dist/core/bot.d.ts +99 -0
  69. package/dist/core/bot.js +174 -0
  70. package/dist/core/memory.d.ts +66 -0
  71. package/dist/core/memory.js +115 -0
  72. package/dist/discord/api.d.ts +112 -0
  73. package/dist/discord/api.js +115 -0
  74. package/dist/discord/cdn.d.ts +67 -0
  75. package/dist/discord/cdn.js +100 -0
  76. package/dist/discord/codes.d.ts +171 -0
  77. package/dist/discord/codes.js +421 -0
  78. package/dist/discord/endpoint.d.ts +56 -0
  79. package/dist/discord/endpoint.js +53 -0
  80. package/dist/discord/endpoints.d.ts +1529 -0
  81. package/dist/discord/endpoints.js +1139 -0
  82. package/dist/discord/formatting.d.ts +67 -0
  83. package/dist/discord/formatting.js +87 -0
  84. package/dist/discord/index.d.ts +10 -0
  85. package/dist/discord/index.js +13 -0
  86. package/dist/discord/intents.d.ts +48 -0
  87. package/dist/discord/intents.js +128 -0
  88. package/dist/discord/permissions.d.ts +94 -0
  89. package/dist/discord/permissions.js +185 -0
  90. package/dist/discord/snowflake.d.ts +21 -0
  91. package/dist/discord/snowflake.js +36 -0
  92. package/dist/discord/types/application-command.d.ts +332 -0
  93. package/dist/discord/types/application-command.js +48 -0
  94. package/dist/discord/types/application-role-connection-metadata.d.ts +42 -0
  95. package/dist/discord/types/application-role-connection-metadata.js +22 -0
  96. package/dist/discord/types/application.d.ts +208 -0
  97. package/dist/discord/types/application.js +48 -0
  98. package/dist/discord/types/audit-log.d.ts +255 -0
  99. package/dist/discord/types/audit-log.js +144 -0
  100. package/dist/discord/types/auto-moderation.d.ts +167 -0
  101. package/dist/discord/types/auto-moderation.js +52 -0
  102. package/dist/discord/types/channel.d.ts +557 -0
  103. package/dist/discord/types/channel.js +88 -0
  104. package/dist/discord/types/common.d.ts +54 -0
  105. package/dist/discord/types/common.js +38 -0
  106. package/dist/discord/types/component.d.ts +775 -0
  107. package/dist/discord/types/component.js +76 -0
  108. package/dist/discord/types/emoji.d.ts +74 -0
  109. package/dist/discord/types/emoji.js +1 -0
  110. package/dist/discord/types/entitlement.d.ts +84 -0
  111. package/dist/discord/types/entitlement.js +22 -0
  112. package/dist/discord/types/gateway-events.d.ts +1148 -0
  113. package/dist/discord/types/gateway-events.js +54 -0
  114. package/dist/discord/types/gateway.d.ts +38 -0
  115. package/dist/discord/types/gateway.js +1 -0
  116. package/dist/discord/types/guild-scheduled-event.d.ts +257 -0
  117. package/dist/discord/types/guild-scheduled-event.js +68 -0
  118. package/dist/discord/types/guild-template.d.ts +51 -0
  119. package/dist/discord/types/guild-template.js +1 -0
  120. package/dist/discord/types/guild.d.ts +910 -0
  121. package/dist/discord/types/guild.js +153 -0
  122. package/dist/discord/types/index.d.ts +31 -0
  123. package/dist/discord/types/index.js +31 -0
  124. package/dist/discord/types/interaction.d.ts +321 -0
  125. package/dist/discord/types/interaction.js +47 -0
  126. package/dist/discord/types/invite.d.ts +158 -0
  127. package/dist/discord/types/invite.js +39 -0
  128. package/dist/discord/types/message.d.ts +834 -0
  129. package/dist/discord/types/message.js +159 -0
  130. package/dist/discord/types/oauth2.d.ts +22 -0
  131. package/dist/discord/types/oauth2.js +1 -0
  132. package/dist/discord/types/permissions.d.ts +183 -0
  133. package/dist/discord/types/permissions.js +118 -0
  134. package/dist/discord/types/poll.d.ts +106 -0
  135. package/dist/discord/types/poll.js +8 -0
  136. package/dist/discord/types/sku.d.ts +47 -0
  137. package/dist/discord/types/sku.js +26 -0
  138. package/dist/discord/types/soundboard.d.ts +71 -0
  139. package/dist/discord/types/soundboard.js +1 -0
  140. package/dist/discord/types/stage-instance.d.ts +58 -0
  141. package/dist/discord/types/stage-instance.js +10 -0
  142. package/dist/discord/types/sticker.d.ts +115 -0
  143. package/dist/discord/types/sticker.js +20 -0
  144. package/dist/discord/types/subscription.d.ts +54 -0
  145. package/dist/discord/types/subscription.js +12 -0
  146. package/dist/discord/types/team.d.ts +55 -0
  147. package/dist/discord/types/team.js +21 -0
  148. package/dist/discord/types/user.d.ts +273 -0
  149. package/dist/discord/types/user.js +83 -0
  150. package/dist/discord/types/voice.d.ts +72 -0
  151. package/dist/discord/types/voice.js +1 -0
  152. package/dist/discord/types/webhook.d.ts +184 -0
  153. package/dist/discord/types/webhook.js +12 -0
  154. package/dist/events/convention.d.ts +25 -0
  155. package/dist/events/convention.js +97 -0
  156. package/dist/events/event.d.ts +8 -0
  157. package/dist/events/event.js +20 -0
  158. package/dist/events/registry.d.ts +706 -0
  159. package/dist/events/registry.js +839 -0
  160. package/dist/events/router.d.ts +45 -0
  161. package/dist/events/router.js +133 -0
  162. package/dist/events/types.d.ts +7 -0
  163. package/dist/events/types.js +48 -0
  164. package/dist/gateway/errors.d.ts +18 -0
  165. package/dist/gateway/errors.js +47 -0
  166. package/dist/gateway/gateway.d.ts +64 -0
  167. package/dist/gateway/gateway.js +117 -0
  168. package/dist/gateway/identify-queue.d.ts +25 -0
  169. package/dist/gateway/identify-queue.js +29 -0
  170. package/dist/gateway/shard.d.ts +94 -0
  171. package/dist/gateway/shard.js +414 -0
  172. package/dist/gateway/state.d.ts +11 -0
  173. package/dist/gateway/state.js +184 -0
  174. package/dist/index.d.ts +55 -18
  175. package/dist/index.js +38 -12
  176. package/dist/interactions/cooldown.d.ts +33 -0
  177. package/dist/interactions/cooldown.js +74 -0
  178. package/dist/interactions/dispatch.d.ts +91 -0
  179. package/dist/interactions/dispatch.js +110 -0
  180. package/dist/loader/generated.d.ts +37 -0
  181. package/dist/loader/generated.js +114 -0
  182. package/dist/loader/hot.d.ts +13 -0
  183. package/dist/loader/hot.js +85 -0
  184. package/dist/loader/loader.d.ts +72 -0
  185. package/dist/loader/loader.js +135 -0
  186. package/dist/loader/locate.d.ts +10 -0
  187. package/dist/loader/locate.js +36 -0
  188. package/dist/loader/watch.d.ts +17 -0
  189. package/dist/loader/watch.js +66 -0
  190. package/dist/main.d.ts +3 -0
  191. package/dist/main.js +6 -0
  192. package/dist/messages/commands.d.ts +23 -0
  193. package/dist/messages/commands.js +123 -0
  194. package/dist/messages/convention.d.ts +89 -0
  195. package/dist/messages/convention.js +347 -0
  196. package/dist/messages/messages.d.ts +219 -0
  197. package/dist/messages/messages.js +30 -0
  198. package/dist/messages/phrases.d.ts +23 -0
  199. package/dist/messages/phrases.js +44 -0
  200. package/dist/messages/translate.d.ts +100 -0
  201. package/dist/messages/translate.js +249 -0
  202. package/dist/presence/convention.d.ts +26 -0
  203. package/dist/presence/convention.js +133 -0
  204. package/dist/presence/presence.d.ts +57 -0
  205. package/dist/presence/presence.js +27 -0
  206. package/dist/rest/errors.d.ts +55 -0
  207. package/dist/rest/errors.js +92 -0
  208. package/dist/rest/rate-limiter.d.ts +46 -0
  209. package/dist/rest/rate-limiter.js +153 -0
  210. package/dist/rest/rest.d.ts +63 -0
  211. package/dist/rest/rest.js +194 -0
  212. package/dist/structures/base.d.ts +48 -0
  213. package/dist/structures/base.js +84 -0
  214. package/dist/structures/channel.d.ts +380 -0
  215. package/dist/structures/channel.js +627 -0
  216. package/dist/structures/context.d.ts +30 -0
  217. package/dist/structures/context.js +7 -0
  218. package/dist/structures/emoji.d.ts +46 -0
  219. package/dist/structures/emoji.js +65 -0
  220. package/dist/structures/entities.d.ts +62 -0
  221. package/dist/structures/entities.js +226 -0
  222. package/dist/structures/guild.d.ts +348 -0
  223. package/dist/structures/guild.js +466 -0
  224. package/dist/structures/interaction.d.ts +197 -0
  225. package/dist/structures/interaction.js +396 -0
  226. package/dist/structures/invite.d.ts +38 -0
  227. package/dist/structures/invite.js +57 -0
  228. package/dist/structures/known.d.ts +28 -0
  229. package/dist/structures/known.js +58 -0
  230. package/dist/structures/member.d.ts +140 -0
  231. package/dist/structures/member.js +260 -0
  232. package/dist/structures/message.d.ts +197 -0
  233. package/dist/structures/message.js +268 -0
  234. package/dist/structures/payload.d.ts +91 -0
  235. package/dist/structures/payload.js +184 -0
  236. package/dist/structures/role.d.ts +69 -0
  237. package/dist/structures/role.js +112 -0
  238. package/dist/structures/user.d.ts +59 -0
  239. package/dist/structures/user.js +94 -0
  240. package/dist/structures/webhook.d.ts +46 -0
  241. package/dist/structures/webhook.js +79 -0
  242. package/dist/tasks/convention.d.ts +26 -0
  243. package/dist/tasks/convention.js +78 -0
  244. package/dist/tasks/schedule.d.ts +54 -0
  245. package/dist/tasks/schedule.js +236 -0
  246. package/dist/tasks/scheduler.d.ts +33 -0
  247. package/dist/tasks/scheduler.js +107 -0
  248. package/dist/tasks/task.d.ts +76 -0
  249. package/dist/tasks/task.js +28 -0
  250. package/dist/util/case.d.ts +13 -0
  251. package/dist/util/case.js +54 -0
  252. package/dist/util/duration.d.ts +8 -0
  253. package/dist/util/duration.js +29 -0
  254. package/dist/util/websocket.d.ts +9 -0
  255. package/dist/util/websocket.js +31 -0
  256. package/dist/voice/connection.d.ts +90 -0
  257. package/dist/voice/connection.js +494 -0
  258. package/dist/voice/dave.d.ts +109 -0
  259. package/dist/voice/dave.js +245 -0
  260. package/dist/voice/opus.d.ts +19 -0
  261. package/dist/voice/opus.js +273 -0
  262. package/dist/voice/session.d.ts +55 -0
  263. package/dist/voice/session.js +405 -0
  264. package/dist/voice/source.d.ts +22 -0
  265. package/dist/voice/source.js +195 -0
  266. package/dist/voice/transport.d.ts +43 -0
  267. package/dist/voice/transport.js +140 -0
  268. package/dist/voice/usage.d.ts +4 -0
  269. package/dist/voice/usage.js +33 -0
  270. package/package.json +26 -7
  271. package/vendor/dave/LICENSE +231 -0
  272. package/vendor/dave/libdave.d.mts +99 -0
  273. package/vendor/dave/libdave.mjs +2 -0
  274. package/vendor/dave/libdave.wasm +0 -0
  275. package/dist/components.d.ts +0 -97
  276. package/dist/components.js +0 -260
  277. package/dist/context.d.ts +0 -72
  278. package/dist/context.js +0 -273
  279. package/dist/discord/client.d.ts +0 -35
  280. package/dist/discord/client.js +0 -66
  281. package/dist/discord/constants.d.ts +0 -49
  282. package/dist/discord/constants.js +0 -61
  283. package/dist/discord/events.d.ts +0 -129
  284. package/dist/discord/events.js +0 -102
  285. package/dist/discord/gateway.d.ts +0 -61
  286. package/dist/discord/gateway.js +0 -320
  287. package/dist/discord/payloads.d.ts +0 -275
  288. package/dist/discord/payloads.js +0 -3
  289. package/dist/discord/presence.d.ts +0 -42
  290. package/dist/discord/presence.js +0 -51
  291. package/dist/discord/rest.d.ts +0 -49
  292. package/dist/discord/rest.js +0 -271
  293. package/dist/discord/types.d.ts +0 -334
  294. package/dist/discord/types.js +0 -4
  295. package/dist/events.d.ts +0 -94
  296. package/dist/events.js +0 -255
  297. package/dist/presence.d.ts +0 -92
  298. package/dist/presence.js +0 -250
  299. package/dist/structures/Channel.d.ts +0 -110
  300. package/dist/structures/Channel.js +0 -171
  301. package/dist/structures/Guild.d.ts +0 -70
  302. package/dist/structures/Guild.js +0 -105
  303. package/dist/structures/Interaction.d.ts +0 -113
  304. package/dist/structures/Interaction.js +0 -274
  305. package/dist/structures/Member.d.ts +0 -70
  306. package/dist/structures/Member.js +0 -124
  307. package/dist/structures/Message.d.ts +0 -87
  308. package/dist/structures/Message.js +0 -182
  309. package/dist/structures/Reaction.d.ts +0 -38
  310. package/dist/structures/Reaction.js +0 -64
  311. package/dist/structures/Role.d.ts +0 -43
  312. package/dist/structures/Role.js +0 -77
  313. package/dist/structures/User.d.ts +0 -41
  314. package/dist/structures/User.js +0 -79
  315. package/dist/structures/utils.d.ts +0 -72
  316. package/dist/structures/utils.js +0 -59
  317. package/dist/utils/errors.d.ts +0 -5
  318. package/dist/utils/errors.js +0 -28
  319. package/dist/utils/modules.d.ts +0 -39
  320. package/dist/utils/modules.js +0 -156
@@ -1,275 +0,0 @@
1
- /** https://docs.discord.com/developers/resources/user#user-object */
2
- export interface User {
3
- id: string;
4
- username: string;
5
- discriminator: string;
6
- global_name: string | null;
7
- avatar: string | null;
8
- bot?: boolean;
9
- system?: boolean;
10
- }
11
- /** https://docs.discord.com/developers/resources/guild#guild-member-object */
12
- export interface GuildMember {
13
- user?: User;
14
- nick?: string | null;
15
- avatar?: string | null;
16
- roles: string[];
17
- joined_at: string | null;
18
- premium_since?: string | null;
19
- deaf?: boolean;
20
- mute?: boolean;
21
- pending?: boolean;
22
- permissions?: string;
23
- communication_disabled_until?: string | null;
24
- }
25
- /** https://docs.discord.com/developers/resources/emoji#emoji-object */
26
- export interface Emoji {
27
- id: string | null;
28
- name: string | null;
29
- animated?: boolean;
30
- }
31
- /** https://docs.discord.com/developers/topics/permissions#role-object */
32
- export interface Role {
33
- id: string;
34
- name: string;
35
- color: number;
36
- hoist: boolean;
37
- position: number;
38
- permissions: string;
39
- managed: boolean;
40
- mentionable: boolean;
41
- }
42
- /** https://docs.discord.com/developers/resources/channel#channel-object */
43
- export interface Channel {
44
- id: string;
45
- type: number;
46
- guild_id?: string;
47
- name?: string | null;
48
- topic?: string | null;
49
- position?: number;
50
- parent_id?: string | null;
51
- nsfw?: boolean;
52
- [key: string]: any;
53
- }
54
- /** https://docs.discord.com/developers/resources/message#attachment-object */
55
- export interface Attachment {
56
- id: string;
57
- filename: string;
58
- size: number;
59
- url: string;
60
- proxy_url: string;
61
- content_type?: string;
62
- width?: number | null;
63
- height?: number | null;
64
- }
65
- /** https://docs.discord.com/developers/resources/message#message-object */
66
- export interface Message {
67
- id: string;
68
- channel_id: string;
69
- author: User;
70
- content: string;
71
- timestamp: string;
72
- edited_timestamp: string | null;
73
- tts: boolean;
74
- mention_everyone: boolean;
75
- mentions: (User & {
76
- member?: Omit<GuildMember, 'user'>;
77
- })[];
78
- mention_roles: string[];
79
- attachments: Attachment[];
80
- embeds: Record<string, any>[];
81
- pinned: boolean;
82
- type: number;
83
- webhook_id?: string;
84
- flags?: number;
85
- message_reference?: {
86
- message_id?: string;
87
- channel_id?: string;
88
- guild_id?: string;
89
- };
90
- referenced_message?: Message | null;
91
- [key: string]: any;
92
- }
93
- /** https://docs.discord.com/developers/events/gateway-events#message-create */
94
- export interface MessageCreateEvent extends Message {
95
- /** Missing in DMs. */
96
- guild_id?: string;
97
- /** Author's member, in guilds. */
98
- member?: Omit<GuildMember, 'user'>;
99
- }
100
- /** https://docs.discord.com/developers/events/gateway-events#message-delete */
101
- export interface MessageDeleteEvent {
102
- id: string;
103
- channel_id: string;
104
- guild_id?: string;
105
- }
106
- /** https://docs.discord.com/developers/events/gateway-events#message-delete-bulk */
107
- export interface MessageDeleteBulkEvent {
108
- ids: string[];
109
- channel_id: string;
110
- guild_id?: string;
111
- }
112
- /** https://docs.discord.com/developers/events/gateway-events#message-reaction-add */
113
- export interface MessageReactionAddEvent {
114
- user_id: string;
115
- channel_id: string;
116
- message_id: string;
117
- guild_id?: string;
118
- member?: GuildMember;
119
- emoji: Emoji;
120
- message_author_id?: string;
121
- burst: boolean;
122
- type: number;
123
- }
124
- /** https://docs.discord.com/developers/events/gateway-events#message-reaction-remove */
125
- export type MessageReactionRemoveEvent = Omit<MessageReactionAddEvent, 'member' | 'message_author_id'>;
126
- /** https://docs.discord.com/developers/events/gateway-events#ready */
127
- export interface ReadyEvent {
128
- v: number;
129
- user: User;
130
- /** Unavailable guilds, filled in by the GUILD_CREATE events that follow. */
131
- guilds: {
132
- id: string;
133
- unavailable?: boolean;
134
- }[];
135
- session_id: string;
136
- resume_gateway_url: string;
137
- shard?: [number, number];
138
- application: {
139
- id: string;
140
- flags: number;
141
- };
142
- }
143
- /** https://docs.discord.com/developers/events/gateway-events#guild-create */
144
- export interface GuildCreateEvent {
145
- id: string;
146
- name: string;
147
- icon: string | null;
148
- owner_id: string;
149
- joined_at: string;
150
- member_count: number;
151
- unavailable?: boolean;
152
- roles: Role[];
153
- emojis: Emoji[];
154
- members: GuildMember[];
155
- channels: Channel[];
156
- threads: Channel[];
157
- [key: string]: any;
158
- }
159
- /** https://docs.discord.com/developers/events/gateway-events#guild-delete */
160
- export interface GuildDeleteEvent {
161
- id: string;
162
- /** Missing when the bot was removed from the guild. */
163
- unavailable?: boolean;
164
- }
165
- /** https://docs.discord.com/developers/events/gateway-events#guild-member-add */
166
- export interface GuildMemberAddEvent extends GuildMember {
167
- user: User;
168
- guild_id: string;
169
- }
170
- /** https://docs.discord.com/developers/events/gateway-events#guild-member-update */
171
- export type GuildMemberUpdateEvent = GuildMemberAddEvent;
172
- /** https://docs.discord.com/developers/events/gateway-events#guild-member-remove */
173
- export interface GuildMemberRemoveEvent {
174
- guild_id: string;
175
- user: User;
176
- }
177
- /** https://docs.discord.com/developers/events/gateway-events#guild-ban-add */
178
- export interface GuildBanEvent {
179
- guild_id: string;
180
- user: User;
181
- }
182
- /** https://docs.discord.com/developers/events/gateway-events#guild-role-create */
183
- export interface GuildRoleEvent {
184
- guild_id: string;
185
- role: Role;
186
- }
187
- /** https://docs.discord.com/developers/events/gateway-events#guild-role-delete */
188
- export interface GuildRoleDeleteEvent {
189
- guild_id: string;
190
- role_id: string;
191
- }
192
- /** https://docs.discord.com/developers/resources/voice#voice-state-object */
193
- export interface VoiceStateUpdateEvent {
194
- guild_id?: string;
195
- channel_id: string | null;
196
- user_id: string;
197
- member?: GuildMember;
198
- session_id: string;
199
- deaf: boolean;
200
- mute: boolean;
201
- self_deaf: boolean;
202
- self_mute: boolean;
203
- self_stream?: boolean;
204
- self_video: boolean;
205
- suppress: boolean;
206
- }
207
- /** https://docs.discord.com/developers/events/gateway-events#typing-start */
208
- export interface TypingStartEvent {
209
- channel_id: string;
210
- guild_id?: string;
211
- user_id: string;
212
- timestamp: number;
213
- member?: GuildMember;
214
- }
215
- /** https://docs.discord.com/developers/events/gateway-events#channel-pins-update */
216
- export interface ChannelPinsUpdateEvent {
217
- guild_id?: string;
218
- channel_id: string;
219
- last_pin_timestamp?: string | null;
220
- }
221
- /** https://docs.discord.com/developers/interactions/receiving-and-responding#interaction-object */
222
- export interface Interaction {
223
- id: string;
224
- application_id: string;
225
- type: number;
226
- data?: Record<string, any>;
227
- guild_id?: string;
228
- channel_id?: string;
229
- /** In guilds. */
230
- member?: GuildMember & {
231
- user: User;
232
- };
233
- /** In DMs. */
234
- user?: User;
235
- token: string;
236
- version: number;
237
- message?: Message;
238
- locale?: string;
239
- guild_locale?: string;
240
- [key: string]: any;
241
- }
242
- /** Data received by each event handler, by event name. */
243
- export interface EventPayloads {
244
- ready: ReadyEvent;
245
- resumed: Record<string, never>;
246
- userUpdate: User;
247
- interactionCreate: Interaction;
248
- guildCreate: GuildCreateEvent;
249
- guildDelete: GuildDeleteEvent;
250
- guildMemberAdd: GuildMemberAddEvent;
251
- guildMemberUpdate: GuildMemberUpdateEvent;
252
- guildMemberRemove: GuildMemberRemoveEvent;
253
- guildBanAdd: GuildBanEvent;
254
- guildBanRemove: GuildBanEvent;
255
- guildRoleCreate: GuildRoleEvent;
256
- guildRoleUpdate: GuildRoleEvent;
257
- guildRoleDelete: GuildRoleDeleteEvent;
258
- channelCreate: Channel;
259
- channelUpdate: Channel;
260
- channelDelete: Channel;
261
- channelPinsUpdate: ChannelPinsUpdateEvent;
262
- threadCreate: Channel & {
263
- newly_created?: boolean;
264
- };
265
- threadUpdate: Channel;
266
- threadDelete: Pick<Channel, 'id' | 'guild_id' | 'parent_id' | 'type'>;
267
- messageCreate: MessageCreateEvent;
268
- messageUpdate: MessageCreateEvent;
269
- messageDelete: MessageDeleteEvent;
270
- messageDeleteBulk: MessageDeleteBulkEvent;
271
- messageReactionAdd: MessageReactionAddEvent;
272
- messageReactionRemove: MessageReactionRemoveEvent;
273
- voiceStateUpdate: VoiceStateUpdateEvent;
274
- typingStart: TypingStartEvent;
275
- }
@@ -1,3 +0,0 @@
1
- // Raw gateway payloads, as sent by Discord (snake_case). Only the common events
2
- // are typed; the others are `Record<string, any>`.
3
- export {};
@@ -1,42 +0,0 @@
1
- export type PresenceStatus = 'online' | 'idle' | 'dnd' | 'invisible';
2
- /** `name` is always the text displayed on the profile. */
3
- export type Activity = {
4
- type: 'playing' | 'listening' | 'watching' | 'competing' | 'custom';
5
- name: string;
6
- } | {
7
- type: 'streaming';
8
- name: string;
9
- url: string;
10
- };
11
- export interface Presence {
12
- /** Defaults to `online`. */
13
- status?: PresenceStatus;
14
- /** A plain string is shown as a custom status. */
15
- activity?: Activity | string;
16
- }
17
- /**
18
- * Converts a `Presence` into the gateway "Update Presence" payload. Values are
19
- * checked at runtime since they may come from a database, and Discord could
20
- * drop the connection on an invalid payload.
21
- */
22
- export declare function toGatewayPresence(presence: Presence): {
23
- since: null;
24
- activities: ({
25
- type: 4;
26
- name: string;
27
- state: string;
28
- url?: undefined;
29
- } | {
30
- state?: undefined;
31
- type: 1;
32
- name: string;
33
- url: string;
34
- } | {
35
- state?: undefined;
36
- url?: undefined;
37
- type: 0 | 2 | 3 | 5;
38
- name: string;
39
- })[];
40
- status: PresenceStatus;
41
- afk: boolean;
42
- };
@@ -1,51 +0,0 @@
1
- // https://docs.discord.com/developers/events/gateway-events#update-presence
2
- // https://docs.discord.com/developers/events/gateway-events#activity-object-activity-types
3
- const ACTIVITY_TYPES = {
4
- playing: 0,
5
- streaming: 1,
6
- listening: 2,
7
- watching: 3,
8
- custom: 4,
9
- competing: 5,
10
- };
11
- const STATUSES = ['online', 'idle', 'dnd', 'invisible'];
12
- /**
13
- * Converts a `Presence` into the gateway "Update Presence" payload. Values are
14
- * checked at runtime since they may come from a database, and Discord could
15
- * drop the connection on an invalid payload.
16
- */
17
- export function toGatewayPresence(presence) {
18
- const status = presence.status ?? 'online';
19
- if (!STATUSES.includes(status)) {
20
- throw new Error(`Status "${status}" doesn't exist. Available statuses: ${STATUSES.join(', ')}.`);
21
- }
22
- const activity = typeof presence.activity === 'string'
23
- ? { type: 'custom', name: presence.activity }
24
- : presence.activity;
25
- return {
26
- since: null,
27
- activities: activity ? [toGatewayActivity(activity)] : [],
28
- status,
29
- afk: false,
30
- };
31
- }
32
- function toGatewayActivity(activity) {
33
- if (!Object.hasOwn(ACTIVITY_TYPES, activity.type)) {
34
- throw new Error(`Activity type "${activity.type}" doesn't exist. Available types: ${Object.keys(ACTIVITY_TYPES).join(', ')}.`);
35
- }
36
- if (typeof activity.name !== 'string' || !activity.name) {
37
- throw new Error(`The "${activity.type}" activity needs a name: the text shown under the bot's name.`);
38
- }
39
- switch (activity.type) {
40
- case 'custom':
41
- // Discord ignores `name` for custom statuses and displays `state`
42
- return { type: ACTIVITY_TYPES.custom, name: 'Custom Status', state: activity.name };
43
- case 'streaming':
44
- if (!/^https:\/\/(www\.)?(twitch\.tv|youtube\.com)\//.test(activity.url)) {
45
- throw new Error(`Streaming activity url must be a https://twitch.tv/ or https://youtube.com/ link, got "${activity.url}".`);
46
- }
47
- return { type: ACTIVITY_TYPES.streaming, name: activity.name, url: activity.url };
48
- default:
49
- return { type: ACTIVITY_TYPES[activity.type], name: activity.name };
50
- }
51
- }
@@ -1,49 +0,0 @@
1
- export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
2
- /** A file sent with a message, as `files[n]`. */
3
- export interface FileUpload {
4
- /** File name shown in Discord, also usable in embeds as `attachment://name`. */
5
- name: string;
6
- data: Blob | ArrayBuffer | Uint8Array | string;
7
- /** Alt text, up to 1024 characters. */
8
- description?: string;
9
- }
10
- export interface RequestOptions {
11
- body?: unknown;
12
- query?: Record<string, string | number | boolean | undefined>;
13
- /** Shown in the guild's audit log, on endpoints supporting `X-Audit-Log-Reason`. */
14
- reason?: string;
15
- files?: FileUpload[];
16
- }
17
- /** Error returned by the Discord API, with its JSON error code when there is one. */
18
- export declare class DiscordAPIError extends Error {
19
- readonly status: number;
20
- readonly method: HttpMethod;
21
- readonly path: string;
22
- /** https://docs.discord.com/developers/topics/opcodes-and-status-codes#json */
23
- readonly code?: number | undefined;
24
- /** Details of an invalid form body. */
25
- readonly errors?: unknown;
26
- constructor(message: string, status: number, method: HttpMethod, path: string,
27
- /** https://docs.discord.com/developers/topics/opcodes-and-status-codes#json */
28
- code?: number | undefined,
29
- /** Details of an invalid form body. */
30
- errors?: unknown);
31
- }
32
- /**
33
- * HTTP client for the Discord API. Requests wait for their rate limit instead
34
- * of failing: buckets are learned from the `X-RateLimit-*` headers, the global
35
- * limit is respected, and a 429 is retried after `retry_after`.
36
- *
37
- * https://docs.discord.com/developers/topics/rate-limits
38
- */
39
- export declare class RestClient {
40
- #private;
41
- constructor(token: string);
42
- get<T>(path: string, options?: RequestOptions): Promise<T>;
43
- post<T>(path: string, options?: RequestOptions): Promise<T>;
44
- put<T>(path: string, options?: RequestOptions): Promise<T>;
45
- patch<T>(path: string, options?: RequestOptions): Promise<T>;
46
- delete<T>(path: string, options?: RequestOptions): Promise<T>;
47
- /** Sends a request once its bucket allows it. Resolves to undefined on 204. */
48
- request<T>(method: HttpMethod, path: string, options?: RequestOptions): Promise<T>;
49
- }
@@ -1,271 +0,0 @@
1
- import { API_BASE_URL, INVALID_TOKEN_MESSAGE } from './constants.js';
2
- const USER_AGENT = 'DiscordBot (https://github.com/chapterjs/chapterjs, 0.1.0)';
3
- /**
4
- * Requests per second allowed for the whole bot. Interaction endpoints are not
5
- * bound to it.
6
- * https://docs.discord.com/developers/topics/rate-limits#global-rate-limit
7
- */
8
- const GLOBAL_LIMIT = 50;
9
- /** Attempts for a request that keeps being rate limited. */
10
- const MAX_ATTEMPTS = 5;
11
- /** Error returned by the Discord API, with its JSON error code when there is one. */
12
- export class DiscordAPIError extends Error {
13
- status;
14
- method;
15
- path;
16
- code;
17
- errors;
18
- constructor(message, status, method, path,
19
- /** https://docs.discord.com/developers/topics/opcodes-and-status-codes#json */
20
- code,
21
- /** Details of an invalid form body. */
22
- errors) {
23
- super(message);
24
- this.status = status;
25
- this.method = method;
26
- this.path = path;
27
- this.code = code;
28
- this.errors = errors;
29
- this.name = 'DiscordAPIError';
30
- }
31
- }
32
- const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
33
- /**
34
- * HTTP client for the Discord API. Requests wait for their rate limit instead
35
- * of failing: buckets are learned from the `X-RateLimit-*` headers, the global
36
- * limit is respected, and a 429 is retried after `retry_after`.
37
- *
38
- * https://docs.discord.com/developers/topics/rate-limits
39
- */
40
- export class RestClient {
41
- #token;
42
- /** Route → bucket hash, as sent by Discord in `X-RateLimit-Bucket`. */
43
- #hashes = new Map();
44
- #buckets = new Map();
45
- #globalResetAt = 0;
46
- #globalWindowStart = 0;
47
- #globalCount = 0;
48
- constructor(token) {
49
- this.#token = token;
50
- }
51
- get(path, options) {
52
- return this.request('GET', path, options);
53
- }
54
- post(path, options) {
55
- return this.request('POST', path, options);
56
- }
57
- put(path, options) {
58
- return this.request('PUT', path, options);
59
- }
60
- patch(path, options) {
61
- return this.request('PATCH', path, options);
62
- }
63
- delete(path, options) {
64
- return this.request('DELETE', path, options);
65
- }
66
- /** Sends a request once its bucket allows it. Resolves to undefined on 204. */
67
- request(method, path, options = {}) {
68
- const route = routeOf(method, path);
69
- const major = majorParameters(path);
70
- const key = `${this.#hashes.get(route) ?? route}:${major}`;
71
- let bucket = this.#buckets.get(key);
72
- if (!bucket) {
73
- bucket = { remaining: 1, resetAt: 0, queue: Promise.resolve() };
74
- this.#buckets.set(key, bucket);
75
- }
76
- // Waiting in the queue loses the caller's stack: errors get the stack of
77
- // this call instead, so they point to the line of user code that made it
78
- const caller = new Error();
79
- const result = bucket.queue
80
- .then(() => this.#send(method, path, route, major, bucket, options))
81
- .catch((error) => {
82
- if (error instanceof Error && caller.stack) {
83
- error.stack = `${error.name}: ${error.message}\n${caller.stack.split('\n').slice(1).join('\n')}`;
84
- }
85
- throw error;
86
- });
87
- bucket.queue = result.catch(() => { });
88
- return result;
89
- }
90
- async #send(method, path, route, major, bucket, options) {
91
- const interaction = path.startsWith('/interactions/');
92
- for (let attempt = 1;; attempt++) {
93
- if (bucket.remaining <= 0 && Date.now() < bucket.resetAt) {
94
- await sleep(bucket.resetAt - Date.now());
95
- }
96
- if (!interaction)
97
- await this.#waitGlobal();
98
- const response = await fetch(buildUrl(path, options.query), {
99
- method,
100
- headers: this.#headers(options),
101
- body: buildBody(options),
102
- }).catch((error) => {
103
- throw new Error(`Can't reach Discord (${error.cause?.code ?? error.message}): check your internet connection.`, { cause: error });
104
- });
105
- const hash = response.headers.get('x-ratelimit-bucket');
106
- if (hash) {
107
- this.#hashes.set(route, hash);
108
- // Later requests are keyed by hash: they must share this bucket's state
109
- const hashKey = `${hash}:${major}`;
110
- if (!this.#buckets.has(hashKey))
111
- this.#buckets.set(hashKey, bucket);
112
- }
113
- const remaining = response.headers.get('x-ratelimit-remaining');
114
- const resetAfter = response.headers.get('x-ratelimit-reset-after');
115
- if (remaining !== null)
116
- bucket.remaining = Number(remaining);
117
- if (resetAfter !== null)
118
- bucket.resetAt = Date.now() + Number(resetAfter) * 1000;
119
- if (response.status === 429) {
120
- // https://docs.discord.com/developers/topics/rate-limits#exceeding-a-rate-limit
121
- const body = (await response.json().catch(() => ({})));
122
- const retryAfter = (body.retry_after ??
123
- Number(response.headers.get('retry-after') ?? 1)) * 1000;
124
- if (body.global || response.headers.get('x-ratelimit-global')) {
125
- this.#globalResetAt = Date.now() + retryAfter;
126
- }
127
- else {
128
- bucket.remaining = 0;
129
- bucket.resetAt = Date.now() + retryAfter;
130
- }
131
- if (attempt < MAX_ATTEMPTS)
132
- continue;
133
- }
134
- if (response.status === 401) {
135
- throw new Error(INVALID_TOKEN_MESSAGE);
136
- }
137
- if (!response.ok)
138
- throw await toError(response, method, path);
139
- if (response.status === 204)
140
- return undefined;
141
- return (await response.json());
142
- }
143
- }
144
- #headers(options) {
145
- const headers = {
146
- Authorization: `Bot ${this.#token}`,
147
- 'User-Agent': USER_AGENT,
148
- };
149
- if (options.body !== undefined && !options.files?.length) {
150
- headers['Content-Type'] = 'application/json';
151
- }
152
- // https://docs.discord.com/developers/resources/audit-log#audit-log-entry-object
153
- if (options.reason)
154
- headers['X-Audit-Log-Reason'] = encodeURIComponent(options.reason);
155
- return headers;
156
- }
157
- async #waitGlobal() {
158
- for (;;) {
159
- const now = Date.now();
160
- if (now < this.#globalResetAt) {
161
- await sleep(this.#globalResetAt - now);
162
- continue;
163
- }
164
- if (now - this.#globalWindowStart >= 1000) {
165
- this.#globalWindowStart = now;
166
- this.#globalCount = 0;
167
- }
168
- if (this.#globalCount < GLOBAL_LIMIT) {
169
- this.#globalCount++;
170
- return;
171
- }
172
- await sleep(this.#globalWindowStart + 1000 - now);
173
- }
174
- }
175
- }
176
- /**
177
- * Identifies a route regardless of its ids, except the top-level resources
178
- * that have their own limits (channel, guild, webhook).
179
- * https://docs.discord.com/developers/topics/rate-limits
180
- */
181
- function routeOf(method, path) {
182
- const route = path
183
- .split('?')[0]
184
- .replace(/\/reactions\/[^/]+/, '/reactions/:emoji')
185
- .replace(/\/(channels|guilds|webhooks)\/\d{17,20}/g, '/$1/:major')
186
- .replace(/\/\d{17,20}/g, '/:id')
187
- .replace(/\/(webhooks\/:major|interactions\/:id)\/[^/]+/, '/$1/:token');
188
- return `${method} ${route}`;
189
- }
190
- function majorParameters(path) {
191
- const match = /^\/(?:channels|guilds)\/(\d+)|^\/webhooks\/(\d+)(?:\/([^/?]+))?/.exec(path);
192
- return match ? match.slice(1).filter(Boolean).join('/') : '';
193
- }
194
- function buildUrl(path, query) {
195
- const url = new URL(`${API_BASE_URL}${path}`);
196
- for (const [key, value] of Object.entries(query ?? {})) {
197
- if (value !== undefined)
198
- url.searchParams.set(key, String(value));
199
- }
200
- return url.href;
201
- }
202
- // https://docs.discord.com/developers/reference#uploading-files
203
- function buildBody({ body, files, }) {
204
- if (!files?.length)
205
- return body === undefined ? undefined : JSON.stringify(body);
206
- const form = new FormData();
207
- const payload = (body ?? {});
208
- const attachments = files.map((file, id) => ({
209
- id,
210
- filename: file.name,
211
- ...(file.description !== undefined && { description: file.description }),
212
- }));
213
- form.set('payload_json', JSON.stringify({ ...payload, attachments }));
214
- files.forEach((file, index) => {
215
- const data = file.data instanceof Blob ? file.data : new Blob([file.data]);
216
- form.set(`files[${index}]`, data, file.name);
217
- });
218
- return form;
219
- }
220
- async function toError(response, method, path) {
221
- const text = await response.text();
222
- let body = {};
223
- try {
224
- body = JSON.parse(text);
225
- }
226
- catch { }
227
- const details = body.errors ? ` ${formatErrors(body.errors)}` : '';
228
- const hint = body.code === undefined ? undefined : ERROR_HINTS[body.code];
229
- return new DiscordAPIError(`${body.message ?? (text || response.statusText)}${details} (${response.status} on ${method} ${path})` +
230
- (hint ? `\n ${hint}` : ''), response.status, method, path, body.code, body.errors);
231
- }
232
- /**
233
- * What to do about the most common errors, by JSON error code.
234
- * https://docs.discord.com/developers/topics/opcodes-and-status-codes#json-json-error-codes
235
- */
236
- const ERROR_HINTS = {
237
- 10003: "The channel doesn't exist anymore, or the bot can't see it.",
238
- 10007: 'This user is not (or no longer) a member of the server.',
239
- 10008: 'The message was deleted, or is not in this channel.',
240
- 10011: "The role doesn't exist anymore.",
241
- 10014: 'Custom emojis are written <:name:id> (type \\:emoji: in Discord to get it).',
242
- 10062: 'The interaction expired: Discord waits 3 seconds for an answer. Call interaction.defer() first when your code takes longer.',
243
- 40060: 'This interaction was already answered: use interaction.editReply() to change the answer, or interaction.followUp() to send another message.',
244
- 50001: "The bot can't see this channel: give its role the View Channel permission (channel settings > Permissions).",
245
- 50007: "This user doesn't accept direct messages from the bot (privacy settings, or no server in common).",
246
- 50013: "The bot is missing a permission for this action. Check its role in Server Settings > Roles and the channel's permissions. " +
247
- "To act on a member or a role, the bot's highest role must also be above theirs.",
248
- 50083: 'The thread is archived: unarchive it first.',
249
- 160002: 'Replying to a message needs the Read Message History permission.',
250
- };
251
- /**
252
- * Flattens nested form errors into `field.path: message`.
253
- * https://docs.discord.com/developers/reference#error-messages
254
- */
255
- function formatErrors(errors, prefix = '') {
256
- if (!errors || typeof errors !== 'object')
257
- return '';
258
- const messages = [];
259
- for (const [key, value] of Object.entries(errors)) {
260
- if (key === '_errors' && Array.isArray(value)) {
261
- for (const error of value)
262
- messages.push(`${prefix || 'body'}: ${error.message}`);
263
- }
264
- else {
265
- const nested = formatErrors(value, prefix ? `${prefix}.${key}` : key);
266
- if (nested)
267
- messages.push(nested);
268
- }
269
- }
270
- return messages.join('; ');
271
- }