diff --git a/src/config.js b/src/config.js index e38e048..a2e3beb 100644 --- a/src/config.js +++ b/src/config.js @@ -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 if (finalConfig.newThreadCategoryId) { finalConfig.categoryAutomation.newThread = finalConfig.newThreadCategoryId; diff --git a/src/data/threads.js b/src/data/threads.js index 4353703..da61715 100644 --- a/src/data/threads.js +++ b/src/data/threads.js @@ -68,8 +68,9 @@ async function createNewThreadForUser(user, quiet = false, ignoreRequirements = if (config.requiredAccountAge && ! ignoreRequirements) { if (user.createdAt > moment() - config.requiredAccountAge * HOURS){ if (config.accountAgeDeniedMessage) { + const accountAgeDeniedMessage = utils.readMultilineConfigValue(config.accountAgeDeniedMessage); const privateChannel = await user.getDMChannel(); - await privateChannel.createMessage(config.accountAgeDeniedMessage); + await privateChannel.createMessage(accountAgeDeniedMessage); } return; } @@ -106,8 +107,9 @@ async function createNewThreadForUser(user, quiet = false, ignoreRequirements = if (! isAllowed) { if (config.timeOnServerDeniedMessage) { + const timeOnServerDeniedMessage = utils.readMultilineConfigValue(config.timeOnServerDeniedMessage); const privateChannel = await user.getDMChannel(); - await privateChannel.createMessage(config.timeOnServerDeniedMessage); + await privateChannel.createMessage(timeOnServerDeniedMessage); } return; } @@ -173,8 +175,10 @@ async function createNewThreadForUser(user, quiet = false, ignoreRequirements = // Send auto-reply to the user if (config.responseMessage) { + const responseMessage = utils.readMultilineConfigValue(config.responseMessage); + try { - await newThread.postToUser(config.responseMessage); + await newThread._sendDMToUser(responseMessage); } catch (err) { responseMessageError = err; } diff --git a/src/main.js b/src/main.js index 5a29e70..140cb5b 100644 --- a/src/main.js +++ b/src/main.js @@ -223,7 +223,8 @@ function initBaseMessageHandlers() { // Send an auto-response to the mention, if enabled 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}>`)); } }); } diff --git a/src/modules/close.js b/src/modules/close.js index 60feb54..9b3463d 100644 --- a/src/modules/close.js +++ b/src/modules/close.js @@ -12,7 +12,8 @@ module.exports = ({ bot, knex, config, commands }) => { const threadsToBeClosed = await threads.getThreadsThatShouldBeClosed(); for (const thread of threadsToBeClosed) { 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); @@ -116,7 +117,8 @@ module.exports = ({ bot, knex, config, commands }) => { // Send close message (unless suppressed with a silent close) 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(); @@ -135,7 +137,11 @@ module.exports = ({ bot, knex, config, commands }) => { if (! thread) return; 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); const logUrl = await thread.getLogUrl(); diff --git a/src/modules/greeting.js b/src/modules/greeting.js index 540d9ac..f85bde9 100644 --- a/src/modules/greeting.js +++ b/src/modules/greeting.js @@ -1,6 +1,7 @@ const path = require('path'); const fs = require('fs'); const config = require('../config'); +const utils = require('../utils'); module.exports = ({ bot }) => { if (! config.enableGreeting) return; @@ -21,14 +22,16 @@ module.exports = ({ bot }) => { }); } + const greetingMessage = utils.readMultilineConfigValue(guildGreeting.message); + if (guildGreeting.attachment) { const filename = path.basename(guildGreeting.attachment); fs.readFile(guildGreeting.attachment, (err, data) => { const file = {file: data, name: filename}; - sendGreeting(guildGreeting.message, file); + sendGreeting(greetingMessage, file); }); } else { - sendGreeting(guildGreeting.message); + sendGreeting(greetingMessage); } }); }; diff --git a/src/utils.js b/src/utils.js index fbea327..3e475ab 100644 --- a/src/utils.js +++ b/src/utils.js @@ -309,6 +309,13 @@ function disableCodeBlocks(str) { return str.replace(/`/g, "`\u200b"); } +/** + * + */ +function readMultilineConfigValue(str) { + return Array.isArray(str) ? str.join('\n') : str; +} + module.exports = { BotError, @@ -345,4 +352,6 @@ module.exports = { escapeMarkdown, disableCodeBlocks, + + readMultilineConfigValue, };