p-queue
This commit is contained in:
20
services/channelQueue.js
Normal file
20
services/channelQueue.js
Normal file
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Serialized channel renames/moves to avoid Discord rate limits (e.g. 2 renames / 10 min per channel).
|
||||
*/
|
||||
const PQueue = require('p-queue').default;
|
||||
|
||||
const channelQueue = new PQueue({
|
||||
concurrency: 1,
|
||||
intervalCap: 2,
|
||||
interval: 10000
|
||||
});
|
||||
|
||||
function enqueueRename(channel, newName) {
|
||||
return channelQueue.add(() => channel.setName(newName));
|
||||
}
|
||||
|
||||
function enqueueMove(channel, categoryId) {
|
||||
return channelQueue.add(() => channel.setParent(categoryId, { lockPermissions: true }));
|
||||
}
|
||||
|
||||
module.exports = { channelQueue, enqueueRename, enqueueMove };
|
||||
@@ -2,20 +2,19 @@
|
||||
* 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.
|
||||
* If not set, defaults to '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';
|
||||
return 'category';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user