Skip to content

refactor(handlers): extract generic loadModules from loaders#1

Merged
Ntalcme merged 1 commit into
mainfrom
refacto-handlers
Jun 4, 2026
Merged

refactor(handlers): extract generic loadModules from loaders#1
Ntalcme merged 1 commit into
mainfrom
refacto-handlers

Conversation

@Ntalcme

@Ntalcme Ntalcme commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@Ntalcme Ntalcme self-assigned this Jun 4, 2026
Copilot AI review requested due to automatic review settings June 4, 2026 11:48
@Ntalcme Ntalcme added the refactor Refactoring of code label Jun 4, 2026
@Ntalcme Ntalcme merged commit c58779a into main Jun 4, 2026
1 check passed
@Ntalcme Ntalcme deleted the refacto-handlers branch June 4, 2026 11:49

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the handlers to centralize dynamic module loading into a reusable loadModules helper, reducing duplicated filesystem/import logic across event and command loaders.

Changes:

  • Added a generic loadModules<T> helper in src/handlers/base-loader.ts.
  • Refactored event loading to use loadModules instead of inline directory scanning/import logic.
  • Refactored slash command loading to use loadModules and then register the validated commands.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/handlers/event-handler.ts Replaces inline event directory scanning/import with loadModules.
src/handlers/command-handler.ts Replaces inline slash command scanning/import with loadModules and registers results.
src/handlers/base-loader.ts Introduces the shared dynamic loader used by handlers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

isValid: (obj: unknown) => obj is T,
): Promise<T[]> {
const items: T[] = [];
const dirPath = dirname(join(__dirname, '..', directory));
Comment on lines +24 to +28
const moduleFiles = files.filter(
(file) =>
(file.endsWith('.js') || file.endsWith('.ts')) && !file.endsWith('.d.ts'),
);
for (const file of files) {
Comment on lines 1 to 5
import { readdir } from 'node:fs/promises';
import { dirname, join } from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
import type { ClientEvents } from 'discord.js';
import type { Event } from '@/types/event.js';
Comment on lines +2 to 6
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { slashCommands } from '@/registries/slash-registry.js';
import { logger } from '@/lib/logger.js';
import { loadModules } from './base-loader.js';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Refactoring of code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants