ramirez/src/config.js

87 lines
1.9 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,
"mentionRole": null,
2017-09-22 15:18:15 -04:00
2017-09-19 13:23:55 -04:00
"inboxServerPermission": null,
"alwaysReply": false,
"alwaysReplyAnon": false,
"useNicknames": false,
"ignoreAccidentalThreads": false,
"threadTimestamps": false,
2018-02-18 17:23:29 -05:00
"allowMove": false,
2018-01-22 17:17:24 -05:00
"typingProxy": false,
"typingProxyReverse": false,
2017-09-19 13:23:55 -04:00
"enableGreeting": false,
2017-09-19 14:32:48 -04:00
"greetingMessage": null,
"greetingAttachment": null,
2017-09-19 13:23:55 -04:00
"relaySmallAttachmentsAsAttachments": false,
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;