nuxt-discord 0.0.10 → 0.0.11

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.
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-discord",
3
3
  "configKey": "discord",
4
- "version": "0.0.10",
4
+ "version": "0.0.11",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.1",
7
7
  "unbuild": "3.5.0"
package/dist/module.mjs CHANGED
@@ -411,8 +411,8 @@ async function generateDynamicCommandBuild(file, config, ctx) {
411
411
  bundle = await rollup({
412
412
  ...config,
413
413
  input: file,
414
- // externalize all modules except the command file itself
415
- external: (id) => !id.includes(file)
414
+ // externalize all modules except the command file itself, excluding .ts files
415
+ external: (id) => !id.includes(file) && !id.endsWith(".ts")
416
416
  });
417
417
  const { output } = await bundle.generate({ ...config.output, sourcemap: false });
418
418
  mkdirSync(path.join(ctx.nuxt.options.buildDir, "discord", "commands"), { recursive: true });
@@ -161,7 +161,11 @@ export class DiscordClient {
161
161
  }
162
162
  try {
163
163
  if (typeof result === "string") {
164
- return interaction.reply({ content: result });
164
+ if (interaction.deferred) {
165
+ return interaction.editReply({ content: result });
166
+ } else {
167
+ return interaction.reply({ content: result });
168
+ }
165
169
  } else if (typeof result === "function") {
166
170
  const newResult = result.call(this, interaction, this);
167
171
  return this.#handleSlashCommandReturn(newResult, interaction, command);
@@ -1,9 +1,15 @@
1
- import type { InteractionReplyOptions } from 'discord.js';
1
+ import type { InteractionEditReplyOptions, InteractionReplyOptions } from 'discord.js';
2
2
  import type { SlashCommandCustomReturnHandler } from '~/src/types';
3
+ type OmitPreservingCallSignature<T, K extends keyof T = keyof T> = Omit<T, K> & (T extends (...args: infer R) => infer S ? (...args: R) => S : unknown);
3
4
  interface ReplyFunction {
4
5
  (text: string, options?: InteractionReplyOptions): SlashCommandCustomReturnHandler;
5
- ephemeral: this;
6
- flags: (flags: InteractionReplyOptions['flags']) => this;
6
+ edit: EditReplyFunction;
7
+ ephemeral: OmitPreservingCallSignature<ReplyFunction, 'edit' | 'ephemeral'>;
8
+ flags: (flags: InteractionReplyOptions['flags']) => OmitPreservingCallSignature<ReplyFunction, 'edit'>;
9
+ }
10
+ interface EditReplyFunction {
11
+ (text: string, options?: InteractionEditReplyOptions): SlashCommandCustomReturnHandler;
12
+ flags: (flags: InteractionEditReplyOptions['flags']) => EditReplyFunction;
7
13
  }
8
14
  export declare const reply: ReplyFunction;
9
15
  export {};
@@ -1,27 +1,46 @@
1
1
  import { MessageFlags } from "discord.js";
2
- function createReplyFunction(defaultOptions = {}) {
3
- const reply2 = (text, options) => (interaction) => {
4
- interaction.reply({
5
- content: text,
6
- ...defaultOptions,
7
- ...options
8
- });
2
+ function createReplyFunction({ editReply, ...defaultOptions } = {}) {
3
+ const reply2 = (text, options) => async (interaction) => {
4
+ if (editReply) {
5
+ await interaction.editReply({
6
+ content: text,
7
+ ...defaultOptions,
8
+ ...options
9
+ });
10
+ } else {
11
+ await interaction.reply({
12
+ content: text,
13
+ ...defaultOptions,
14
+ ...options
15
+ });
16
+ }
9
17
  };
10
- return new Proxy(reply2, {
11
- get(target, prop, receiver) {
12
- if (prop === "ephemeral") {
18
+ Object.defineProperties(reply2, {
19
+ ephemeral: {
20
+ get() {
13
21
  return createReplyFunction({
14
22
  ...defaultOptions,
15
23
  flags: defaultOptions.flags == null ? MessageFlags.Ephemeral : typeof defaultOptions.flags === "string" ? [defaultOptions.flags, "Ephemeral"] : Array.isArray(defaultOptions.flags) ? [...defaultOptions.flags, "Ephemeral"] : typeof defaultOptions.flags === "number" || typeof defaultOptions.flags === "bigint" ? defaultOptions.flags | MessageFlags.Ephemeral : MessageFlags.Ephemeral
16
24
  });
17
- } else if (prop === "flags") {
25
+ }
26
+ },
27
+ flags: {
28
+ get() {
18
29
  return (flags) => createReplyFunction({
19
30
  ...defaultOptions,
20
31
  flags
21
32
  });
22
33
  }
23
- return Reflect.get(target, prop, receiver);
34
+ },
35
+ edit: {
36
+ get() {
37
+ return createReplyFunction({
38
+ ...defaultOptions,
39
+ editReply: true
40
+ });
41
+ }
24
42
  }
25
43
  });
44
+ return reply2;
26
45
  }
27
46
  export const reply = createReplyFunction();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-discord",
3
3
  "type": "module",
4
- "version": "0.0.10",
4
+ "version": "0.0.11",
5
5
  "description": "A Nuxt module for building Discord bots",
6
6
  "author": "Jize Zou <jeffzou2001@gmail.com> (https://github.com/zojize)",
7
7
  "license": "MIT",