ramirez/src/config.js

80 lines
1.7 KiB
JavaScript
Raw Normal View History

const path = require('path');
2017-09-19 13:23:55 -04:00
let userConfig;
try {
userConfig = require('../config');
} catch (e) {
throw new Error(`Config file could not be found or read! The error given was: ${e.message}`);
}
const defaultConfig = {
"token": null,
"mailGuildId": null,
"mainGuildId": null,
"logChannelId": null,
"prefix": "!",
"snippetPrefix": "!!",
"status": "Message me for help!",
"responseMessage": "Thank you for your message! Our mod team will reply to you here as soon as possible.",
2017-09-22 15:18:15 -04:00
"newThreadCategoryId": null,
2017-09-19 13:23:55 -04:00
"inboxServerPermission": null,
"alwaysReply": false,
"alwaysReplyAnon": false,
"useNicknames": false,
"ignoreAccidentalThreads": false,
"enableGreeting": false,
2017-09-19 14:32:48 -04:00
"greetingMessage": null,
"greetingAttachment": null,
2017-09-19 13:23:55 -04:00
"port": 8890,
"url": null,
"dbDir": path.join(__dirname, '..', 'db'),
"knex": null,
"logDir": path.join(__dirname, '..', 'logs'),
2017-09-19 13:23:55 -04:00
};
2017-12-31 19:16:05 -05:00
const required = ['token', 'mailGuildId', 'mainGuildId', 'logChannelId'];
2017-09-19 13:23:55 -04:00
const finalConfig = Object.assign({}, defaultConfig);
for (const [prop, value] of Object.entries(userConfig)) {
if (! defaultConfig.hasOwnProperty(prop)) {
throw new Error(`Invalid option: ${prop}`);
}
finalConfig[prop] = value;
}
if (! finalConfig['knex']) {
finalConfig['knex'] = {
client: 'sqlite',
connection: {
filename: path.join(finalConfig.dbDir, 'data.sqlite')
},
useNullAsDefault: true
};
}
Object.assign(finalConfig['knex'], {
migrations: {
directory: path.join(finalConfig.dbDir, 'migrations')
}
});
for (const opt of required) {
if (! finalConfig[opt]) {
console.error(`Missing required config.json value: ${opt}`);
process.exit(1);
}
}
2017-09-19 13:23:55 -04:00
module.exports = finalConfig;