diff --git a/src/data/threads.js b/src/data/threads.js index 9ed03a8..c4429d6 100644 --- a/src/data/threads.js +++ b/src/data/threads.js @@ -1,4 +1,4 @@ -const {User, Member} = require("eris"); +const {User, Member, Message} = require("eris"); const transliterate = require("transliteration"); const moment = require("moment"); @@ -53,9 +53,12 @@ function getHeaderGuildInfo(member) { /** * @typedef CreateNewThreadForUserOpts - * @property {boolean} quiet If true, doesn't ping mentionRole or reply with responseMessage - * @property {boolean} ignoreRequirements If true, creates a new thread even if the account doesn't meet requiredAccountAge - * @property {string} source A string identifying the source of the new thread + * @property {boolean} [quiet] If true, doesn't ping mentionRole or reply with responseMessage + * @property {boolean} [ignoreRequirements] If true, creates a new thread even if the account doesn't meet requiredAccountAge + * @property {boolean} [ignoreHooks] If true, doesn't call beforeNewThread hooks + * @property {Message} [message] Original DM message that is trying to start the thread, if there is one + * @property {string} [categoryId] Category where to open the thread + * @property {string} [source] A string identifying the source of the new thread */ /** @@ -68,6 +71,7 @@ function getHeaderGuildInfo(member) { async function createNewThreadForUser(user, opts = {}) { const quiet = opts.quiet != null ? opts.quiet : false; const ignoreRequirements = opts.ignoreRequirements != null ? opts.ignoreRequirements : false; + const ignoreHooks = opts.ignoreHooks != null ? opts.ignoreHooks : false; const existingThread = await findOpenThreadByUserId(user.id); if (existingThread) { @@ -127,7 +131,7 @@ async function createNewThreadForUser(user, opts = {}) { } // Call any registered beforeNewThreadHooks - const hookResult = await callBeforeNewThreadHooks({ user, opts }); + const hookResult = await callBeforeNewThreadHooks({ user, opts, message: opts.message }); if (hookResult.cancelled) return; // Use the user's name+discrim for the thread channel's name @@ -145,7 +149,7 @@ async function createNewThreadForUser(user, opts = {}) { console.log(`[NOTE] Creating new thread channel ${channelName}`); // Figure out which category we should place the thread channel in - let newThreadCategoryId = hookResult.categoryId || null; + let newThreadCategoryId = hookResult.categoryId || opts.categoryId || null; if (! newThreadCategoryId && config.categoryAutomation.newThreadFromServer) { // Categories for specific source guilds (in case of multiple main guilds) diff --git a/src/hooks/beforeNewThread.js b/src/hooks/beforeNewThread.js index bfde8bd..e581163 100644 --- a/src/hooks/beforeNewThread.js +++ b/src/hooks/beforeNewThread.js @@ -9,6 +9,7 @@ const Eris = require("eris"); /** * @typedef BeforeNewThreadHookData * @property {Eris.User} user + * @property {Eris.Message} [message] * @property {CreateNewThreadForUserOpts} opts * @property {Function} cancel * @property {BeforeNewThreadHook_SetCategoryId} setCategoryId @@ -48,6 +49,7 @@ beforeNewThread = (fn) => { /** * @param {{ * user: Eris.User, + * message?: Eris.Message, * opts: CreateNewThreadForUserOpts, * }} input * @return {Promise} diff --git a/src/main.js b/src/main.js index 0a5b533..45ce593 100644 --- a/src/main.js +++ b/src/main.js @@ -155,6 +155,7 @@ function initBaseMessageHandlers() { thread = await threads.createNewThreadForUser(msg.author, { source: "dm", + message: msg, }); }