queue
This commit is contained in:
@@ -138,7 +138,13 @@ async function handleButton(interaction) {
|
|||||||
if (pendingCloses.has(interaction.channel.id)) {
|
if (pendingCloses.has(interaction.channel.id)) {
|
||||||
return interaction.reply({ content: 'A close is already pending for this ticket.', ephemeral: true });
|
return interaction.reply({ content: 'A close is already pending for this ticket.', ephemeral: true });
|
||||||
}
|
}
|
||||||
await interaction.update({ content: `Closing ticket in ${timerSeconds} seconds. Use \`/cancel-close\` to abort.`, components: [] });
|
const cancelRow = new ActionRowBuilder().addComponents(
|
||||||
|
new ButtonBuilder()
|
||||||
|
.setCustomId('cancel_close')
|
||||||
|
.setLabel('Cancel Close')
|
||||||
|
.setStyle(ButtonStyle.Secondary)
|
||||||
|
);
|
||||||
|
await interaction.update({ content: `Closing ticket in ${timerSeconds} seconds.`, components: [cancelRow] });
|
||||||
const timerId = setTimeout(async () => {
|
const timerId = setTimeout(async () => {
|
||||||
pendingCloses.delete(interaction.channel.id);
|
pendingCloses.delete(interaction.channel.id);
|
||||||
const freshTicket = await Ticket.findOne({ discordThreadId: interaction.channel.id }).lean();
|
const freshTicket = await Ticket.findOne({ discordThreadId: interaction.channel.id }).lean();
|
||||||
@@ -156,6 +162,11 @@ async function handleButton(interaction) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (interaction.customId === 'cancel_close') {
|
if (interaction.customId === 'cancel_close') {
|
||||||
|
const pending = pendingCloses.get(interaction.channel.id);
|
||||||
|
if (pending) {
|
||||||
|
clearTimeout(pending.timeout);
|
||||||
|
pendingCloses.delete(interaction.channel.id);
|
||||||
|
}
|
||||||
return interaction.update({ content: 'Close cancelled.', components: [] });
|
return interaction.update({ content: 'Close cancelled.', components: [] });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,9 +35,6 @@ function processQueue(channel, state) {
|
|||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
state.processing = false;
|
state.processing = false;
|
||||||
// New window
|
// New window
|
||||||
if (state.queue.length > 3) {
|
|
||||||
logWarn('renameQueue', `Channel ${channel.name} has ${state.queue.length} renames queued`).catch(() => {});
|
|
||||||
}
|
|
||||||
const item = state.queue.shift();
|
const item = state.queue.shift();
|
||||||
if (!item) return;
|
if (!item) return;
|
||||||
item.started = true;
|
item.started = true;
|
||||||
@@ -77,19 +74,20 @@ function enqueueRename(channel, newName) {
|
|||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
// At limit — queue it
|
// At limit — replace pending rename with latest
|
||||||
const queueSize = state.queue.length + 1;
|
const isNew = state.queue.length === 0;
|
||||||
const queuedItem = { newName, started: false };
|
state.queue[0] = { newName, started: false };
|
||||||
state.queue.push(queuedItem);
|
const queuedItem = state.queue[0];
|
||||||
|
|
||||||
// Only notify if this rename is still waiting after ~2s.
|
if (isNew) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (queuedItem.started) return;
|
if (queuedItem.started) return;
|
||||||
const estMinutes = Math.max(1, Math.ceil((queueSize * RENAME_WINDOW_MS) / 60000));
|
const estMinutes = Math.ceil(RENAME_WINDOW_MS / 60000);
|
||||||
channel.send(`⏳ Channel will be renamed in ~${estMinutes} minute${estMinutes === 1 ? '' : 's'}.`).catch(() => {});
|
channel.send(`⏳ Channel will be renamed in ~${estMinutes} minute${estMinutes === 1 ? '' : 's'}.`).catch(() => {});
|
||||||
}, 2000);
|
}, 2000);
|
||||||
|
|
||||||
processQueue(channel, state);
|
processQueue(channel, state);
|
||||||
|
}
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user