chapterjs 0.2.3 → 0.4.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 (87) hide show
  1. package/README.md +65 -0
  2. package/dist/cli/build.js +14 -1
  3. package/dist/cli/cli.js +41 -6
  4. package/dist/cli/dev.js +29 -1
  5. package/dist/cli/env.d.ts +5 -0
  6. package/dist/cli/env.js +39 -3
  7. package/dist/cli/project.d.ts +49 -7
  8. package/dist/cli/project.js +103 -19
  9. package/dist/cli/redis.d.ts +23 -0
  10. package/dist/cli/redis.js +57 -0
  11. package/dist/cli/start.js +43 -17
  12. package/dist/cli/test.d.ts +29 -0
  13. package/dist/cli/test.js +446 -0
  14. package/dist/commands/autocomplete.d.ts +1 -1
  15. package/dist/commands/autocomplete.js +37 -41
  16. package/dist/commands/router.d.ts +4 -1
  17. package/dist/commands/router.js +15 -17
  18. package/dist/components/router.d.ts +7 -2
  19. package/dist/components/router.js +16 -16
  20. package/dist/discord/types/channel.d.ts +9 -1
  21. package/dist/discord/types/guild.d.ts +5 -5
  22. package/dist/discord/types/permissions.d.ts +6 -0
  23. package/dist/discord/types/poll.d.ts +7 -1
  24. package/dist/events/registry.d.ts +252 -239
  25. package/dist/events/registry.js +125 -100
  26. package/dist/events/router.d.ts +9 -4
  27. package/dist/events/router.js +24 -11
  28. package/dist/index.d.ts +4 -2
  29. package/dist/index.js +1 -0
  30. package/dist/interactions/dispatch.d.ts +5 -1
  31. package/dist/interactions/dispatch.js +6 -2
  32. package/dist/loader/hot.js +22 -2
  33. package/dist/loader/loader.d.ts +7 -0
  34. package/dist/loader/loader.js +22 -12
  35. package/dist/ranking/declaration.d.ts +12 -0
  36. package/dist/ranking/declaration.js +48 -0
  37. package/dist/ranking/ranking.d.ts +102 -0
  38. package/dist/ranking/ranking.js +129 -0
  39. package/dist/redis/client.d.ts +36 -0
  40. package/dist/redis/client.js +252 -0
  41. package/dist/redis/protocol.d.ts +22 -0
  42. package/dist/redis/protocol.js +99 -0
  43. package/dist/redis/url.d.ts +24 -0
  44. package/dist/redis/url.js +50 -0
  45. package/dist/store/backend.d.ts +49 -4
  46. package/dist/store/backend.js +66 -11
  47. package/dist/store/declaration.d.ts +3 -0
  48. package/dist/store/declaration.js +8 -3
  49. package/dist/store/file-backend.d.ts +3 -1
  50. package/dist/store/file-backend.js +29 -0
  51. package/dist/store/ipc-backend.d.ts +24 -1
  52. package/dist/store/ipc-backend.js +49 -0
  53. package/dist/store/memory-backend.d.ts +17 -0
  54. package/dist/store/memory-backend.js +82 -0
  55. package/dist/store/ranking-backend.d.ts +45 -0
  56. package/dist/store/ranking-backend.js +82 -0
  57. package/dist/store/redis-backend.d.ts +38 -0
  58. package/dist/store/redis-backend.js +245 -0
  59. package/dist/store/redis-ranking.d.ts +15 -0
  60. package/dist/store/redis-ranking.js +69 -0
  61. package/dist/store/scope.d.ts +11 -0
  62. package/dist/store/scope.js +23 -0
  63. package/dist/store/store.d.ts +39 -5
  64. package/dist/store/store.js +83 -33
  65. package/dist/structures/invite.d.ts +6 -0
  66. package/dist/structures/invite.js +11 -0
  67. package/dist/tasks/scheduler.d.ts +6 -0
  68. package/dist/tasks/scheduler.js +9 -3
  69. package/dist/testing/failure.d.ts +9 -0
  70. package/dist/testing/failure.js +20 -0
  71. package/dist/testing/fake-discord.d.ts +59 -0
  72. package/dist/testing/fake-discord.js +120 -0
  73. package/dist/testing/fake-gateway.d.ts +59 -0
  74. package/dist/testing/fake-gateway.js +123 -0
  75. package/dist/testing/harness.d.ts +387 -0
  76. package/dist/testing/harness.js +1418 -0
  77. package/dist/testing/index.d.ts +4 -0
  78. package/dist/testing/index.js +5 -0
  79. package/dist/testing/scenario.d.ts +39 -0
  80. package/dist/testing/scenario.js +58 -0
  81. package/dist/testing/smoke.d.ts +20 -0
  82. package/dist/testing/smoke.js +659 -0
  83. package/dist/testing/websocket.d.ts +34 -0
  84. package/dist/testing/websocket.js +167 -0
  85. package/dist/testing/world.d.ts +145 -0
  86. package/dist/testing/world.js +1479 -0
  87. package/package.json +20 -3
@@ -14,6 +14,11 @@ export declare class ComponentRouter {
14
14
  constructor(options: ComponentRouterOptions);
15
15
  /** Replaces every component (after a load or a reload). */
16
16
  set(entries: Iterable<ComponentEntry>): void;
17
- /** Handles an Interaction Create event, if it is a component or a form. */
18
- dispatch(ctx: Context, raw: RawInteraction): void;
17
+ /**
18
+ * Handles an Interaction Create event, if it is a component or a form.
19
+ * Returns a promise of everything being done (the function run, the
20
+ * person answered), or `null` when the interaction is not for this
21
+ * router. Nothing of the bot waits for it: `chapterjs test` does.
22
+ */
23
+ dispatch(ctx: Context, raw: RawInteraction): Promise<void> | null;
19
24
  }
@@ -33,18 +33,23 @@ export class ComponentRouter {
33
33
  }
34
34
  this.#components = components;
35
35
  }
36
- /** Handles an Interaction Create event, if it is a component or a form. */
36
+ /**
37
+ * Handles an Interaction Create event, if it is a component or a form.
38
+ * Returns a promise of everything being done (the function run, the
39
+ * person answered), or `null` when the interaction is not for this
40
+ * router. Nothing of the bot waits for it: `chapterjs test` does.
41
+ */
37
42
  dispatch(ctx, raw) {
38
43
  const isComponent = raw.type === InteractionType.MessageComponent;
39
44
  const isModal = raw.type === InteractionType.ModalSubmit;
40
45
  if (!isComponent && !isModal)
41
- return;
46
+ return null;
42
47
  const data = raw.data;
43
48
  if (!data || typeof data.custom_id !== 'string')
44
- return;
49
+ return null;
45
50
  const author = authorOf(raw);
46
51
  if (!author)
47
- return;
52
+ return null;
48
53
  const user = ctx.entities.user(author.user);
49
54
  const { user: _user, member: _member, message: rawMessage, ...rest } = raw;
50
55
  const message = rawMessage
@@ -79,7 +84,7 @@ export class ComponentRouter {
79
84
  message: message,
80
85
  });
81
86
  if (isComponent && !message)
82
- return;
87
+ return null;
83
88
  // Embeds are never in the map: what is left has a `run`.
84
89
  if (!entry ||
85
90
  entry.component.kind === 'embed' ||
@@ -87,27 +92,23 @@ export class ComponentRouter {
87
92
  SELECT_TYPES[entry.component.type] !==
88
93
  data.component_type)) {
89
94
  // Sent before the export was renamed, removed or changed of kind.
90
- refuse(interaction, 'gone', { what });
91
- return;
95
+ return refuse(interaction, 'gone', { what });
92
96
  }
93
97
  const { component, file } = entry;
94
98
  const values = readData(component.data, parts);
95
99
  if (!values) {
96
100
  // The data of the component changed since the message was sent.
97
- refuse(interaction, 'outdated', { what });
98
- return;
101
+ return refuse(interaction, 'outdated', { what });
99
102
  }
100
103
  const placed = resolvePlace(ctx, raw, user, author.member, component.where, warning => this.#options.onWarning(file, `${name} ${warning}`));
101
104
  if (!placed.place) {
102
- refuse(interaction, placed.refusal, { what });
103
- return;
105
+ return refuse(interaction, placed.refusal, { what });
104
106
  }
105
107
  const { place } = placed;
106
108
  if (component.kind !== 'modal' &&
107
109
  component.who === 'author' &&
108
110
  rawMessage?.interaction_metadata?.user.id !== user.id) {
109
- refuse(interaction, 'authorOnly', { what });
110
- return;
111
+ return refuse(interaction, 'authorOnly', { what });
111
112
  }
112
113
  remember(interaction, {
113
114
  guild: place.guild ?? undefined,
@@ -127,8 +128,7 @@ export class ComponentRouter {
127
128
  }
128
129
  catch (error) {
129
130
  this.#options.onError(file, error);
130
- refuse(interaction, 'failed', { what });
131
- return;
131
+ return refuse(interaction, 'failed', { what });
132
132
  }
133
133
  const context = Object.freeze({
134
134
  interaction,
@@ -144,7 +144,7 @@ export class ComponentRouter {
144
144
  ephemeral: ephemeralOf(component),
145
145
  })),
146
146
  });
147
- runInteraction({
147
+ return runInteraction({
148
148
  interaction,
149
149
  file,
150
150
  name,
@@ -251,6 +251,14 @@ export interface RawForumTag {
251
251
  /** the unicode character of the emoji * */
252
252
  emoji_name: string | null;
253
253
  }
254
+ /**
255
+ * A forum tag as a request gives it: a new tag has no `id` yet, an existing
256
+ * one keeps its own.
257
+ * @see https://docs.discord.com/developers/resources/channel#forum-tag-object
258
+ */
259
+ export type RawForumTagInput = Omit<RawForumTag, 'id'> & {
260
+ id?: Snowflake;
261
+ };
254
262
  /**
255
263
  * JSON Params (Group DM)
256
264
  * @see https://docs.discord.com/developers/resources/channel#modify-channel-json-params-group-dm
@@ -293,7 +301,7 @@ export interface ModifyGuildChannelJSONParams {
293
301
  /** channel flags combined as a bitfield. */
294
302
  flags?: number;
295
303
  /** the set of tags that can be used in a `GUILD_FORUM` or a `GUILD_MEDIA` channel; limited to 20 */
296
- available_tags?: RawForumTag[];
304
+ available_tags?: RawForumTagInput[];
297
305
  /** the emoji to show in the add reaction button on a thread in a `GUILD_FORUM` or a `GUILD_MEDIA` channel */
298
306
  default_reaction_emoji?: RawDefaultReaction | null;
299
307
  /** the initial `rate_limit_per_user` to set on newly created threads in a channel. this field is copied to the thread at creation time and does not live update. */
@@ -1,9 +1,9 @@
1
1
  import type { RawApplication } from './application.js';
2
- import type { ChannelType, ForumLayoutType, ForumSortOrderType, RawChannel, RawDefaultReaction, RawForumTag, RawPermissionOverwrite, RawThreadMember, VideoQualityMode } from './channel.js';
2
+ import type { ChannelType, ForumLayoutType, ForumSortOrderType, RawChannel, RawDefaultReaction, RawForumTagInput, RawPermissionOverwrite, RawThreadMember, VideoQualityMode } from './channel.js';
3
3
  import type { ISO8601Timestamp, ImageData, Locale, Snowflake } from './common.js';
4
4
  import type { RawEmoji } from './emoji.js';
5
5
  import type { OAuth2Scope } from './oauth2.js';
6
- import type { RawRole, RawRoleColors } from './permissions.js';
6
+ import type { RawRole, RawRoleColorsInput } from './permissions.js';
7
7
  import type { RawSticker } from './sticker.js';
8
8
  import type { RawAvatarDecorationData, RawCollectibles, RawUser } from './user.js';
9
9
  /**
@@ -605,7 +605,7 @@ export interface CreateGuildChannelJSONParams {
605
605
  /** emoji to show in the add reaction button on a thread in a `GUILD_FORUM` or a `GUILD_MEDIA` channel */
606
606
  default_reaction_emoji?: RawDefaultReaction | null;
607
607
  /** set of tags that can be used in a `GUILD_FORUM` or a `GUILD_MEDIA` channel */
608
- available_tags?: RawForumTag[] | null;
608
+ available_tags?: RawForumTagInput[] | null;
609
609
  /** the default sort order type used to order posts in `GUILD_FORUM` and `GUILD_MEDIA` channels */
610
610
  default_sort_order?: ForumSortOrderType | null;
611
611
  /** the default forum layout view used to display posts in `GUILD_FORUM` channels */
@@ -773,7 +773,7 @@ export interface CreateGuildRoleJSONParams {
773
773
  /** **Deprecated** RGB color value */
774
774
  color?: number;
775
775
  /** the role's colors */
776
- colors?: RawRoleColors;
776
+ colors?: RawRoleColorsInput;
777
777
  /** whether the role should be displayed separately in the sidebar */
778
778
  hoist?: boolean;
779
779
  /** the role's icon image (if the guild has the `ROLE_ICONS` feature) */
@@ -805,7 +805,7 @@ export interface ModifyGuildRoleJSONParams {
805
805
  /** **Deprecated** RGB color value */
806
806
  color?: number;
807
807
  /** the role's colors */
808
- colors?: RawRoleColors;
808
+ colors?: RawRoleColorsInput;
809
809
  /** whether the role should be displayed separately in the sidebar */
810
810
  hoist?: boolean;
811
811
  /** the role's icon image (if the guild has the `ROLE_ICONS` feature) */
@@ -172,6 +172,12 @@ export interface RawRoleColors {
172
172
  /** the tertiary color for the role, this will turn the gradient into a holographic style */
173
173
  tertiary_color: number | null;
174
174
  }
175
+ /**
176
+ * The colors of a role as a request gives them: only the primary color is
177
+ * needed, the two others make a gradient when given.
178
+ * @see https://docs.discord.com/developers/topics/permissions#role-object-role-colors-object
179
+ */
180
+ export type RawRoleColorsInput = Pick<RawRoleColors, 'primary_color'> & Partial<Omit<RawRoleColors, 'primary_color'>>;
175
181
  /**
176
182
  * Role Flags
177
183
  * @see https://docs.discord.com/developers/topics/permissions#role-object-role-flags
@@ -27,7 +27,7 @@ export interface RawPollCreateRequest {
27
27
  /** The question of the poll. Only `text` is supported. */
28
28
  question: RawPollMedia;
29
29
  /** Each of the answers available in the poll, up to 10 */
30
- answers: RawPollAnswer[];
30
+ answers: RawPollAnswerInput[];
31
31
  /** Number of hours the poll should be open for, up to 32 days. Defaults to 24 */
32
32
  duration?: number;
33
33
  /** Whether a user can select multiple answers. Defaults to false */
@@ -54,6 +54,12 @@ export interface RawPollMedia {
54
54
  /** The emoji of the field */
55
55
  emoji?: Partial<RawEmoji>;
56
56
  }
57
+ /**
58
+ * A poll answer as a request gives it: `answer_id` is only sent as part of
59
+ * responses from Discord's API/Gateway.
60
+ * @see https://docs.discord.com/developers/resources/poll#poll-answer-object-poll-answer-object-structure
61
+ */
62
+ export type RawPollAnswerInput = Omit<RawPollAnswer, 'answer_id'>;
57
63
  /**
58
64
  * Poll Answer Object Structure
59
65
  * @see https://docs.discord.com/developers/resources/poll#poll-answer-object-poll-answer-object-structure