nuxt-discord 0.0.9 → 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.d.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
+ import * as __runtime_logger from '../dist/runtime/logger.js';
2
3
  import * as _nuxt_kit from '@nuxt/kit';
3
4
  import * as nuxt_schema from 'nuxt/schema';
4
5
  import { DiscordClient } from '/Users/jeffz/Dev/nuxt-discord/dist/runtime/server/utils/client.js';
@@ -6,12 +7,6 @@ import { IntegerOption, NumberOption, StringOption } from '../dist/runtime/serve
6
7
  import { ClientOptions, ApplicationCommandOptionType, ChatInputCommandInteraction } from 'discord.js';
7
8
  import { ListenOptions } from 'listhen';
8
9
 
9
- declare const logger: {
10
- log: (...args: unknown[]) => void;
11
- warn: (...args: unknown[]) => void;
12
- error: (...args: unknown[]) => void;
13
- };
14
-
15
10
  interface NuxtDiscordOptions {
16
11
  /**
17
12
  * Options passed to the internal Discord client.
@@ -133,7 +128,7 @@ interface NuxtDiscordContext {
133
128
  root: _nuxt_kit.Resolver['resolve'];
134
129
  module: _nuxt_kit.Resolver['resolve'];
135
130
  };
136
- logger: typeof logger;
131
+ logger: typeof __runtime_logger.logger;
137
132
  }
138
133
 
139
134
  declare const _default: _nuxt_schema.NuxtModule<NuxtDiscordOptions, NuxtDiscordOptions, false>;
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-discord",
3
3
  "configKey": "discord",
4
- "version": "0.0.9",
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
@@ -1,6 +1,6 @@
1
1
  import { createResolver, installModule, extendPages, updateTemplates, addVitePlugin, isIgnored, addServerTemplate, addTemplate, addTypeTemplate, defineNuxtModule, addServerScanDir, addImports } from '@nuxt/kit';
2
2
  import { ApplicationCommandOptionType, GatewayIntentBits } from 'discord.js';
3
- import ansis from 'ansis';
3
+ import { logger } from '../dist/runtime/logger.js';
4
4
  import { globSync, readFileSync, existsSync, mkdirSync, writeFileSync } from 'node:fs';
5
5
  import path from 'node:path';
6
6
  import ts from 'typescript';
@@ -11,13 +11,6 @@ import { WebSocketServer } from 'ws';
11
11
  import defu from 'defu';
12
12
  import { genSafeVariableName, genImport, genArrayFromRaw, genString } from 'knitwork';
13
13
 
14
- const logger = {
15
- // eslint-disable-next-line no-console
16
- log: (...args) => console.log(ansis.hex("#5865F2").bold("[Discord]"), ...args),
17
- warn: (...args) => console.warn(ansis.yellow.bold("[Discord]"), ...args),
18
- error: (...args) => console.error(ansis.red.bold("[Discord]"), ...args)
19
- };
20
-
21
14
  function createContext(options, nuxt) {
22
15
  return {
23
16
  nuxt,
@@ -418,8 +411,8 @@ async function generateDynamicCommandBuild(file, config, ctx) {
418
411
  bundle = await rollup({
419
412
  ...config,
420
413
  input: file,
421
- // externalize all modules except the command file itself
422
- 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")
423
416
  });
424
417
  const { output } = await bundle.generate({ ...config.output, sourcemap: false });
425
418
  mkdirSync(path.join(ctx.nuxt.options.buildDir, "discord", "commands"), { recursive: true });
@@ -0,0 +1,5 @@
1
+ export declare const logger: {
2
+ log: (...args: unknown[]) => void;
3
+ warn: (...args: unknown[]) => void;
4
+ error: (...args: unknown[]) => void;
5
+ };
@@ -0,0 +1,7 @@
1
+ import ansis from "ansis";
2
+ export const logger = {
3
+ // eslint-disable-next-line no-console
4
+ log: (...args) => console.log(ansis.hex("#5865F2").bold("[Discord]"), ...args),
5
+ warn: (...args) => console.warn(ansis.yellow.bold("[Discord]"), ...args),
6
+ error: (...args) => console.error(ansis.red.bold("[Discord]"), ...args)
7
+ };
@@ -1,7 +1,7 @@
1
1
  import fs from "node:fs";
2
2
  import slashCommands from "discord/slashCommands";
3
3
  import { defineNitroPlugin, useRuntimeConfig } from "nitropack/runtime";
4
- import { logger } from "../../../logger";
4
+ import { logger } from "../../logger.js";
5
5
  import { DiscordClient } from "../utils/client.js";
6
6
  export default defineNitroPlugin(async (nitro) => {
7
7
  const runtimeConfig = useRuntimeConfig();
@@ -1,7 +1,7 @@
1
1
  import process from "node:process";
2
2
  import { ApplicationCommandOptionType, Events, Client as InternalClient, REST, Routes, SlashCommandBuilder } from "discord.js";
3
3
  import { useNitroApp } from "nitropack/runtime";
4
- import { logger } from "../../../logger";
4
+ import { logger } from "../../logger.js";
5
5
  let currentInteraction = null;
6
6
  export function useInteraction() {
7
7
  return currentInteraction;
@@ -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.9",
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",