Include DM message in beforeNewThread hook data. Allow specifying categoryId in createNewThreadForUser().
parent
aadda31069
commit
a3c1ed0a28
|
@ -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)
|
||||
|
|
|
@ -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<BeforeNewThreadHookResult>}
|
||||
|
|
|
@ -155,6 +155,7 @@ function initBaseMessageHandlers() {
|
|||
|
||||
thread = await threads.createNewThreadForUser(msg.author, {
|
||||
source: "dm",
|
||||
message: msg,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue