@dressed/react 1.7.1 → 1.7.3

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.
@@ -1,41 +1,12 @@
1
- import { type APIInteractionResponseCallbackData, type APIModalInteractionResponseCallbackData, type ApplicationCommandType } from "discord-api-types/v10";
2
- import type { CommandConfig, CommandInteraction as DressedCommandInteraction, MessageComponentInteraction as DressedMessageComponentInteraction, ModalSubmitInteraction as DressedModalSubmitInteraction } from "dressed";
3
- import type { createInteraction, RawFile } from "dressed/server";
1
+ import { type ApplicationCommandType } from "discord-api-types/v10";
2
+ import { type CommandConfig, type CommandInteraction as DressedCommandInteraction, type MessageComponentInteraction as DressedMessageComponentInteraction, type ModalSubmitInteraction as DressedModalSubmitInteraction } from "dressed";
3
+ import type { createInteraction } from "dressed/server";
4
4
  import type { ReactNode } from "react";
5
- type ReplyProps = [
6
- components: ReactNode,
7
- data?: Omit<APIInteractionResponseCallbackData, "content"> & {
8
- /** Whether the message is ephemeral */
9
- ephemeral?: boolean;
10
- /** The files to send with the message */
11
- files?: RawFile[];
12
- /** Whether to return the source message with the response */
13
- with_response?: boolean;
14
- }
15
- ];
16
- type EditReplyProps = [
17
- components: ReactNode,
18
- data?: Omit<APIInteractionResponseCallbackData, "content"> & {
19
- /** The files to send with the message */
20
- files?: RawFile[];
21
- }
22
- ];
23
- type FollowUpProps = [
24
- components: ReactNode,
25
- data?: Omit<APIInteractionResponseCallbackData, "content"> & {
26
- /** The files to send with the message */
27
- files?: RawFile[];
28
- /** Whether the message is ephemeral */
29
- ephemeral?: boolean;
30
- }
31
- ];
32
- type ShowModalProps = [components: ReactNode, data: Omit<APIModalInteractionResponseCallbackData, "components">];
33
5
  type ReactivatedInteraction<T> = OverrideMethodParams<T, {
34
- reply: ReplyProps;
35
- editReply: EditReplyProps;
36
- update: EditReplyProps;
37
- followUp: FollowUpProps;
38
- showModal: ShowModalProps;
6
+ [K in "reply" | "editReply" | "update" | "followUp" | "showModal"]: [
7
+ components: ReactNode,
8
+ ...(Parameters<T[K]> extends readonly [infer First, ...infer Rest] ? [Omit<Exclude<First, string>, "content" | "components">, ...Rest] : never)
9
+ ];
39
10
  }>;
40
11
  type OverrideMethodParams<T, Overrides extends Record<string, unknown[]>> = {
41
12
  [K in keyof T]: K extends keyof Overrides ? T[K] extends (...args: any) => any ? (...args: Overrides[K]) => ReturnType<T[K]> : T[K] : T[K];
@@ -1,4 +1,5 @@
1
- import { MessageFlags, } from "discord-api-types/v10";
1
+ import { MessageFlags } from "discord-api-types/v10";
2
+ import { editWebhookMessage, } from "dressed";
2
3
  import { render } from "./index.js";
3
4
  export function patchInteraction(interaction) {
4
5
  if (!interaction)
@@ -11,16 +12,23 @@ export function patchInteraction(interaction) {
11
12
  if (!(method in interaction))
12
13
  continue;
13
14
  const original = interaction[method];
14
- newInteraction[method] = (components, data = {}) => {
15
+ newInteraction[method] = (...[components, originalData = {}, $req]) => {
15
16
  var _a;
16
- data.flags = ((_a = data.flags) !== null && _a !== void 0 ? _a : 0) | MessageFlags.IsComponentsV2;
17
- const { promise, resolve } = Promise.withResolvers();
18
- render(components, (c) => {
19
- data.components = c;
20
- const didRespond = interaction.history.some((h) => ["reply", "deferReply", "update", "deferUpdate"].includes(h));
21
- resolve((didRespond ? editReply : original)(data));
17
+ originalData.flags = ((_a = originalData.flags) !== null && _a !== void 0 ? _a : 0) | MessageFlags.IsComponentsV2;
18
+ return new Promise((resolve) => {
19
+ let followUpId;
20
+ render(components, async (c) => {
21
+ const data = { ...originalData, components: c };
22
+ if (followUpId) {
23
+ return editWebhookMessage(interaction.application_id, interaction.token, followUpId, data, undefined, $req);
24
+ }
25
+ const shouldEdit = (method === "reply" || method === "update") && interaction.history.includes(method);
26
+ const res = await (shouldEdit ? editReply : original)(data, $req);
27
+ if (method === "followUp")
28
+ followUpId = res.id;
29
+ resolve(res);
30
+ });
22
31
  });
23
- return promise;
24
32
  };
25
33
  }
26
34
  return newInteraction;
@@ -1 +1 @@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AE,CAAC,EAAE,EAAE;oBAC7B,MAAM,IAAI,GAAG,EAAE,GAAG,YAAY,EAAE,UAAU,EAAE,CAAkC,EAAE,CAAC;oBACjF,IAAI,UAAU,EAAE,CAAC;wBACf,OAAO,kBAAkB,CAAC,WAAW,CAAC,cAAc,EAAE,WAAW,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;oBAC9G,CAAC;oBACD,MAAM,UAAU,GAAG,CAAC,MAAM,KAAK,OAAO,IAAI,MAAM,KAAK,QAAQ,CAAC,IAAI,WAAW,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;oBACvG,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;oBAClE,IAAI,MAAM,KAAK,UAAU;wBAAE,UAAU,GAAG,GAAG,CAAC,EAAE,CAAC;oBAC/C,OAAO,CAAC,GAAG,CAAC,CAAC;gBACf,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;IACJ,CAAC;IACD,OAAO,cAAc,CAAC;AACxB,CAAC"}
@@ -8,18 +8,18 @@ import { render } from "./index.js";
8
8
  export async function createMessage(channelId, components, data = {}) {
9
9
  var _a;
10
10
  data.flags = ((_a = data.flags) !== null && _a !== void 0 ? _a : 0) | MessageFlags.IsComponentsV2;
11
- const { promise, resolve } = Promise.withResolvers();
12
11
  let messageId;
13
- render(components, async (c) => {
14
- data.components = c;
15
- if (messageId) {
16
- return dressedEditMessage(channelId, messageId, data);
17
- }
18
- const message = await dressedCreateMessage(channelId, data);
19
- messageId = message.id;
20
- resolve(message);
12
+ return new Promise((resolve) => {
13
+ render(components, async (c) => {
14
+ data.components = c;
15
+ if (messageId) {
16
+ return dressedEditMessage(channelId, messageId, data);
17
+ }
18
+ const message = await dressedCreateMessage(channelId, data);
19
+ messageId = message.id;
20
+ resolve(message);
21
+ });
21
22
  });
22
- return promise;
23
23
  }
24
24
  /**
25
25
  * Renders the provided children and edits a previously sent message.
@@ -28,11 +28,11 @@ export async function createMessage(channelId, components, data = {}) {
28
28
  export async function editMessage(channelId, messageId, components, data = {}) {
29
29
  var _a;
30
30
  data.flags = ((_a = data.flags) !== null && _a !== void 0 ? _a : 0) | MessageFlags.IsComponentsV2;
31
- const { promise, resolve } = Promise.withResolvers();
32
- render(components, async (c) => {
33
- data.components = c;
34
- resolve(dressedEditMessage(channelId, messageId, data));
31
+ return new Promise((resolve) => {
32
+ render(components, async (c) => {
33
+ data.components = c;
34
+ resolve(dressedEditMessage(channelId, messageId, data));
35
+ });
35
36
  });
36
- return promise;
37
37
  }
38
38
  //# sourceMappingURL=message.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"message.js","sourceRoot":"","sources":["../../src/rendering/message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoC,YAAY,EAAkB,MAAM,uBAAuB,CAAC;AACvG,OAAO,EAAE,aAAa,IAAI,oBAAoB,EAAE,WAAW,IAAI,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAEnG,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEpC;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,SAAoB,EACpB,UAAqB,EACrB,OAAoE,EAAE;;IAEtE,IAAI,CAAC,KAAK,GAAG,CAAC,MAAA,IAAI,CAAC,KAAK,mCAAI,CAAC,CAAC,GAAG,YAAY,CAAC,cAAc,CAAC;IAE7D,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IACrD,IAAI,SAAiB,CAAC;IAEtB,MAAM,CAAC,UAAU,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;QAC7B,IAAI,CAAC,UAAU,GAAG,CAAkC,CAAC;QACrD,IAAI,SAAS,EAAE,CAAC;YACd,OAAO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"git+https://github.com/Inbestigator/dressed.git",