From 714a4189eb02051ddd330513048b07b3be070e27 Mon Sep 17 00:00:00 2001 From: WlodekM Date: Sat, 30 Nov 2024 14:24:39 +0200 Subject: do stuff 3 --- commands.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'commands.ts') diff --git a/commands.ts b/commands.ts index fbde383..e416aad 100644 --- a/commands.ts +++ b/commands.ts @@ -3,14 +3,21 @@ import type User from "./user.ts"; import type Server from "./server.ts"; import { ChannelConfig } from "./server.ts"; +export type CommandFnArgs = { + user: User, + server: Server, + args: string[], + sendInChannel: (msg: string, channel: string, server?: Server) => void, + commands: {[key: string]: Command} +} + // NOTE - temporary, will make class later export type Command = { name: string, usage?: string, description: string, aliases: string[], - command: ({ user, server, args, sendInChannel, commands }: - { user: User, server: Server, args: string[], sendInChannel: (msg: string, channel: string, server?: Server) => void, commands: {[key: string]: Command} }) => void + command: ({ user, server, args, sendInChannel, commands }: CommandFnArgs) => void } export const commands: {[key: string]: Command} = { @@ -178,8 +185,9 @@ export function register(cmd: string, data: Command) { const commandFiles = fs .readdirSync("commands") - .filter((filename) => filename.endsWith(".js") || filename.endsWith(".ts")) - .map((file) => file.replace(/\.js$/gim, "")); + .filter((filename: string) => filename.endsWith(".js") || filename.endsWith(".ts")) + .map((file: string) => file.replace(/\.js$/gim, "")); + for (let i = 0; i < commandFiles.length; i++) { const cmdName = commandFiles[i]; const cmd = (await import(`./commands/${cmdName}.js`)).default; -- cgit 1.4.1-2-gfad0