@shadow-dev/core
Version:
A modular core framework for Discord bot development, providing commands, buttons, menus, middleware, and more.
68 lines (67 loc) • 2.62 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.splitSpecialId = splitSpecialId;
exports.importFile = importFile;
exports.isBotOwner = isBotOwner;
function splitSpecialId(specialId) {
const [feature, action, id] = specialId.split(":");
return { feature, action, id };
}
async function importFile(filePath) {
try {
// Handle .js files using require
if (filePath.endsWith(".js")) {
return require(filePath);
}
// Handle .ts files using dynamic import
const imported = await Promise.resolve(`${filePath}`).then(s => __importStar(require(s)));
// If default export is found, return it (class in this case)
if (imported?.default) {
return imported.default; // Return the class constructor itself, not an instance
}
// If no default export is found, log an error
console.error(`❌ No default export found in ${filePath}`);
return null;
}
catch (err) {
console.error(`❌ Error importing file: ${filePath}`, err);
return null;
}
}
function isBotOwner(userId, ownerId) {
const owners = Array.isArray(ownerId) ? ownerId : [ownerId];
return owners.includes(userId);
}