chapterjs 0.3.0 → 0.5.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 (115) hide show
  1. package/README.md +5 -3
  2. package/dist/assets/public.js +4 -4
  3. package/dist/cli/build.d.ts +6 -2
  4. package/dist/cli/build.js +17 -4
  5. package/dist/cli/dev.js +37 -6
  6. package/dist/cli/env.d.ts +5 -0
  7. package/dist/cli/env.js +39 -3
  8. package/dist/cli/project.d.ts +61 -9
  9. package/dist/cli/project.js +250 -44
  10. package/dist/cli/redis.d.ts +23 -0
  11. package/dist/cli/redis.js +69 -0
  12. package/dist/cli/start.js +54 -18
  13. package/dist/cli/test.js +112 -18
  14. package/dist/commands/command.d.ts +140 -5
  15. package/dist/commands/command.js +17 -2
  16. package/dist/commands/declaration.d.ts +17 -4
  17. package/dist/commands/declaration.js +128 -2
  18. package/dist/commands/router.js +78 -18
  19. package/dist/commands/tree.d.ts +25 -4
  20. package/dist/commands/tree.js +95 -26
  21. package/dist/commands/twins.d.ts +8 -0
  22. package/dist/commands/twins.js +24 -6
  23. package/dist/components/button.d.ts +8 -3
  24. package/dist/components/declaration.d.ts +2 -2
  25. package/dist/components/declaration.js +16 -12
  26. package/dist/components/render.js +5 -0
  27. package/dist/components/router.js +41 -0
  28. package/dist/components/select.d.ts +12 -5
  29. package/dist/core/bot.d.ts +7 -0
  30. package/dist/core/bot.js +44 -0
  31. package/dist/discord/api.d.ts +2 -0
  32. package/dist/discord/api.js +2 -0
  33. package/dist/discord/permissions.d.ts +4 -4
  34. package/dist/discord/permissions.js +13 -0
  35. package/dist/events/registry.d.ts +265 -243
  36. package/dist/events/registry.js +131 -100
  37. package/dist/index.d.ts +7 -4
  38. package/dist/index.js +2 -1
  39. package/dist/interactions/dispatch.js +4 -2
  40. package/dist/loader/loader.d.ts +16 -0
  41. package/dist/loader/loader.js +52 -7
  42. package/dist/loader/usage.d.ts +15 -0
  43. package/dist/loader/usage.js +40 -0
  44. package/dist/loader/watch.d.ts +5 -3
  45. package/dist/loader/watch.js +88 -17
  46. package/dist/messages/commands.js +3 -0
  47. package/dist/messages/messages.d.ts +1 -0
  48. package/dist/messages/translate.js +5 -1
  49. package/dist/presence/declaration.d.ts +49 -2
  50. package/dist/presence/declaration.js +122 -39
  51. package/dist/presence/presence.d.ts +65 -6
  52. package/dist/presence/presence.js +11 -0
  53. package/dist/presence/rotation.d.ts +32 -0
  54. package/dist/presence/rotation.js +167 -0
  55. package/dist/ranking/declaration.d.ts +12 -0
  56. package/dist/ranking/declaration.js +48 -0
  57. package/dist/ranking/ranking.d.ts +102 -0
  58. package/dist/ranking/ranking.js +129 -0
  59. package/dist/redis/client.d.ts +36 -0
  60. package/dist/redis/client.js +252 -0
  61. package/dist/redis/protocol.d.ts +22 -0
  62. package/dist/redis/protocol.js +99 -0
  63. package/dist/redis/url.d.ts +24 -0
  64. package/dist/redis/url.js +50 -0
  65. package/dist/rest/errors.d.ts +0 -1
  66. package/dist/rest/errors.js +15 -1
  67. package/dist/rest/rest.js +10 -1
  68. package/dist/store/backend.d.ts +49 -4
  69. package/dist/store/backend.js +66 -11
  70. package/dist/store/declaration.d.ts +3 -0
  71. package/dist/store/declaration.js +8 -3
  72. package/dist/store/file-backend.d.ts +3 -2
  73. package/dist/store/file-backend.js +47 -1
  74. package/dist/store/ipc-backend.d.ts +24 -1
  75. package/dist/store/ipc-backend.js +49 -0
  76. package/dist/store/memory-backend.d.ts +4 -2
  77. package/dist/store/memory-backend.js +27 -1
  78. package/dist/store/ranking-backend.d.ts +45 -0
  79. package/dist/store/ranking-backend.js +82 -0
  80. package/dist/store/redis-backend.d.ts +38 -0
  81. package/dist/store/redis-backend.js +245 -0
  82. package/dist/store/redis-ranking.d.ts +15 -0
  83. package/dist/store/redis-ranking.js +69 -0
  84. package/dist/store/scope.d.ts +17 -1
  85. package/dist/store/scope.js +32 -3
  86. package/dist/store/store.d.ts +39 -5
  87. package/dist/store/store.js +79 -32
  88. package/dist/structures/channel.d.ts +13 -0
  89. package/dist/structures/channel.js +24 -0
  90. package/dist/structures/context.d.ts +3 -0
  91. package/dist/structures/entities.js +1 -0
  92. package/dist/structures/interaction.d.ts +6 -0
  93. package/dist/structures/interaction.js +20 -0
  94. package/dist/structures/invite.d.ts +6 -0
  95. package/dist/structures/invite.js +11 -0
  96. package/dist/structures/message.d.ts +17 -0
  97. package/dist/structures/message.js +33 -0
  98. package/dist/structures/wait.d.ts +105 -0
  99. package/dist/structures/wait.js +85 -0
  100. package/dist/testing/harness.d.ts +48 -8
  101. package/dist/testing/harness.js +156 -36
  102. package/dist/testing/index.d.ts +1 -1
  103. package/dist/testing/smoke.js +112 -1
  104. package/dist/testing/world.js +51 -2
  105. package/dist/util/call-site.d.ts +4 -0
  106. package/dist/util/call-site.js +22 -0
  107. package/dist/voice/connection.d.ts +2 -0
  108. package/dist/voice/connection.js +15 -1
  109. package/dist/voice/usage.d.ts +3 -2
  110. package/dist/voice/usage.js +7 -19
  111. package/dist/waiting/usage.d.ts +5 -0
  112. package/dist/waiting/usage.js +19 -0
  113. package/dist/waiting/waiters.d.ts +48 -0
  114. package/dist/waiting/waiters.js +107 -0
  115. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  import type { CacheLimits } from '../cache/cache.js';
2
2
  import type { Snowflake } from '../discord/types/common.js';
3
3
  import type { GatewayDispatchEventName, GatewayDispatchEvents } from '../discord/types/gateway-events.js';
4
- import type { Channel, DMChannel, GuildChannel, GuildTextBasedChannel, TextBasedChannel, ThreadChannel, VoiceChannel } from '../structures/channel.js';
4
+ import type { DMChannel, GuildChannel, GuildTextBasedChannel, TextBasedChannel, ThreadChannel, VoiceChannel } from '../structures/channel.js';
5
5
  import type { Context } from '../structures/context.js';
6
6
  import type { GuildEmoji } from '../structures/emoji.js';
7
7
  import type { AuditLogEntry, Guild, ScheduledEvent, VoiceState } from '../structures/guild.js';
@@ -11,7 +11,152 @@ import type { DmMessage, GuildMessage, MemberMessage, Message, PrivateMessage, R
11
11
  import type { Role } from '../structures/role.js';
12
12
  import type { User, UserPresence } from '../structures/user.js';
13
13
  import type { TranslationContext } from '../messages/messages.js';
14
- /** What your function receives, for each event. */
14
+ /**
15
+ * A message that was deleted: what is known of it. The message itself is
16
+ * only there when the bot remembered it.
17
+ */
18
+ export interface DeletedMessage {
19
+ /** The id of the deleted message. */
20
+ id: Snowflake;
21
+ /** The id of the channel the message was in. */
22
+ channelId: Snowflake;
23
+ /** The channel, when the bot knows it. */
24
+ channel: TextBasedChannel | null;
25
+ /** The id of the server; `null` for a private message. */
26
+ guildId: Snowflake | null;
27
+ /** The message as it was, when the bot remembered it. */
28
+ before: Message | null;
29
+ }
30
+ /** A reaction added to a message, or removed from it. */
31
+ export interface UserReaction {
32
+ /** The emoji of the reaction. */
33
+ emoji: ReactionEmoji;
34
+ /** Who reacted. */
35
+ user: User;
36
+ /** Who reacted, as a member of the server: `null` in a private message, or when the bot does not remember them. */
37
+ member: GuildMember | null;
38
+ /** Whether it is a super reaction. */
39
+ burst: boolean;
40
+ /** The id of the message. */
41
+ messageId: Snowflake;
42
+ /** The message, when the bot remembers it. */
43
+ message: Message | null;
44
+ /** The id of the channel of the message. */
45
+ channelId: Snowflake;
46
+ /** The channel of the message, when the bot knows it. */
47
+ channel: TextBasedChannel | null;
48
+ /** The id of the server; `null` in a private message. */
49
+ guildId: Snowflake | null;
50
+ }
51
+ /** A reaction added to a message: what Discord tells of its message too. */
52
+ export interface AddedReaction extends UserReaction {
53
+ /** The id of who wrote the message, when Discord says it. */
54
+ messageAuthorId: Snowflake | null;
55
+ }
56
+ /** Reactions removed from a message at once: all of them, or every reaction of one emoji. */
57
+ export interface ClearedReactions {
58
+ /** The emoji whose reactions were removed; `null` when all were. */
59
+ emoji: ReactionEmoji | null;
60
+ /** The id of the message. */
61
+ messageId: Snowflake;
62
+ /** The message, when the bot remembers it. */
63
+ message: Message | null;
64
+ /** The id of the channel of the message. */
65
+ channelId: Snowflake;
66
+ /** The channel of the message, when the bot knows it. */
67
+ channel: TextBasedChannel | null;
68
+ /** The id of the server; `null` in a private message. */
69
+ guildId: Snowflake | null;
70
+ }
71
+ /** A vote in a poll, given or taken back. */
72
+ export interface PollVote {
73
+ /** The id Discord gave to the answer: today, its position in the poll, `1` for the first answer. */
74
+ answerId: number;
75
+ /** Who voted. */
76
+ user: User;
77
+ /** Who voted, as a member of the server, when the bot remembers it. */
78
+ member: GuildMember | null;
79
+ /** The id of the message of the poll. */
80
+ messageId: Snowflake;
81
+ /** The message of the poll, when the bot remembers it. */
82
+ message: Message | null;
83
+ /** The id of the channel of the poll. */
84
+ channelId: Snowflake;
85
+ /** The channel of the poll, when the bot knows it. */
86
+ channel: TextBasedChannel | null;
87
+ /** The id of the server; `null` in a private message. */
88
+ guildId: Snowflake | null;
89
+ }
90
+ /** Someone typing in a channel. */
91
+ export interface Typing {
92
+ /** Who is typing. */
93
+ user: User;
94
+ /** Who is typing, as a member of the server; `null` in a private message. */
95
+ member: GuildMember | null;
96
+ /** When they started. */
97
+ startedAt: Date;
98
+ /** The id of the channel. */
99
+ channelId: Snowflake;
100
+ /** The channel, when the bot knows it. */
101
+ channel: TextBasedChannel | null;
102
+ /** The id of the server; `null` in a private message. */
103
+ guildId: Snowflake | null;
104
+ }
105
+ /** An invite that was deleted, or expired: what is left of it. */
106
+ export interface DeletedInvite {
107
+ /** The code of the invite (`discord.gg/code`). */
108
+ code: string;
109
+ /** The channel the invite led to. */
110
+ channel: GuildChannel;
111
+ }
112
+ /** Someone in a voice channel: who, where, and their voice state. */
113
+ export interface VoiceActivity {
114
+ /** Who it is. */
115
+ member: GuildMember;
116
+ /** The voice channel. */
117
+ channel: VoiceChannel;
118
+ /** Their voice state: muted, deafened, streaming... */
119
+ state: VoiceState;
120
+ }
121
+ /** Someone who went from one voice channel to another. */
122
+ export interface VoiceMove {
123
+ /** Who moved. */
124
+ member: GuildMember;
125
+ /** The channel they left. */
126
+ from: VoiceChannel;
127
+ /** The channel they are in now. */
128
+ to: VoiceChannel;
129
+ /** Their voice state, as it is now. */
130
+ state: VoiceState;
131
+ }
132
+ /** Someone in a voice channel whose voice state changed. */
133
+ export interface VoiceChange extends VoiceActivity {
134
+ /** Their voice state as it was. */
135
+ before: VoiceState;
136
+ }
137
+ /** Someone's status or activity, as it is now, and whose it is. */
138
+ export interface PresenceChange extends UserPresence {
139
+ /** The id of whose presence changed. */
140
+ userId: Snowflake;
141
+ /** The account of whose presence changed, when the bot knows it. */
142
+ user: User | null;
143
+ /** Whose presence changed, as a member of the server, when the bot remembers it. */
144
+ member: GuildMember | null;
145
+ }
146
+ /** Someone interested in a scheduled event, or no longer. */
147
+ export interface ScheduledEventInterest {
148
+ /** The id of the scheduled event. */
149
+ scheduledEventId: Snowflake;
150
+ /** Who it is. */
151
+ user: User;
152
+ /** Who it is, as a member of the server, when the bot remembers it. */
153
+ member: GuildMember | null;
154
+ }
155
+ /**
156
+ * What your function receives, for each event: what the event is about,
157
+ * the server it happened in, and `t`. The widest form: the options of a
158
+ * file narrow it (`ContextOf`).
159
+ */
15
160
  export interface EventContexts {
16
161
  /** The bot is connected and knows every server it is in. */
17
162
  ready: {
@@ -24,26 +169,22 @@ export interface EventContexts {
24
169
  messageCreate: {
25
170
  /** The message that was sent. */
26
171
  message: Message;
172
+ /** The server; `null` for a private message. */
173
+ guild: Guild | null;
27
174
  };
28
175
  /** A message was edited. */
29
176
  messageUpdate: {
30
177
  /** The message, as it is now. */
31
178
  message: Message;
179
+ /** The server; `null` for a private message. */
180
+ guild: Guild | null;
32
181
  };
33
182
  /** A message was deleted. */
34
183
  messageDelete: {
35
- /** The id of the deleted message. */
36
- messageId: Snowflake;
37
- /** The id of the channel the message was in. */
38
- channelId: Snowflake;
39
- /** The id of the server; `null` for a private message. */
40
- guildId: Snowflake | null;
184
+ /** The message that was deleted. */
185
+ message: DeletedMessage;
41
186
  /** The server; `null` for a private message. */
42
187
  guild: Guild | null;
43
- /** The channel, when the bot knows it. */
44
- channel: TextBasedChannel | null;
45
- /** The message as it was, when the bot remembered it. */
46
- message: Message | null;
47
188
  };
48
189
  /** Someone joined a server. */
49
190
  memberJoin: {
@@ -58,8 +199,6 @@ export interface EventContexts {
58
199
  user: User;
59
200
  /** The server they left. */
60
201
  guild: Guild;
61
- /** The member as it was, when the bot knew it. */
62
- member: GuildMember | null;
63
202
  };
64
203
  /** A member changed: nickname, roles, timeout, avatar... */
65
204
  memberUpdate: {
@@ -81,17 +220,32 @@ export interface EventContexts {
81
220
  /** A channel was created. */
82
221
  channelCreate: {
83
222
  /** The new channel or thread. */
84
- channel: GuildChannel | ThreadChannel | Channel;
223
+ channel: GuildChannel | ThreadChannel;
224
+ /**
225
+ * The server of the channel: Discord only sends these events, with the
226
+ * Guilds intent, for the channels of a server.
227
+ */
228
+ guild: Guild;
85
229
  };
86
230
  /** A channel changed: name, topic, permissions... */
87
231
  channelUpdate: {
88
232
  /** The channel or thread, as it is now. */
89
- channel: GuildChannel | ThreadChannel | Channel;
233
+ channel: GuildChannel | ThreadChannel;
234
+ /**
235
+ * The server of the channel: Discord only sends these events, with the
236
+ * Guilds intent, for the channels of a server.
237
+ */
238
+ guild: Guild;
90
239
  };
91
240
  /** A channel was deleted. */
92
241
  channelDelete: {
93
242
  /** The channel or thread as it was. */
94
- channel: GuildChannel | ThreadChannel | Channel;
243
+ channel: GuildChannel | ThreadChannel;
244
+ /**
245
+ * The server of the channel: Discord only sends these events, with the
246
+ * Guilds intent, for the channels of a server.
247
+ */
248
+ guild: Guild;
95
249
  };
96
250
  /** A role was created. */
97
251
  roleCreate: {
@@ -109,12 +263,10 @@ export interface EventContexts {
109
263
  };
110
264
  /** A role was deleted. */
111
265
  roleDelete: {
112
- /** The id of the deleted role. */
113
- roleId: Snowflake;
114
- /** The server the role was in. */
115
- guild: Guild;
116
266
  /** The role as it was. */
117
267
  role: Role;
268
+ /** The server the role was in. */
269
+ guild: Guild;
118
270
  };
119
271
  /** The server changed: name, icon, settings... */
120
272
  guildUpdate: {
@@ -162,17 +314,13 @@ export interface EventContexts {
162
314
  invite: Invite;
163
315
  /** The server the invite leads to. */
164
316
  guild: Guild;
165
- /** The channel the invite leads to. */
166
- channel: GuildChannel;
167
317
  };
168
318
  /** An invite was deleted, or expired. */
169
319
  inviteDelete: {
170
- /** The code of the invite (`discord.gg/code`). */
171
- code: string;
320
+ /** The invite that was deleted. */
321
+ invite: DeletedInvite;
172
322
  /** The server the invite led to. */
173
323
  guild: Guild;
174
- /** The channel the invite led to. */
175
- channel: GuildChannel;
176
324
  };
177
325
  /** Something was added to the audit log of a server. */
178
326
  auditLogEntryCreate: {
@@ -183,125 +331,43 @@ export interface EventContexts {
183
331
  };
184
332
  /** Someone added a reaction to a message. */
185
333
  reactionAdd: {
186
- /** The emoji of the reaction. */
187
- emoji: ReactionEmoji;
188
- /** Who reacted. */
189
- user: User;
190
- /** Who reacted, as a member of the server; `null` in a private message. */
191
- member: GuildMember | null;
192
- /** Whether it is a super reaction. */
193
- burst: boolean;
194
- /** The id of the message. */
195
- messageId: Snowflake;
196
- /** The message, when the bot remembers it. */
197
- message: Message | null;
198
- /** The id of who wrote the message, when Discord says it. */
199
- messageAuthorId: Snowflake | null;
200
- /** The id of the channel of the message. */
201
- channelId: Snowflake;
202
- /** The channel of the message, when the bot knows it. */
203
- channel: TextBasedChannel | null;
204
- /** The id of the server; `null` in a private message. */
205
- guildId: Snowflake | null;
334
+ /** The reaction that was added. */
335
+ reaction: AddedReaction;
206
336
  /** The server; `null` in a private message. */
207
337
  guild: Guild | null;
208
338
  };
209
339
  /** Someone removed their reaction from a message. */
210
340
  reactionRemove: {
211
- /** The emoji of the reaction. */
212
- emoji: ReactionEmoji;
213
- /** Who had reacted. */
214
- user: User;
215
- /** Who had reacted, as a member of the server, when the bot remembers it. */
216
- member: GuildMember | null;
217
- /** Whether it was a super reaction. */
218
- burst: boolean;
219
- /** The id of the message. */
220
- messageId: Snowflake;
221
- /** The message, when the bot remembers it. */
222
- message: Message | null;
223
- /** The id of the channel of the message. */
224
- channelId: Snowflake;
225
- /** The channel of the message, when the bot knows it. */
226
- channel: TextBasedChannel | null;
227
- /** The id of the server; `null` in a private message. */
228
- guildId: Snowflake | null;
341
+ /** The reaction that was removed. */
342
+ reaction: UserReaction;
229
343
  /** The server; `null` in a private message. */
230
344
  guild: Guild | null;
231
345
  };
232
346
  /** The reactions of a message were removed: all of them, or every reaction of one emoji. */
233
347
  reactionClear: {
234
- /** The emoji whose reactions were removed; `null` when all were. */
235
- emoji: ReactionEmoji | null;
236
- /** The id of the message. */
237
- messageId: Snowflake;
238
- /** The message, when the bot remembers it. */
239
- message: Message | null;
240
- /** The id of the channel of the message. */
241
- channelId: Snowflake;
242
- /** The channel of the message, when the bot knows it. */
243
- channel: TextBasedChannel | null;
244
- /** The id of the server; `null` in a private message. */
245
- guildId: Snowflake | null;
348
+ /** The reactions that were removed. */
349
+ reactions: ClearedReactions;
246
350
  /** The server; `null` in a private message. */
247
351
  guild: Guild | null;
248
352
  };
249
353
  /** Someone voted in a poll. */
250
354
  pollVoteAdd: {
251
- /** The id Discord gave to the answer they voted for: today, its position in the poll, `1` for the first answer. */
252
- answerId: number;
253
- /** Who voted. */
254
- user: User;
255
- /** Who voted, as a member of the server, when the bot remembers it. */
256
- member: GuildMember | null;
257
- /** The id of the message of the poll. */
258
- messageId: Snowflake;
259
- /** The message of the poll, when the bot remembers it. */
260
- message: Message | null;
261
- /** The id of the channel of the poll. */
262
- channelId: Snowflake;
263
- /** The channel of the poll, when the bot knows it. */
264
- channel: TextBasedChannel | null;
265
- /** The id of the server; `null` in a private message. */
266
- guildId: Snowflake | null;
355
+ /** The vote. */
356
+ vote: PollVote;
267
357
  /** The server; `null` in a private message. */
268
358
  guild: Guild | null;
269
359
  };
270
360
  /** Someone took back their vote in a poll. */
271
361
  pollVoteRemove: {
272
- /** The id Discord gave to the answer they no longer vote for: today, its position in the poll, `1` for the first answer. */
273
- answerId: number;
274
- /** Who had voted. */
275
- user: User;
276
- /** Who had voted, as a member of the server, when the bot remembers it. */
277
- member: GuildMember | null;
278
- /** The id of the message of the poll. */
279
- messageId: Snowflake;
280
- /** The message of the poll, when the bot remembers it. */
281
- message: Message | null;
282
- /** The id of the channel of the poll. */
283
- channelId: Snowflake;
284
- /** The channel of the poll, when the bot knows it. */
285
- channel: TextBasedChannel | null;
286
- /** The id of the server; `null` in a private message. */
287
- guildId: Snowflake | null;
362
+ /** The vote taken back. */
363
+ vote: PollVote;
288
364
  /** The server; `null` in a private message. */
289
365
  guild: Guild | null;
290
366
  };
291
367
  /** Someone started typing in a channel. */
292
368
  typingStart: {
293
- /** Who is typing. */
294
- user: User;
295
- /** Who is typing, as a member of the server; `null` in a private message. */
296
- member: GuildMember | null;
297
- /** When they started. */
298
- startedAt: Date;
299
- /** The id of the channel. */
300
- channelId: Snowflake;
301
- /** The channel, when the bot knows it. */
302
- channel: TextBasedChannel | null;
303
- /** The id of the server; `null` in a private message. */
304
- guildId: Snowflake | null;
369
+ /** Who is typing, and where. */
370
+ typing: Typing;
305
371
  /** The server; `null` in a private message. */
306
372
  guild: Guild | null;
307
373
  };
@@ -311,8 +377,6 @@ export interface EventContexts {
311
377
  thread: ThreadChannel;
312
378
  /** Who was added, as a member of the server. */
313
379
  member: GuildMember;
314
- /** The account of who was added. */
315
- user: User;
316
380
  /** The server of the thread. */
317
381
  guild: Guild;
318
382
  };
@@ -322,8 +386,6 @@ export interface EventContexts {
322
386
  thread: ThreadChannel;
323
387
  /** The id of who was removed. */
324
388
  userId: Snowflake;
325
- /** The account of who was removed, when the bot knows it. */
326
- user: User | null;
327
389
  /** Who was removed, as a member of the server, when the bot remembers it. */
328
390
  member: GuildMember | null;
329
391
  /** The server of the thread. */
@@ -331,62 +393,36 @@ export interface EventContexts {
331
393
  };
332
394
  /** Someone joined a voice channel. */
333
395
  voiceJoin: {
334
- /** Who joined. */
335
- member: GuildMember;
336
- /** The channel they joined. */
337
- channel: VoiceChannel;
338
- /** Their voice state: muted, deafened, streaming... */
339
- voice: VoiceState;
396
+ /** Who joined, the channel, and their voice state. */
397
+ voice: VoiceActivity;
340
398
  /** The server of the channel. */
341
399
  guild: Guild;
342
400
  };
343
401
  /** Someone left a voice channel, or was disconnected. */
344
402
  voiceLeave: {
345
- /** Who left. */
346
- member: GuildMember;
347
- /** The channel they left. */
348
- channel: VoiceChannel;
349
- /** Their voice state as it was, in that channel. */
350
- voice: VoiceState;
403
+ /** Who left, the channel they left, and their voice state as it was. */
404
+ voice: VoiceActivity;
351
405
  /** The server of the channel. */
352
406
  guild: Guild;
353
407
  };
354
408
  /** Someone went from one voice channel to another, or was moved. */
355
409
  voiceMove: {
356
- /** Who moved. */
357
- member: GuildMember;
358
- /** The channel they left. */
359
- from: VoiceChannel;
360
- /** The channel they are in now. */
361
- to: VoiceChannel;
362
- /** Their voice state, as it is now. */
363
- voice: VoiceState;
410
+ /** Who moved, from where, to where. */
411
+ voice: VoiceMove;
364
412
  /** The server of the channels. */
365
413
  guild: Guild;
366
414
  };
367
415
  /** Someone in a voice channel changed: muted, deafened, started a stream or a camera... */
368
416
  voiceUpdate: {
369
- /** Who changed. */
370
- member: GuildMember;
371
- /** The channel they are in. */
372
- channel: VoiceChannel;
373
- /** Their voice state, as it is now. */
374
- voice: VoiceState;
375
- /** Their voice state as it was. */
376
- before: VoiceState;
417
+ /** Who changed, their voice state now and before. */
418
+ voice: VoiceChange;
377
419
  /** The server of the channel. */
378
420
  guild: Guild;
379
421
  };
380
422
  /** Someone's status or activity changed: online, idle, playing a game... */
381
423
  presenceUpdate: {
382
- /** The id of whose presence changed. */
383
- userId: Snowflake;
384
- /** The account of whose presence changed, when the bot knows it. */
385
- user: User | null;
386
- /** Whose presence changed, as a member of the server, when the bot remembers it. */
387
- member: GuildMember | null;
388
- /** Their status, activities and devices, as they are now. */
389
- presence: UserPresence;
424
+ /** The presence as it is now, and whose it is. */
425
+ presence: PresenceChange;
390
426
  /** The server the change is seen from. */
391
427
  guild: Guild;
392
428
  };
@@ -413,23 +449,15 @@ export interface EventContexts {
413
449
  };
414
450
  /** Someone said they are interested in a scheduled event. */
415
451
  scheduledEventUserAdd: {
416
- /** The id of the scheduled event. */
417
- scheduledEventId: Snowflake;
418
- /** Who is interested. */
419
- user: User;
420
- /** Who is interested, as a member of the server, when the bot remembers it. */
421
- member: GuildMember | null;
452
+ /** Who is interested, in which scheduled event. */
453
+ interest: ScheduledEventInterest;
422
454
  /** The server of the scheduled event. */
423
455
  guild: Guild;
424
456
  };
425
457
  /** Someone is no longer interested in a scheduled event. */
426
458
  scheduledEventUserRemove: {
427
- /** The id of the scheduled event. */
428
- scheduledEventId: Snowflake;
429
- /** Who is no longer interested. */
430
- user: User;
431
- /** Who is no longer interested, as a member of the server, when the bot remembers it. */
432
- member: GuildMember | null;
459
+ /** Who is no longer interested, in which scheduled event. */
460
+ interest: ScheduledEventInterest;
433
461
  /** The server of the scheduled event. */
434
462
  guild: Guild;
435
463
  };
@@ -493,88 +521,67 @@ type IsOn<Options, Key extends string> = Key extends keyof Options ? Exclude<Opt
493
521
  * it says nothing, every place it may be when it is only known to be one.
494
522
  */
495
523
  type WhereOf<Options> = 'where' extends keyof Options ? [Exclude<Options['where'], undefined>] extends [never] ? 'guild' : Exclude<Options['where'], undefined> : 'guild';
496
- /** A message of a server: its author is a member unless bots are let in. */
497
- type ServerMessage<Options> = IsOn<Options, 'bots'> extends true ? GuildMessage : MemberMessage;
498
- /** The message a file receives: what its options let through. */
499
- type MessageFor<Options, Where = WhereOf<Options>> = Where extends 'guild' ? ServerMessage<Options> : Where extends 'dm' ? DmMessage : ServerMessage<Options> | PrivateMessage;
500
- type Deleted = Omit<EventContexts['messageDelete'], 'guildId' | 'guild' | 'channel' | 'message'>;
501
- /** A message deleted in a server. */
502
- interface DeletedInGuild extends Deleted {
503
- /** The id of the server. */
504
- guildId: Snowflake;
505
- /** The server the message was in. */
506
- guild: Guild;
507
- /** The channel the message was in. */
508
- channel: GuildTextBasedChannel;
509
- /** The message as it was, when the bot remembered it. */
510
- message: GuildMessage | null;
511
- }
512
- /** A private message deleted, for a file that receives both kinds. */
513
- interface DeletedInPrivate extends Deleted {
514
- /** No server: the message was private. */
515
- guildId: null;
516
- /** No server: the message was private. */
517
- guild: null;
518
- /** The private conversation, when the bot knows it. */
519
- channel: DMChannel | null;
520
- /** The message as it was, when the bot remembered it. */
521
- message: PrivateMessage | null;
522
- }
523
- /** A private message deleted, for a file that only receives those. */
524
- interface DeletedInDm extends Deleted {
525
- /** The private conversation, when the bot knows it. */
526
- channel: DMChannel | null;
527
- /** The message as it was, when the bot remembered it. */
528
- message: DmMessage | null;
529
- }
530
- type DeletedFor<Where> = Where extends 'guild' ? DeletedInGuild : Where extends 'dm' ? DeletedInDm : DeletedInGuild | DeletedInPrivate;
531
- /** Where something happened in a server: the server and the channel are there. */
532
- interface ServerPlace {
524
+ /**
525
+ * Something about a message, told apart by where it happened: in a server
526
+ * the server is there and the channel is one of the server; in private,
527
+ * the conversation, when the bot knows it.
528
+ */
529
+ interface InServer {
533
530
  /** The id of the server. */
534
531
  guildId: Snowflake;
535
- /** The server. */
536
- guild: Guild;
537
532
  /** The channel. */
538
533
  channel: GuildTextBasedChannel;
539
534
  }
540
- /** Where something happened in private, for a file that receives both kinds. */
541
- interface PrivatePlace {
535
+ /** In private, for a file that receives both kinds. */
536
+ interface InPrivate {
542
537
  /** No server: it happened in private. */
543
538
  guildId: null;
544
- /** No server: it happened in private. */
545
- guild: null;
546
539
  /** The private conversation, when the bot knows it. */
547
540
  channel: DMChannel | null;
548
541
  }
549
- /** Where something happened in private, for a file that only receives that. */
550
- interface DmPlace {
542
+ /** In private, for a file that only receives that. */
543
+ interface InDm {
551
544
  /** The private conversation, when the bot knows it. */
552
545
  channel: DMChannel | null;
553
546
  }
554
- /** The message of something that happened in a server. */
547
+ /** The fields of an object that its place narrows. */
548
+ type PlaceKeys = 'guildId' | 'channel' | 'message' | 'member' | 'before';
549
+ /** `T` without what its place narrows: the rest is the same everywhere. */
550
+ type Unplaced<T> = Omit<T, PlaceKeys>;
551
+ /**
552
+ * What a file receives for an event of servers and private messages,
553
+ * following where it listens: the object of the event under `Key`, and
554
+ * the server when there is one. With `'both'`, a union told apart by
555
+ * `guild`.
556
+ */
557
+ type Placed<Where, Key extends string, InGuild, Private, Dm> = Where extends 'guild' ? {
558
+ [K in Key]: InGuild;
559
+ } & {
560
+ guild: Guild;
561
+ } : Where extends 'dm' ? {
562
+ [K in Key]: Dm;
563
+ } : ({
564
+ [K in Key]: InGuild;
565
+ } & {
566
+ guild: Guild;
567
+ }) | ({
568
+ [K in Key]: Private;
569
+ } & {
570
+ guild: null;
571
+ });
572
+ /** A message the bot remembers, in each place. */
555
573
  interface ServerMessagePart {
556
574
  /** The message, when the bot remembers it. */
557
575
  message: GuildMessage | null;
558
576
  }
559
- /** The message of something that happened in private, for both kinds. */
560
577
  interface PrivateMessagePart {
561
578
  /** The message, when the bot remembers it. */
562
579
  message: PrivateMessage | null;
563
580
  }
564
- /** The message of something that happened in private, for that only. */
565
581
  interface DmMessagePart {
566
582
  /** The message, when the bot remembers it. */
567
583
  message: DmMessage | null;
568
584
  }
569
- /** The fields an event of servers and private messages narrows. */
570
- type PlaceKeys = 'guildId' | 'guild' | 'channel' | 'message' | 'member';
571
- /**
572
- * What a file receives for an event of servers and private messages,
573
- * following where it listens: the same fields, plus what each place has.
574
- */
575
- type Placed<Where, Common, InServer, InPrivate, InDm> = Where extends 'guild' ? Common & InServer : Where extends 'dm' ? Common & InDm : (Common & InServer) | (Common & InPrivate);
576
- /** An event about a message, with or without the member who did it. */
577
- type OnMessage<Name extends EventName, Options, Member> = Placed<WhereOf<Options>, Omit<EventContexts[Name], PlaceKeys>, ServerPlace & ServerMessagePart & Member, PrivatePlace & PrivateMessagePart & ([keyof Member] extends [never] ? object : NoMember), DmPlace & DmMessagePart>;
578
585
  /** No member in private: who did it is `user`. */
579
586
  interface NoMember {
580
587
  /** No member: it happened in private. */
@@ -590,24 +597,39 @@ interface KnownMember {
590
597
  /** Who did it, as a member of the server, when the bot remembers it. */
591
598
  member: GuildMember | null;
592
599
  }
600
+ /** An object about a message (a reaction, a vote), narrowed by where. */
601
+ type AboutMessage<Where, Key extends string, T, Member> = Placed<Where, Key, Unplaced<T> & InServer & ServerMessagePart & Member, Unplaced<T> & InPrivate & PrivateMessagePart & ([keyof Member] extends [never] ? object : NoMember), Unplaced<T> & InDm & DmMessagePart>;
602
+ /** A message of a server: its author is a member unless bots are let in. */
603
+ type ServerMessage<Options> = IsOn<Options, 'bots'> extends true ? GuildMessage : MemberMessage;
604
+ /** A message deleted in a server. */
605
+ interface DeletedInGuild extends Unplaced<DeletedMessage>, InServer {
606
+ /** The message as it was, when the bot remembered it. */
607
+ before: GuildMessage | null;
608
+ }
609
+ /** A private message deleted, for a file that receives both kinds. */
610
+ interface DeletedInPrivate extends Unplaced<DeletedMessage>, InPrivate {
611
+ /** The message as it was, when the bot remembered it. */
612
+ before: PrivateMessage | null;
613
+ }
614
+ /** A private message deleted, for a file that only receives those. */
615
+ interface DeletedInDm extends Unplaced<DeletedMessage>, InDm {
616
+ /** The message as it was, when the bot remembered it. */
617
+ before: DmMessage | null;
618
+ }
593
619
  /**
594
620
  * The events whose handler receives something more precise than
595
621
  * `EventContexts`, following where its file listens.
596
622
  */
597
623
  interface NarrowedContexts<Options> {
598
- messageCreate: {
599
- message: MessageFor<Options>;
600
- };
601
- messageUpdate: {
602
- message: MessageFor<Options>;
603
- };
604
- messageDelete: DeletedFor<WhereOf<Options>>;
605
- reactionAdd: OnMessage<'reactionAdd', Options, SentMember>;
606
- reactionRemove: OnMessage<'reactionRemove', Options, KnownMember>;
607
- reactionClear: OnMessage<'reactionClear', Options, object>;
608
- pollVoteAdd: OnMessage<'pollVoteAdd', Options, KnownMember>;
609
- pollVoteRemove: OnMessage<'pollVoteRemove', Options, KnownMember>;
610
- typingStart: Placed<WhereOf<Options>, Omit<EventContexts['typingStart'], PlaceKeys>, ServerPlace & SentMember, PrivatePlace & NoMember, DmPlace>;
624
+ messageCreate: Placed<WhereOf<Options>, 'message', ServerMessage<Options>, PrivateMessage, DmMessage>;
625
+ messageUpdate: Placed<WhereOf<Options>, 'message', ServerMessage<Options>, PrivateMessage, DmMessage>;
626
+ messageDelete: Placed<WhereOf<Options>, 'message', DeletedInGuild, DeletedInPrivate, DeletedInDm>;
627
+ reactionAdd: AboutMessage<WhereOf<Options>, 'reaction', AddedReaction, SentMember>;
628
+ reactionRemove: AboutMessage<WhereOf<Options>, 'reaction', UserReaction, KnownMember>;
629
+ reactionClear: AboutMessage<WhereOf<Options>, 'reactions', ClearedReactions, object>;
630
+ pollVoteAdd: AboutMessage<WhereOf<Options>, 'vote', PollVote, KnownMember>;
631
+ pollVoteRemove: AboutMessage<WhereOf<Options>, 'vote', PollVote, KnownMember>;
632
+ typingStart: Placed<WhereOf<Options>, 'typing', Unplaced<Typing> & InServer & SentMember, Unplaced<Typing> & InPrivate & NoMember, Unplaced<Typing> & InDm>;
611
633
  }
612
634
  /**
613
635
  * What your function receives for an event, given the options its file passed