djs-commander
Advanced tools
Comparing version 0.0.47 to 0.0.48
"use strict"; | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
@@ -8,2 +9,3 @@ var __defProps = Object.defineProperties; | ||
var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
@@ -36,5 +38,2 @@ var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
}; | ||
var __esm = (fn, res) => function __init() { | ||
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res; | ||
}; | ||
var __export = (target, all) => { | ||
@@ -52,2 +51,10 @@ for (var name in all) | ||
}; | ||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( | ||
// If the importer is in node compatibility mode or this is not an ESM | ||
// file that has been converted to a CommonJS file using a Babel- | ||
// compatible transform (i.e. "__esModule" has not been set), then set | ||
// "default" to the CommonJS "module.exports" for node compatibility. | ||
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, | ||
mod | ||
)); | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
@@ -75,8 +82,12 @@ var __async = (__this, __arguments, generator) => { | ||
// src/index.ts | ||
var src_exports = {}; | ||
__export(src_exports, { | ||
CommandHandler: () => CommandHandler | ||
}); | ||
module.exports = __toCommonJS(src_exports); | ||
// src/utils/getPaths.ts | ||
var getPaths_exports = {}; | ||
__export(getPaths_exports, { | ||
getFilePaths: () => getFilePaths, | ||
getFolderPaths: () => getFolderPaths | ||
}); | ||
var import_fs = __toESM(require("fs")); | ||
var import_path = __toESM(require("path")); | ||
function getFilePaths(directory, nesting) { | ||
@@ -86,5 +97,5 @@ let filePaths = []; | ||
return filePaths; | ||
const files = fs.readdirSync(directory, { withFileTypes: true }); | ||
const files = import_fs.default.readdirSync(directory, { withFileTypes: true }); | ||
for (const file of files) { | ||
const filePath = path.join(directory, file.name); | ||
const filePath = import_path.default.join(directory, file.name); | ||
if (file.isFile()) { | ||
@@ -103,5 +114,5 @@ filePaths.push(filePath); | ||
return folderPaths; | ||
const folders = fs.readdirSync(directory, { withFileTypes: true }); | ||
const folders = import_fs.default.readdirSync(directory, { withFileTypes: true }); | ||
for (const folder of folders) { | ||
const folderPath = path.join(directory, folder.name); | ||
const folderPath = import_path.default.join(directory, folder.name); | ||
if (folder.isDirectory()) { | ||
@@ -116,46 +127,35 @@ folderPaths.push(folderPath); | ||
} | ||
var fs, path; | ||
var init_getPaths = __esm({ | ||
"src/utils/getPaths.ts"() { | ||
"use strict"; | ||
fs = require("fs"); | ||
path = require("path"); | ||
} | ||
}); | ||
// src/index.ts | ||
var src_exports = {}; | ||
__export(src_exports, { | ||
CommandHandler: () => CommandHandler | ||
}); | ||
module.exports = __toCommonJS(src_exports); | ||
init_getPaths(); | ||
// src/utils/buildCommandTree.ts | ||
var { getFilePaths: getFilePaths2 } = (init_getPaths(), __toCommonJS(getPaths_exports)); | ||
function buildCommandTree(commandsDir) { | ||
const commandTree = []; | ||
if (!commandsDir) | ||
return []; | ||
const commandFilePaths = getFilePaths2(commandsDir, true); | ||
for (const commandFilePath of commandFilePaths) { | ||
let _a = require(commandFilePath), { data, run, deleted } = _a, rest = __objRest(_a, ["data", "run", "deleted"]); | ||
if (!data) | ||
throw new Error(`File ${commandFilePath} must export "data".`); | ||
if (!run) | ||
throw new Error(`File ${commandFilePath} must export a "run" function.`); | ||
if (!data.name) | ||
throw new Error(`File ${commandFilePath} must have a command name.`); | ||
if (!data.description) | ||
throw new Error(`File ${commandFilePath} must have a command description.`); | ||
try { | ||
data = data.toJSON(); | ||
} catch (error) { | ||
return __async(this, null, function* () { | ||
const commandTree = []; | ||
if (!commandsDir) | ||
return []; | ||
const commandFilePaths = getFilePaths(commandsDir, true); | ||
for (const commandFilePath of commandFilePaths) { | ||
let commandObj = yield import(commandFilePath); | ||
if (commandObj == null ? void 0 : commandObj.default) { | ||
commandObj = commandObj.default; | ||
} | ||
let _a = commandObj, { data, run, deleted } = _a, rest = __objRest(_a, ["data", "run", "deleted"]); | ||
if (!data) | ||
throw new Error(`File ${commandFilePath} must export "data".`); | ||
if (!run) | ||
throw new Error(`File ${commandFilePath} must export a "run" function.`); | ||
if (!data.name) | ||
throw new Error(`File ${commandFilePath} must have a command name.`); | ||
if (!data.description) | ||
throw new Error(`File ${commandFilePath} must have a command description.`); | ||
try { | ||
data = data.toJSON(); | ||
} catch (error) { | ||
} | ||
commandTree.push(__spreadProps(__spreadValues(__spreadValues({}, data), rest), { | ||
deleted, | ||
run | ||
})); | ||
} | ||
commandTree.push(__spreadProps(__spreadValues(__spreadValues({}, data), rest), { | ||
deleted, | ||
run | ||
})); | ||
} | ||
return commandTree; | ||
return commandTree; | ||
}); | ||
} | ||
@@ -299,4 +299,6 @@ | ||
_commandsInit() { | ||
let commands = buildCommandTree(this._commandsPath); | ||
this._commands = commands; | ||
return __async(this, null, function* () { | ||
let commands = yield buildCommandTree(this._commandsPath); | ||
this._commands = commands; | ||
}); | ||
} | ||
@@ -321,3 +323,6 @@ _registerSlashCommands() { | ||
for (const eventFuncPath of eventFuncPaths) { | ||
const eventFunc = require(eventFuncPath); | ||
let eventFunc = yield import(eventFuncPath); | ||
if (eventFunc == null ? void 0 : eventFunc.default) { | ||
eventFunc = eventFunc.default; | ||
} | ||
const cantRunEvent = yield eventFunc(...arg, this._client, this); | ||
@@ -331,11 +336,16 @@ if (cantRunEvent) | ||
_validationsInit() { | ||
const validationFilePaths = getFilePaths(this._validationsPath); | ||
validationFilePaths.sort(); | ||
for (const validationFilePath of validationFilePaths) { | ||
const validationFunc = require(validationFilePath); | ||
if (typeof validationFunc !== "function") { | ||
throw new Error(`Validation file ${validationFilePath} must export a function by default.`); | ||
return __async(this, null, function* () { | ||
const validationFilePaths = getFilePaths(this._validationsPath); | ||
validationFilePaths.sort(); | ||
for (const validationFilePath of validationFilePaths) { | ||
let validationFunc = yield import(validationFilePath); | ||
if (validationFunc == null ? void 0 : validationFunc.default) { | ||
validationFunc = validationFunc.default; | ||
} | ||
if (typeof validationFunc !== "function") { | ||
throw new Error(`Validation file ${validationFilePath} must export a function by default.`); | ||
} | ||
this._validationFuncs.push(validationFunc); | ||
} | ||
this._validationFuncs.push(validationFunc); | ||
} | ||
}); | ||
} | ||
@@ -348,4 +358,4 @@ _handleCommands() { | ||
if (command) { | ||
let canRun = true; | ||
if (this._validationFuncs.length) { | ||
let canRun = true; | ||
for (const validationFunc of this._validationFuncs) { | ||
@@ -358,10 +368,4 @@ const cantRunCommand = yield validationFunc(interaction, command, this, this._client); | ||
} | ||
if (canRun) { | ||
yield command.run({ | ||
interaction, | ||
client: this._client, | ||
handler: this | ||
}); | ||
} | ||
} else { | ||
} | ||
if (canRun) { | ||
yield command.run({ | ||
@@ -368,0 +372,0 @@ interaction, |
@@ -1,2 +0,2 @@ | ||
import { Client, APIApplicationCommand } from 'discord.js'; | ||
import { Client, ApplicationCommandOption } from 'discord.js'; | ||
import { Logger } from 'winston'; | ||
@@ -6,3 +6,3 @@ | ||
constructor(options: CommandHandlerOptions); | ||
public get commands(): LocalCommand[]; | ||
public get commands(): CommandObj[]; | ||
} | ||
@@ -19,3 +19,12 @@ | ||
interface LocalCommand extends APIApplicationCommand { | ||
interface CommandObj { | ||
options?: ApplicationCommandOption[]; | ||
name: string; | ||
name_localizations?: undefined; | ||
description: string; | ||
description_localizations?: undefined; | ||
default_member_permissions?: string | number | bigint | null; | ||
dm_permission?: boolean; | ||
nsfw?: boolean; | ||
deleted?: boolean; | ||
@@ -25,2 +34,2 @@ [key: string]: any; | ||
export { CommandHandler, LocalCommand }; | ||
export { CommandHandler, CommandObj }; |
{ | ||
"name": "djs-commander", | ||
"version": "0.0.47", | ||
"version": "0.0.48", | ||
"description": "A command and event handler that works seamlessly with Discord.js", | ||
@@ -5,0 +5,0 @@ "types": "./index.d.ts", |
Sorry, the diff of this file is not supported yet
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
2
40854
825