From edd2ceb1abd92f024d3fd59abf4258d00f62ffd5 Mon Sep 17 00:00:00 2001 From: DopeGhoti Date: Thu, 4 Jun 2020 20:27:01 -0700 Subject: [PATCH] Add optional automatic thread creation on mention Add an option to have the bot automatically open a new thread when a user @s the bot in a monitored channel. Modify configuration parser to handle the new settings; add a stanza to the configuration documentiaion for it. --- docs/configuration.md | 4 ++++ src/config.js | 1 + src/main.js | 11 +++++++++++ 3 files changed, 16 insertions(+) diff --git a/docs/configuration.md b/docs/configuration.md index cb4f2bb..a6a3fe3 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -254,6 +254,10 @@ The bot's "Playing" text **Default:** `on` If enabled, channel permissions for the thread are synchronized with the category when using `!move`. Requires `allowMove` to be enabled. +#### threadOnMention +**Default:** `off` +If enabled, the bot will automatically create a new thread for a user who pings it. + #### threadTimestamps **Default:** `off` If enabled, modmail threads will show accurate UTC timestamps for each message, in addition to Discord's own timestamps. diff --git a/src/config.js b/src/config.js index 5d649f8..7d23c86 100644 --- a/src/config.js +++ b/src/config.js @@ -76,6 +76,7 @@ const defaultConfig = { "mentionRole": "here", "pingOnBotMention": true, "botMentionResponse": null, + "threadOnMention": false, "inboxServerPermission": null, "alwaysReply": false, diff --git a/src/main.js b/src/main.js index e8f7258..c2bd4a5 100644 --- a/src/main.js +++ b/src/main.js @@ -229,6 +229,17 @@ function initBaseMessageHandlers() { const botMentionResponse = utils.readMultilineConfigValue(config.botMentionResponse); bot.createMessage(msg.channel.id, botMentionResponse.replace(/{userMention}/g, `<@${msg.author.id}>`)); } + + // If configured, automatically open a new thread with a user who has pinged it + if (config.threadOnMention) { + if (await blocked.isBlocked(msg.author.id)) return; // This may not be needed as it is checked above. + if (utils.isStaff(msg.member)) return; // Same. + const existingThread = await threads.findOpenThreadByUserId(msg.author.id); + if (existingThread) { // Already a thread open; nothing to do + return; + } + const createdThread = await threads.createNewThreadForUser(msg.author, true, true); + } }); }