mirror of
https://github.com/ReVanced/revanced-bots.git
synced 2026-01-21 18:23:57 +00:00
feat(bots/discord/utils): allow loading commands from custom dir
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
import type { Command } from '$commands'
|
||||
import { listAllFilesRecursive } from '$utils/fs'
|
||||
|
||||
export const loadCommands = async () => {
|
||||
export const loadCommands = async (dir: string) => {
|
||||
const commandsMap: Record<string, Command> = {}
|
||||
const files = await listAllFilesRecursive('src/commands')
|
||||
const files = listAllFilesRecursive(dir)
|
||||
const commands = await Promise.all(
|
||||
files.map(async file => {
|
||||
const command = await import(file)
|
||||
|
||||
@@ -1,17 +1,21 @@
|
||||
import { join } from 'path'
|
||||
import { readdir, stat } from 'fs/promises'
|
||||
import { readdirSync, statSync } from 'fs'
|
||||
import { dirname, join } from 'path'
|
||||
import { fileURLToPath } from 'bun'
|
||||
|
||||
export async function listAllFilesRecursive(dir: string): Promise<string[]> {
|
||||
const files = await readdir(dir)
|
||||
export const listAllFilesRecursive = (dir: string): string[] => {
|
||||
const files = readdirSync(dir)
|
||||
const result: string[] = []
|
||||
for (const file of files) {
|
||||
const filePath = join(dir, file)
|
||||
const fileStat = await stat(filePath)
|
||||
const fileStat = statSync(filePath)
|
||||
if (fileStat.isDirectory()) {
|
||||
result.push(...(await listAllFilesRecursive(filePath)))
|
||||
result.push(...listAllFilesRecursive(filePath))
|
||||
} else {
|
||||
result.push(filePath)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
export const pathJoinCurrentDir = (importMetaUrl: string, ...objects: [string, ...string[]]) =>
|
||||
join(dirname(fileURLToPath(importMetaUrl)), ...objects)
|
||||
|
||||
Reference in New Issue
Block a user