Add categoryAutomation config option and make newThreadCategoryId a shortcut for the newThread sub-option. Add support for per-guild categories via categoryAutomation.
parent
ddc3f6425a
commit
073f3a87ea
|
@ -83,6 +83,8 @@ const defaultConfig = {
|
||||||
"attachmentStorage": "local",
|
"attachmentStorage": "local",
|
||||||
"attachmentStorageChannelId": null,
|
"attachmentStorageChannelId": null,
|
||||||
|
|
||||||
|
"categoryAutomation": {},
|
||||||
|
|
||||||
"port": 8890,
|
"port": 8890,
|
||||||
"url": null,
|
"url": null,
|
||||||
|
|
||||||
|
@ -155,4 +157,10 @@ if (! Array.isArray(finalConfig['inboxServerPermission'])) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// newThreadCategoryId is syntactic sugar for categoryAutomation.newThread
|
||||||
|
if (finalConfig.newThreadCategoryId) {
|
||||||
|
finalConfig.categoryAutomation.newThread = finalConfig.newThreadCategoryId;
|
||||||
|
delete finalConfig.newThreadCategoryId;
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = finalConfig;
|
module.exports = finalConfig;
|
||||||
|
|
|
@ -79,10 +79,48 @@ async function createNewThreadForUser(user, quiet = false) {
|
||||||
|
|
||||||
console.log(`[NOTE] Creating new thread channel ${channelName}`);
|
console.log(`[NOTE] Creating new thread channel ${channelName}`);
|
||||||
|
|
||||||
|
// Find which main guilds this user is part of
|
||||||
|
const mainGuilds = utils.getMainGuilds();
|
||||||
|
const userGuildData = new Map();
|
||||||
|
|
||||||
|
for (const guild of mainGuilds) {
|
||||||
|
let member = guild.members.get(user.id);
|
||||||
|
|
||||||
|
if (! member) {
|
||||||
|
try {
|
||||||
|
member = await bot.getRESTGuildMember(guild.id, user.id);
|
||||||
|
} catch (e) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (member) {
|
||||||
|
userGuildData.set(guild.id, { guild, member });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Figure out which category we should place the thread channel in
|
||||||
|
let newThreadCategoryId;
|
||||||
|
|
||||||
|
if (config.categoryAutomation.newThreadFromGuild) {
|
||||||
|
// Categories for specific source guilds (in case of multiple main guilds)
|
||||||
|
for (const [guildId, categoryId] of Object.entries(config.categoryAutomation.newThreadFromGuild)) {
|
||||||
|
if (userGuildData.has(guildId)) {
|
||||||
|
newThreadCategoryId = categoryId;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! newThreadCategoryId && config.categoryAutomation.newThread) {
|
||||||
|
// Blanket category id for all new threads (also functions as a fallback for the above)
|
||||||
|
newThreadCategoryId = config.categoryAutomation.newThread;
|
||||||
|
}
|
||||||
|
|
||||||
// Attempt to create the inbox channel for this thread
|
// Attempt to create the inbox channel for this thread
|
||||||
let createdChannel;
|
let createdChannel;
|
||||||
try {
|
try {
|
||||||
createdChannel = await utils.getInboxGuild().createChannel(channelName, null, 'New ModMail thread', config.newThreadCategoryId);
|
createdChannel = await utils.getInboxGuild().createChannel(channelName, null, 'New ModMail thread', newThreadCategoryId);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`Error creating modmail channel for ${user.username}#${user.discriminator}!`);
|
console.error(`Error creating modmail channel for ${user.username}#${user.discriminator}!`);
|
||||||
throw err;
|
throw err;
|
||||||
|
@ -136,21 +174,8 @@ async function createNewThreadForUser(user, quiet = false) {
|
||||||
let infoHeader = infoHeaderItems.join(', ');
|
let infoHeader = infoHeaderItems.join(', ');
|
||||||
|
|
||||||
// Guild member info
|
// Guild member info
|
||||||
const mainGuilds = utils.getMainGuilds();
|
for (const [guildId, guildData] of userGuildData.entries()) {
|
||||||
|
const {nickname, joinDate} = getHeaderGuildInfo(guildData.member);
|
||||||
for (const guild of mainGuilds) {
|
|
||||||
let member = guild.members.get(user.id);
|
|
||||||
|
|
||||||
if (! member) {
|
|
||||||
try {
|
|
||||||
member = await bot.getRESTGuildMember(guild.id, user.id);
|
|
||||||
} catch (e) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (member) {
|
|
||||||
const {nickname, joinDate} = getHeaderGuildInfo(member);
|
|
||||||
const headerStr = [
|
const headerStr = [
|
||||||
`NICKNAME **${nickname}**`,
|
`NICKNAME **${nickname}**`,
|
||||||
`JOINED **${joinDate}** ago`
|
`JOINED **${joinDate}** ago`
|
||||||
|
@ -159,8 +184,7 @@ async function createNewThreadForUser(user, quiet = false) {
|
||||||
if (mainGuilds.length === 1) {
|
if (mainGuilds.length === 1) {
|
||||||
infoHeader += `\n${headerStr}`;
|
infoHeader += `\n${headerStr}`;
|
||||||
} else {
|
} else {
|
||||||
infoHeader += `\n**[${guild.name}]** ${headerStr}`;
|
infoHeader += `\n**[${guildData.guild.name}]** ${headerStr}`;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue