Move beforeNewThread hook after validations, fix a couple bugs
parent
468d1fc037
commit
d03903ce80
|
@ -208,15 +208,16 @@ class Thread {
|
|||
}
|
||||
|
||||
// Save the log entry
|
||||
const logContent = formatters.formatStaffReplyLogMessage(moderator, text, threadMessage.message_number, { isAnonymous, attachmentLinks });
|
||||
const threadMessage = await this._addThreadMessageToDB({
|
||||
message_type: THREAD_MESSAGE_TYPE.TO_USER,
|
||||
user_id: moderator.id,
|
||||
user_name: fullModeratorName,
|
||||
body: logContent,
|
||||
body: '',
|
||||
is_anonymous: (isAnonymous ? 1 : 0),
|
||||
dm_message_id: dmMessage.id
|
||||
});
|
||||
const logContent = formatters.formatStaffReplyLogMessage(moderator, text, threadMessage.message_number, { isAnonymous, attachmentLinks });
|
||||
await this._updateThreadMessage(threadMessage.id, { body: logContent });
|
||||
|
||||
// Show the reply in the inbox thread
|
||||
const inboxContent = formatters.formatStaffReplyThreadMessage(moderator, text, threadMessage.message_number, { isAnonymous });
|
||||
|
|
|
@ -15,6 +15,17 @@ module.exports = {
|
|||
SYSTEM_TO_USER: 7
|
||||
},
|
||||
|
||||
// https://discord.com/developers/docs/resources/channel#channel-object-channel-types
|
||||
DISOCRD_CHANNEL_TYPES: {
|
||||
GUILD_TEXT: 0,
|
||||
DM: 1,
|
||||
GUILD_VOICE: 2,
|
||||
GROUP_DM: 3,
|
||||
GUILD_CATEGORY: 4,
|
||||
GUILD_NEWS: 5,
|
||||
GUILD_STORE: 6,
|
||||
},
|
||||
|
||||
ACCIDENTAL_THREAD_MESSAGES: [
|
||||
'ok',
|
||||
'okay',
|
||||
|
|
|
@ -13,7 +13,7 @@ const updates = require('./updates');
|
|||
|
||||
const Thread = require('./Thread');
|
||||
const {callBeforeNewThreadHooks} = require("../hooks/beforeNewThread");
|
||||
const {THREAD_STATUS} = require('./constants');
|
||||
const {THREAD_STATUS, DISOCRD_CHANNEL_TYPES} = require('./constants');
|
||||
|
||||
const MINUTES = 60 * 1000;
|
||||
const HOURS = 60 * MINUTES;
|
||||
|
@ -73,9 +73,6 @@ async function createNewThreadForUser(user, opts = {}) {
|
|||
throw new Error('Attempted to create a new thread for a user with an existing open thread!');
|
||||
}
|
||||
|
||||
const hookResult = await callBeforeNewThreadHooks({ user, opts });
|
||||
if (hookResult.cancelled) return;
|
||||
|
||||
// If set in config, check that the user's account is old enough (time since they registered on Discord)
|
||||
// If the account is too new, don't start a new thread and optionally reply to them with a message
|
||||
if (config.requiredAccountAge && ! ignoreRequirements) {
|
||||
|
@ -128,6 +125,10 @@ async function createNewThreadForUser(user, opts = {}) {
|
|||
}
|
||||
}
|
||||
|
||||
// Call any registered beforeNewThreadHooks
|
||||
const hookResult = await callBeforeNewThreadHooks({ user, opts });
|
||||
if (hookResult.cancelled) return;
|
||||
|
||||
// Use the user's name+discrim for the thread channel's name
|
||||
// Channel names are particularly picky about what characters they allow, so we gotta do some clean-up
|
||||
let cleanName = transliterate.slugify(user.username);
|
||||
|
@ -159,7 +160,10 @@ async function createNewThreadForUser(user, opts = {}) {
|
|||
// Attempt to create the inbox channel for this thread
|
||||
let createdChannel;
|
||||
try {
|
||||
createdChannel = await utils.getInboxGuild().createChannel(channelName, null, 'New Modmail thread', newThreadCategoryId);
|
||||
createdChannel = await utils.getInboxGuild().createChannel(channelName, DISOCRD_CHANNEL_TYPES.GUILD_TEXT, {
|
||||
reason: 'New Modmail thread',
|
||||
parentID: newThreadCategoryId,
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(`Error creating modmail channel for ${user.username}#${user.discriminator}!`);
|
||||
throw err;
|
||||
|
|
Loading…
Reference in New Issue