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 transliterate = require("transliteration");
|
||||||
const moment = require("moment");
|
const moment = require("moment");
|
||||||
|
@ -53,9 +53,12 @@ function getHeaderGuildInfo(member) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef CreateNewThreadForUserOpts
|
* @typedef CreateNewThreadForUserOpts
|
||||||
* @property {boolean} quiet If true, doesn't ping mentionRole or reply with responseMessage
|
* @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} [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} [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 = {}) {
|
async function createNewThreadForUser(user, opts = {}) {
|
||||||
const quiet = opts.quiet != null ? opts.quiet : false;
|
const quiet = opts.quiet != null ? opts.quiet : false;
|
||||||
const ignoreRequirements = opts.ignoreRequirements != null ? opts.ignoreRequirements : false;
|
const ignoreRequirements = opts.ignoreRequirements != null ? opts.ignoreRequirements : false;
|
||||||
|
const ignoreHooks = opts.ignoreHooks != null ? opts.ignoreHooks : false;
|
||||||
|
|
||||||
const existingThread = await findOpenThreadByUserId(user.id);
|
const existingThread = await findOpenThreadByUserId(user.id);
|
||||||
if (existingThread) {
|
if (existingThread) {
|
||||||
|
@ -127,7 +131,7 @@ async function createNewThreadForUser(user, opts = {}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call any registered beforeNewThreadHooks
|
// Call any registered beforeNewThreadHooks
|
||||||
const hookResult = await callBeforeNewThreadHooks({ user, opts });
|
const hookResult = await callBeforeNewThreadHooks({ user, opts, message: opts.message });
|
||||||
if (hookResult.cancelled) return;
|
if (hookResult.cancelled) return;
|
||||||
|
|
||||||
// Use the user's name+discrim for the thread channel's name
|
// 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}`);
|
console.log(`[NOTE] Creating new thread channel ${channelName}`);
|
||||||
|
|
||||||
// Figure out which category we should place the thread channel in
|
// 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) {
|
if (! newThreadCategoryId && config.categoryAutomation.newThreadFromServer) {
|
||||||
// Categories for specific source guilds (in case of multiple main guilds)
|
// Categories for specific source guilds (in case of multiple main guilds)
|
||||||
|
|
|
@ -9,6 +9,7 @@ const Eris = require("eris");
|
||||||
/**
|
/**
|
||||||
* @typedef BeforeNewThreadHookData
|
* @typedef BeforeNewThreadHookData
|
||||||
* @property {Eris.User} user
|
* @property {Eris.User} user
|
||||||
|
* @property {Eris.Message} [message]
|
||||||
* @property {CreateNewThreadForUserOpts} opts
|
* @property {CreateNewThreadForUserOpts} opts
|
||||||
* @property {Function} cancel
|
* @property {Function} cancel
|
||||||
* @property {BeforeNewThreadHook_SetCategoryId} setCategoryId
|
* @property {BeforeNewThreadHook_SetCategoryId} setCategoryId
|
||||||
|
@ -48,6 +49,7 @@ beforeNewThread = (fn) => {
|
||||||
/**
|
/**
|
||||||
* @param {{
|
* @param {{
|
||||||
* user: Eris.User,
|
* user: Eris.User,
|
||||||
|
* message?: Eris.Message,
|
||||||
* opts: CreateNewThreadForUserOpts,
|
* opts: CreateNewThreadForUserOpts,
|
||||||
* }} input
|
* }} input
|
||||||
* @return {Promise<BeforeNewThreadHookResult>}
|
* @return {Promise<BeforeNewThreadHookResult>}
|
||||||
|
|
|
@ -155,6 +155,7 @@ function initBaseMessageHandlers() {
|
||||||
|
|
||||||
thread = await threads.createNewThreadForUser(msg.author, {
|
thread = await threads.createNewThreadForUser(msg.author, {
|
||||||
source: "dm",
|
source: "dm",
|
||||||
|
message: msg,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue