@constatic/base 0.0.5 → 0.0.6

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,6 +1,6 @@
1
1
  import { ApplicationCommandOptionType, ApplicationCommandType, AutocompleteInteraction, ChatInputCommandInteraction, InteractionContextType, MessageContextMenuCommandInteraction, UserContextMenuCommandInteraction, type ApplicationCommandOptionAllowedChannelTypes, type ApplicationCommandOptionChoiceData, type BaseApplicationCommandData, type CacheType, type LocalizationMap } from "discord.js";
2
2
  import type { NotEmptyArray, UniqueArray } from "../../utils/types.js";
3
- export type CommandType = Exclude<ApplicationCommandType, ApplicationCommandType.PrimaryEntryPoint>;
3
+ export type CommandType = ApplicationCommandType.ChatInput | ApplicationCommandType.Message | ApplicationCommandType.User;
4
4
  type AutocompleData<Type> = Promise<readonly ApplicationCommandOptionChoiceData<Type extends (number | string) ? Type : (number | string)>[] | undefined | void>;
5
5
  export type AutocompleteRun<Type, Contexts> = (this: void, interaction: AutocompleteInteraction<CacheMode<Contexts>>) => AutocompleData<Type>;
6
6
  interface AutocompleteOptionData<Type, Contexts> {
@@ -196,26 +196,32 @@ class CommandManager extends BaseManager {
196
196
  const promises = [];
197
197
  const manager = client.application.commands;
198
198
  const logs = [];
199
- const setGlobal = (commands2) => {
200
- promises.push(manager.set(commands2).then((data) => logs.push([
201
- data.size,
202
- `${client.user.username} application`
203
- ])));
199
+ const setGlobal = async (commands2) => {
200
+ const data = await manager.set(commands2);
201
+ logs.push([data.size, `${client.user.username} application`]);
204
202
  };
205
- if (guildList.size >= 1) {
206
- const guildCommands = commands.filter((c) => !c.global);
207
- for (const id of guildList.values()) {
208
- promises.push(manager.set(guildCommands, id).then((commands2) => logs.push([
209
- commands2.size,
203
+ if (guildList.size) {
204
+ const guildScopedCommands = [];
205
+ const globalCommands = [];
206
+ for (const command of commands) {
207
+ if (command.global) {
208
+ globalCommands.push(command);
209
+ } else {
210
+ guildScopedCommands.push(command);
211
+ }
212
+ }
213
+ for (const id of guildList) {
214
+ promises.push(manager.set(guildScopedCommands, id).then((registerdCommands) => logs.push([
215
+ registerdCommands.size,
210
216
  `${id} guild`
211
217
  ])));
212
218
  }
213
- const globalCommands = commands.filter((c) => c.global);
214
- if (globalCommands.length >= 1) {
215
- setGlobal(globalCommands);
219
+ if (globalCommands.length) {
220
+ promises.push(setGlobal(globalCommands));
216
221
  }
217
222
  } else {
218
- setGlobal(commands);
223
+ promises.push(setGlobal(commands));
224
+ client.guilds.cache.forEach((guild) => guild.commands.set([]).catch(() => null));
219
225
  }
220
226
  await Promise.all(promises);
221
227
  console.log(logs.map(([size, location]) => format(styleText("green", "└ %s command%s registered in %s"), size, size === 1 ? "" : "s", styleText("greenBright", location))).join(`
package/dist/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var version = "0.0.5";
2
+ var version = "0.0.6";
3
3
  export {
4
4
  version
5
5
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constatic/base",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "Library with structures and functions for creating modern Discord applications.",
5
5
  "license": "MIT",
6
6
  "type": "module",