mirror of
https://github.com/JonnyBro/JaBa.git
synced 2025-02-06 01:24:10 +05:00
Compare commits
No commits in common. "6c7f892ae48b9cd0d52981c9139e3d28e028aa39" and "eb78c29c9033466516e0aa4b1b590f326295f03f" have entirely different histories.
6c7f892ae4
...
eb78c29c90
5 changed files with 5 additions and 67 deletions
|
@ -4,14 +4,11 @@ import { getFilePaths } from "@/utils/get-path.js";
|
|||
import { toFileURL } from "@/utils/resolve-file.js";
|
||||
import registerCommands from "./functions/registerCommands.js";
|
||||
import { ExtendedClient } from "@/structures/client.js";
|
||||
import { BuiltInValidation, CommandFileObject } from "@/types.js";
|
||||
import builtInValidationsFunctions from "./validations/index.js";
|
||||
import { CommandFileObject } from "@//types.js";
|
||||
|
||||
export class CommandHandler {
|
||||
client: ExtendedClient;
|
||||
commands: CommandFileObject[] = [];
|
||||
builtInValidations: BuiltInValidation[] = [];
|
||||
|
||||
constructor(client: ExtendedClient) {
|
||||
this.client = client;
|
||||
}
|
||||
|
@ -19,8 +16,6 @@ export class CommandHandler {
|
|||
async init() {
|
||||
await this.#buildCommands();
|
||||
|
||||
this.buildBuiltInValidations();
|
||||
|
||||
await registerCommands({
|
||||
client: this.client,
|
||||
commands: this.commands,
|
||||
|
@ -50,12 +45,6 @@ export class CommandHandler {
|
|||
}
|
||||
}
|
||||
|
||||
buildBuiltInValidations() {
|
||||
for (const builtInValidationFunction of builtInValidationsFunctions) {
|
||||
this.builtInValidations.push(builtInValidationFunction);
|
||||
}
|
||||
}
|
||||
|
||||
handleCommands() {
|
||||
this.client.on("interactionCreate", async interaction => {
|
||||
if (!interaction.isChatInputCommand() && !interaction.isAutocomplete()) return;
|
||||
|
@ -69,23 +58,6 @@ export class CommandHandler {
|
|||
// Skip if autocomplete handler is not defined
|
||||
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"]!;
|
||||
|
||||
try {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
import devOnly from "./devOnly.js";
|
||||
|
||||
export default [devOnly];
|
|
@ -33,16 +33,9 @@ export class EventHandler {
|
|||
const eventFilePaths = (await getFilePaths(eventPath, true)).filter(path => path.endsWith(".js") || path.endsWith(".ts"));
|
||||
|
||||
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)) {
|
||||
logger.warn(`Event ${eventFilePath} does not have a data object or name`);
|
||||
continue;
|
||||
}
|
||||
|
||||
const { data, run } = eventModule;
|
||||
|
||||
if (!data.name) {
|
||||
if (!data || !data.name) {
|
||||
logger.warn(`Event ${eventFilePath} does not have a data object or name`);
|
||||
continue;
|
||||
}
|
||||
|
|
10
src/types.d.ts
vendored
10
src/types.d.ts
vendored
|
@ -19,14 +19,6 @@ export type cacheRemindsData = {
|
|||
reminds: UserReminds[];
|
||||
};
|
||||
|
||||
export type BuiltInValidationParams = {
|
||||
targetCommand: CommandFileObject;
|
||||
interaction: Interaction<CacheType>;
|
||||
client: ExtendedClient;
|
||||
};
|
||||
|
||||
export type BuiltInValidation = ({}: BuiltInValidationParams) => boolean | void;
|
||||
|
||||
export type CronTaskData = {
|
||||
name: string;
|
||||
schedule: string;
|
||||
|
@ -49,6 +41,8 @@ export interface CommandContext<_T extends Interaction, _Cached extends CacheTyp
|
|||
|
||||
export interface CommandOptions {
|
||||
devOnly?: boolean;
|
||||
userPermissions?: PermissionsString | PermissionsString[];
|
||||
botPermissions?: PermissionsString | PermissionsString[];
|
||||
}
|
||||
|
||||
export interface CommandFileObject {
|
||||
|
|
Loading…
Reference in a new issue