35 lines
1.1 KiB
JavaScript
35 lines
1.1 KiB
JavaScript
/**
|
|
* Guild-specific settings (e.g. email ticket routing).
|
|
*/
|
|
const { mongoose } = require('../db-connection');
|
|
const { CONFIG } = require('../config');
|
|
|
|
const GuildSettings = mongoose.model('GuildSettings');
|
|
|
|
/**
|
|
* Get email ticket routing for a guild. Returns 'thread' or 'category'.
|
|
* If not set, defaults from CONFIG: thread if EMAIL_THREAD_CHANNEL_ID is set, else category.
|
|
* @param {string} guildId
|
|
* @returns {Promise<'thread'|'category'>}
|
|
*/
|
|
async function getEmailRouting(guildId) {
|
|
const doc = await GuildSettings.findOne({ guildId }).select('emailRouting').lean();
|
|
if (doc && doc.emailRouting) return doc.emailRouting;
|
|
return CONFIG.EMAIL_THREAD_CHANNEL_ID ? 'thread' : 'category';
|
|
}
|
|
|
|
/**
|
|
* Set email ticket routing for a guild.
|
|
* @param {string} guildId
|
|
* @param {'thread'|'category'} value
|
|
*/
|
|
async function setEmailRouting(guildId, value) {
|
|
await GuildSettings.findOneAndUpdate(
|
|
{ guildId },
|
|
{ $set: { emailRouting: value, updatedAt: new Date() } },
|
|
{ upsert: true, new: true }
|
|
);
|
|
}
|
|
|
|
module.exports = { getEmailRouting, setEmailRouting };
|