Expand multi-line .ini value support
The following options now also support multi-line values: - responseMessage - closeMessage - botMentionResponse - greetingMessage - accountAgeDeniedMessage - timeOnServerDeniedMessagemaster
parent
015c9fae31
commit
00fe240eb0
|
@ -241,13 +241,6 @@ if (finalConfig.greetingMessage || finalConfig.greetingAttachment) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert arrays of lines to multiline strings in greetings
|
|
||||||
for (const obj of Object.values(finalConfig.guildGreetings)) {
|
|
||||||
if (Array.isArray(obj.message)) {
|
|
||||||
obj.message = obj.message.join('\n');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// newThreadCategoryId is syntactic sugar for categoryAutomation.newThread
|
// newThreadCategoryId is syntactic sugar for categoryAutomation.newThread
|
||||||
if (finalConfig.newThreadCategoryId) {
|
if (finalConfig.newThreadCategoryId) {
|
||||||
finalConfig.categoryAutomation.newThread = finalConfig.newThreadCategoryId;
|
finalConfig.categoryAutomation.newThread = finalConfig.newThreadCategoryId;
|
||||||
|
|
|
@ -68,8 +68,9 @@ async function createNewThreadForUser(user, quiet = false, ignoreRequirements =
|
||||||
if (config.requiredAccountAge && ! ignoreRequirements) {
|
if (config.requiredAccountAge && ! ignoreRequirements) {
|
||||||
if (user.createdAt > moment() - config.requiredAccountAge * HOURS){
|
if (user.createdAt > moment() - config.requiredAccountAge * HOURS){
|
||||||
if (config.accountAgeDeniedMessage) {
|
if (config.accountAgeDeniedMessage) {
|
||||||
|
const accountAgeDeniedMessage = utils.readMultilineConfigValue(config.accountAgeDeniedMessage);
|
||||||
const privateChannel = await user.getDMChannel();
|
const privateChannel = await user.getDMChannel();
|
||||||
await privateChannel.createMessage(config.accountAgeDeniedMessage);
|
await privateChannel.createMessage(accountAgeDeniedMessage);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -106,8 +107,9 @@ async function createNewThreadForUser(user, quiet = false, ignoreRequirements =
|
||||||
|
|
||||||
if (! isAllowed) {
|
if (! isAllowed) {
|
||||||
if (config.timeOnServerDeniedMessage) {
|
if (config.timeOnServerDeniedMessage) {
|
||||||
|
const timeOnServerDeniedMessage = utils.readMultilineConfigValue(config.timeOnServerDeniedMessage);
|
||||||
const privateChannel = await user.getDMChannel();
|
const privateChannel = await user.getDMChannel();
|
||||||
await privateChannel.createMessage(config.timeOnServerDeniedMessage);
|
await privateChannel.createMessage(timeOnServerDeniedMessage);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -173,8 +175,10 @@ async function createNewThreadForUser(user, quiet = false, ignoreRequirements =
|
||||||
|
|
||||||
// Send auto-reply to the user
|
// Send auto-reply to the user
|
||||||
if (config.responseMessage) {
|
if (config.responseMessage) {
|
||||||
|
const responseMessage = utils.readMultilineConfigValue(config.responseMessage);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await newThread.postToUser(config.responseMessage);
|
await newThread._sendDMToUser(responseMessage);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
responseMessageError = err;
|
responseMessageError = err;
|
||||||
}
|
}
|
||||||
|
|
|
@ -223,7 +223,8 @@ function initBaseMessageHandlers() {
|
||||||
|
|
||||||
// Send an auto-response to the mention, if enabled
|
// Send an auto-response to the mention, if enabled
|
||||||
if (config.botMentionResponse) {
|
if (config.botMentionResponse) {
|
||||||
bot.createMessage(msg.channel.id, config.botMentionResponse.replace(/{userMention}/g, `<@${msg.author.id}>`));
|
const botMentionResponse = utils.readMultilineConfigValue(config.botMentionResponse);
|
||||||
|
bot.createMessage(msg.channel.id, botMentionResponse.replace(/{userMention}/g, `<@${msg.author.id}>`));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,8 @@ module.exports = ({ bot, knex, config, commands }) => {
|
||||||
const threadsToBeClosed = await threads.getThreadsThatShouldBeClosed();
|
const threadsToBeClosed = await threads.getThreadsThatShouldBeClosed();
|
||||||
for (const thread of threadsToBeClosed) {
|
for (const thread of threadsToBeClosed) {
|
||||||
if (config.closeMessage && ! thread.scheduled_close_silent) {
|
if (config.closeMessage && ! thread.scheduled_close_silent) {
|
||||||
await thread.postToUser(config.closeMessage).catch(() => {});
|
const closeMessage = utils.readMultilineConfigValue(config.closeMessage);
|
||||||
|
await thread.postToUser(closeMessage).catch(() => {});
|
||||||
}
|
}
|
||||||
|
|
||||||
await thread.close(false, thread.scheduled_close_silent);
|
await thread.close(false, thread.scheduled_close_silent);
|
||||||
|
@ -116,7 +117,8 @@ module.exports = ({ bot, knex, config, commands }) => {
|
||||||
|
|
||||||
// Send close message (unless suppressed with a silent close)
|
// Send close message (unless suppressed with a silent close)
|
||||||
if (hasCloseMessage && ! silentClose) {
|
if (hasCloseMessage && ! silentClose) {
|
||||||
await thread.postToUser(config.closeMessage).catch(() => {});
|
const closeMessage = utils.readMultilineConfigValue(config.closeMessage);
|
||||||
|
await thread._sendDMToUser(closeMessage).catch(() => {});
|
||||||
}
|
}
|
||||||
|
|
||||||
const logUrl = await thread.getLogUrl();
|
const logUrl = await thread.getLogUrl();
|
||||||
|
@ -135,7 +137,11 @@ module.exports = ({ bot, knex, config, commands }) => {
|
||||||
if (! thread) return;
|
if (! thread) return;
|
||||||
|
|
||||||
console.log(`[INFO] Auto-closing thread with ${thread.user_name} because the channel was deleted`);
|
console.log(`[INFO] Auto-closing thread with ${thread.user_name} because the channel was deleted`);
|
||||||
if (config.closeMessage) await thread.postToUser(config.closeMessage).catch(() => {});
|
if (config.closeMessage) {
|
||||||
|
const closeMessage = utils.readMultilineConfigValue(config.closeMessage);
|
||||||
|
await thread._sendDMToUser(closeMessage).catch(() => {});
|
||||||
|
}
|
||||||
|
|
||||||
await thread.close(true);
|
await thread.close(true);
|
||||||
|
|
||||||
const logUrl = await thread.getLogUrl();
|
const logUrl = await thread.getLogUrl();
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const config = require('../config');
|
const config = require('../config');
|
||||||
|
const utils = require('../utils');
|
||||||
|
|
||||||
module.exports = ({ bot }) => {
|
module.exports = ({ bot }) => {
|
||||||
if (! config.enableGreeting) return;
|
if (! config.enableGreeting) return;
|
||||||
|
@ -21,14 +22,16 @@ module.exports = ({ bot }) => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const greetingMessage = utils.readMultilineConfigValue(guildGreeting.message);
|
||||||
|
|
||||||
if (guildGreeting.attachment) {
|
if (guildGreeting.attachment) {
|
||||||
const filename = path.basename(guildGreeting.attachment);
|
const filename = path.basename(guildGreeting.attachment);
|
||||||
fs.readFile(guildGreeting.attachment, (err, data) => {
|
fs.readFile(guildGreeting.attachment, (err, data) => {
|
||||||
const file = {file: data, name: filename};
|
const file = {file: data, name: filename};
|
||||||
sendGreeting(guildGreeting.message, file);
|
sendGreeting(greetingMessage, file);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
sendGreeting(guildGreeting.message);
|
sendGreeting(greetingMessage);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -309,6 +309,13 @@ function disableCodeBlocks(str) {
|
||||||
return str.replace(/`/g, "`\u200b");
|
return str.replace(/`/g, "`\u200b");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function readMultilineConfigValue(str) {
|
||||||
|
return Array.isArray(str) ? str.join('\n') : str;
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
BotError,
|
BotError,
|
||||||
|
|
||||||
|
@ -345,4 +352,6 @@ module.exports = {
|
||||||
|
|
||||||
escapeMarkdown,
|
escapeMarkdown,
|
||||||
disableCodeBlocks,
|
disableCodeBlocks,
|
||||||
|
|
||||||
|
readMultilineConfigValue,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue