miraipie
Version:
the most powerful nodejs development kit for mirai-api-http
74 lines (73 loc) • 2.96 kB
JavaScript
;
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ApplicationConfig = exports.checkUserConfig = exports.makeConfigs = void 0;
/** 通过元定义生成默认用户配置 */
function makeConfigs(configMeta) {
var configs = {};
for (var key in configMeta || {}) {
if (configMeta.hasOwnProperty(key))
configs[key] = configMeta[key].default && configMeta[key].default();
}
return configs;
}
exports.makeConfigs = makeConfigs;
function checkUserConfig(configMeta, configs, logger) {
var e_1, _a;
try {
for (var _b = __values(Object.keys(configMeta)), _c = _b.next(); !_c.done; _c = _b.next()) {
var prop = _c.value;
if (prop in configs) {
if (typeof configs[prop] !== typeof configMeta[prop].type() && logger) {
logger.warn("\u914D\u7F6E\u9879 " + prop + " \u4E0D\u7B26\u5408\u7C7B\u578B\u5B9A\u4E49, \u9700\u8981\u7C7B\u578B " + typeof configMeta[prop].type() + ", \u5F97\u5230\u7C7B\u578B " + typeof configs[prop]);
}
}
if (!(prop in configs) && configMeta[prop].required) {
if (logger) {
logger.error("\u5FC5\u8981\u914D\u7F6E\u9879 " + prop + " \u7F3A\u5931");
}
else {
throw new Error("\u5FC5\u8981\u914D\u7F6E\u9879 " + prop + " \u7F3A\u5931");
}
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
}
exports.checkUserConfig = checkUserConfig;
var ApplicationConfig = /** @class */ (function () {
function ApplicationConfig() {
}
ApplicationConfig.make = function (config) {
if (!config.qq)
throw Error('配置文件缺少服务qq号');
return {
qq: config.qq,
adapterInUse: config.adapterInUse || 'http',
logDirectory: config.logDirectory || null,
logLevel: config.logLevel || 'debug',
verbose: config.verbose || false,
adapters: config.adapters || {},
pies: config.pies || {},
extensions: config.extensions || []
};
};
return ApplicationConfig;
}());
exports.ApplicationConfig = ApplicationConfig;