Compare commits

..

No commits in common. "6c7f892ae48b9cd0d52981c9139e3d28e028aa39" and "eb78c29c9033466516e0aa4b1b590f326295f03f" have entirely different histories.

5 changed files with 5 additions and 67 deletions

View file

@ -4,14 +4,11 @@ import { getFilePaths } from "@/utils/get-path.js";
import { toFileURL } from "@/utils/resolve-file.js"; import { toFileURL } from "@/utils/resolve-file.js";
import registerCommands from "./functions/registerCommands.js"; import registerCommands from "./functions/registerCommands.js";
import { ExtendedClient } from "@/structures/client.js"; import { ExtendedClient } from "@/structures/client.js";
import { BuiltInValidation, CommandFileObject } from "@/types.js"; import { CommandFileObject } from "@//types.js";
import builtInValidationsFunctions from "./validations/index.js";
export class CommandHandler { export class CommandHandler {
client: ExtendedClient; client: ExtendedClient;
commands: CommandFileObject[] = []; commands: CommandFileObject[] = [];
builtInValidations: BuiltInValidation[] = [];
constructor(client: ExtendedClient) { constructor(client: ExtendedClient) {
this.client = client; this.client = client;
} }
@ -19,8 +16,6 @@ export class CommandHandler {
async init() { async init() {
await this.#buildCommands(); await this.#buildCommands();
this.buildBuiltInValidations();
await registerCommands({ await registerCommands({
client: this.client, client: this.client,
commands: this.commands, commands: this.commands,
@ -50,12 +45,6 @@ export class CommandHandler {
} }
} }
buildBuiltInValidations() {
for (const builtInValidationFunction of builtInValidationsFunctions) {
this.builtInValidations.push(builtInValidationFunction);
}
}
handleCommands() { handleCommands() {
this.client.on("interactionCreate", async interaction => { this.client.on("interactionCreate", async interaction => {
if (!interaction.isChatInputCommand() && !interaction.isAutocomplete()) return; if (!interaction.isChatInputCommand() && !interaction.isAutocomplete()) return;
@ -69,23 +58,6 @@ export class CommandHandler {
// Skip if autocomplete handler is not defined // Skip if autocomplete handler is not defined
if (isAutocomplete && !targetCommand.autocompleteRun) return; if (isAutocomplete && !targetCommand.autocompleteRun) return;
let canRun = true;
for (const validation of this.builtInValidations) {
const stopValidationLoop = validation({
targetCommand,
interaction,
client: this.client,
});
if (stopValidationLoop) {
canRun = false;
break;
}
}
if (!canRun) return;
const command = targetCommand[isAutocomplete ? "autocompleteRun" : "run"]!; const command = targetCommand[isAutocomplete ? "autocompleteRun" : "run"]!;
try { try {

View file

@ -1,18 +0,0 @@
import { BuiltInValidationParams } from "@/types.js";
export default function ({ interaction, targetCommand, client }: BuiltInValidationParams) {
if (interaction.isAutocomplete()) return;
const devGuildsIds = client.configService.get<string[]>("devGuildsIds");
if (!targetCommand.options?.devOnly) return;
if (interaction.inGuild() && !devGuildsIds.includes(interaction.guildId)) {
interaction.reply({
content: "❌ This command is only available in development servers.",
ephemeral: true,
});
return true;
}
}

View file

@ -1,3 +0,0 @@
import devOnly from "./devOnly.js";
export default [devOnly];

View file

@ -33,16 +33,9 @@ export class EventHandler {
const eventFilePaths = (await getFilePaths(eventPath, true)).filter(path => path.endsWith(".js") || path.endsWith(".ts")); const eventFilePaths = (await getFilePaths(eventPath, true)).filter(path => path.endsWith(".js") || path.endsWith(".ts"));
for (const eventFilePath of eventFilePaths) { for (const eventFilePath of eventFilePaths) {
const eventModule = await import(toFileURL(eventFilePath)); const { data, run } = await import(toFileURL(eventFilePath));
if (!("data" in eventModule) || !("run" in eventModule)) { if (!data || !data.name) {
logger.warn(`Event ${eventFilePath} does not have a data object or name`);
continue;
}
const { data, run } = eventModule;
if (!data.name) {
logger.warn(`Event ${eventFilePath} does not have a data object or name`); logger.warn(`Event ${eventFilePath} does not have a data object or name`);
continue; continue;
} }

10
src/types.d.ts vendored
View file

@ -19,14 +19,6 @@ export type cacheRemindsData = {
reminds: UserReminds[]; reminds: UserReminds[];
}; };
export type BuiltInValidationParams = {
targetCommand: CommandFileObject;
interaction: Interaction<CacheType>;
client: ExtendedClient;
};
export type BuiltInValidation = ({}: BuiltInValidationParams) => boolean | void;
export type CronTaskData = { export type CronTaskData = {
name: string; name: string;
schedule: string; schedule: string;
@ -49,6 +41,8 @@ export interface CommandContext<_T extends Interaction, _Cached extends CacheTyp
export interface CommandOptions { export interface CommandOptions {
devOnly?: boolean; devOnly?: boolean;
userPermissions?: PermissionsString | PermissionsString[];
botPermissions?: PermissionsString | PermissionsString[];
} }
export interface CommandFileObject { export interface CommandFileObject {