Make sure numeric options are numbers. Convert empty strings from config.ini to null. Some loading message tweaks.
parent
89e7d6373b
commit
6635fe1414
|
@ -3,8 +3,10 @@
|
||||||
## v2.29.0
|
## v2.29.0
|
||||||
* **Change default configuration format to .ini**
|
* **Change default configuration format to .ini**
|
||||||
* Existing `config.json` files will continue to work and will not be deprecated
|
* Existing `config.json` files will continue to work and will not be deprecated
|
||||||
* New, rewritten instructions for setting up and using the bot
|
* This makes the default configuration format for the bot much more approachable than JSON
|
||||||
* Updated several package dependencies
|
* New rewritten instructions for setting up and using the bot
|
||||||
|
* New easy-to-use `start.bat` file for Windows
|
||||||
|
* Update several package dependencies
|
||||||
* Fixed incompatibility with certain Node.js 10 versions
|
* Fixed incompatibility with certain Node.js 10 versions
|
||||||
|
|
||||||
## v2.28.0
|
## v2.28.0
|
||||||
|
|
|
@ -40,7 +40,7 @@ if (! foundConfigFile) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load config file
|
// Load config file
|
||||||
console.log(`Loading configuration from ${foundConfigFile}`);
|
console.log(`Loading configuration from ${foundConfigFile}...`);
|
||||||
try {
|
try {
|
||||||
if (foundConfigFile.endsWith('.js')) {
|
if (foundConfigFile.endsWith('.js')) {
|
||||||
userConfig = require(`../${foundConfigFile}`);
|
userConfig = require(`../${foundConfigFile}`);
|
||||||
|
@ -123,6 +123,7 @@ const defaultConfig = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const required = ['token', 'mailGuildId', 'mainGuildId', 'logChannelId'];
|
const required = ['token', 'mailGuildId', 'mainGuildId', 'logChannelId'];
|
||||||
|
const numericOptions = ['requiredAccountAge', 'requiredTimeOnServer', 'smallAttachmentLimit', 'port'];
|
||||||
|
|
||||||
const finalConfig = Object.assign({}, defaultConfig);
|
const finalConfig = Object.assign({}, defaultConfig);
|
||||||
|
|
||||||
|
@ -152,14 +153,6 @@ Object.assign(finalConfig['knex'], {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Make sure all of the required config options are present
|
|
||||||
for (const opt of required) {
|
|
||||||
if (! finalConfig[opt]) {
|
|
||||||
console.error(`Missing required config.json value: ${opt}`);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (finalConfig.smallAttachmentLimit > 1024 * 1024 * 8) {
|
if (finalConfig.smallAttachmentLimit > 1024 * 1024 * 8) {
|
||||||
finalConfig.smallAttachmentLimit = 1024 * 1024 * 8;
|
finalConfig.smallAttachmentLimit = 1024 * 1024 * 8;
|
||||||
console.warn('[WARN] smallAttachmentLimit capped at 8MB');
|
console.warn('[WARN] smallAttachmentLimit capped at 8MB');
|
||||||
|
@ -212,6 +205,33 @@ if (finalConfig.newThreadCategoryId) {
|
||||||
delete finalConfig.newThreadCategoryId;
|
delete finalConfig.newThreadCategoryId;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Configuration ok");
|
// Turn empty string options to null (i.e. "option=" without a value in config.ini)
|
||||||
|
for (const [key, value] of Object.entries(finalConfig)) {
|
||||||
|
if (value === '') {
|
||||||
|
finalConfig[key] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cast numeric options to numbers
|
||||||
|
for (const numericOpt of numericOptions) {
|
||||||
|
if (finalConfig[numericOpt] != null) {
|
||||||
|
const number = parseFloat(finalConfig[numericOpt]);
|
||||||
|
if (Number.isNaN(number)) {
|
||||||
|
console.error(`Invalid numeric value for ${numericOpt}: ${finalConfig[numericOpt]}`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
finalConfig[numericOpt] = number;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure all of the required config options are present
|
||||||
|
for (const opt of required) {
|
||||||
|
if (! finalConfig[opt]) {
|
||||||
|
console.error(`Missing required config.json value: ${opt}`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("Configuration ok!");
|
||||||
|
|
||||||
module.exports = finalConfig;
|
module.exports = finalConfig;
|
||||||
|
|
|
@ -35,18 +35,20 @@ module.exports = {
|
||||||
console.log('Connecting to Discord...');
|
console.log('Connecting to Discord...');
|
||||||
|
|
||||||
bot.once('ready', async () => {
|
bot.once('ready', async () => {
|
||||||
console.log('Connected, waiting for guilds to become available');
|
console.log('Connected! Waiting for guilds to become available...');
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
...config.mainGuildId.map(id => waitForGuild(id)),
|
...config.mainGuildId.map(id => waitForGuild(id)),
|
||||||
waitForGuild(config.mailGuildId)
|
waitForGuild(config.mailGuildId)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
console.log('Initializing');
|
console.log('Initializing...');
|
||||||
initStatus();
|
initStatus();
|
||||||
initBaseMessageHandlers();
|
initBaseMessageHandlers();
|
||||||
initPlugins();
|
initPlugins();
|
||||||
|
|
||||||
|
console.log('');
|
||||||
console.log('Done! Now listening to DMs.');
|
console.log('Done! Now listening to DMs.');
|
||||||
|
console.log('');
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.connect();
|
bot.connect();
|
||||||
|
|
Loading…
Reference in New Issue