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.
cshd
DopeGhoti 2020-06-04 20:27:01 -07:00
parent 1382c639a9
commit edd2ceb1ab
3 changed files with 16 additions and 0 deletions

View File

@ -254,6 +254,10 @@ The bot's "Playing" text
**Default:** `on` **Default:** `on`
If enabled, channel permissions for the thread are synchronized with the category when using `!move`. Requires `allowMove` to be enabled. 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 #### threadTimestamps
**Default:** `off` **Default:** `off`
If enabled, modmail threads will show accurate UTC timestamps for each message, in addition to Discord's own timestamps. If enabled, modmail threads will show accurate UTC timestamps for each message, in addition to Discord's own timestamps.

View File

@ -76,6 +76,7 @@ const defaultConfig = {
"mentionRole": "here", "mentionRole": "here",
"pingOnBotMention": true, "pingOnBotMention": true,
"botMentionResponse": null, "botMentionResponse": null,
"threadOnMention": false,
"inboxServerPermission": null, "inboxServerPermission": null,
"alwaysReply": false, "alwaysReply": false,

View File

@ -229,6 +229,17 @@ function initBaseMessageHandlers() {
const botMentionResponse = utils.readMultilineConfigValue(config.botMentionResponse); const botMentionResponse = utils.readMultilineConfigValue(config.botMentionResponse);
bot.createMessage(msg.channel.id, botMentionResponse.replace(/{userMention}/g, `<@${msg.author.id}>`)); 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);
}
}); });
} }