(utils): Slice threads to 100 characters & await thread edits.

This commit is contained in:
2026-10-09 08:57:32 +08:00
parent eecfde1568
commit 5173b3fd2a
3 changed files with 16 additions and 14 deletions
+1 -1
View File
@@ -24,7 +24,7 @@ export default {
await interaction.editReply({ content: 'Ticket closed.' }); await interaction.editReply({ content: 'Ticket closed.' });
channel.edit({ channel.edit({
name: `[CLOSED] ${channel.name}`, name: `[CLOSED] ${channel.name}`.slice(0, 100),
archived: true, archived: true,
locked: true locked: true
}); });
+1 -1
View File
@@ -21,7 +21,7 @@ export default {
await interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Ticket closed.' }); await interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Ticket closed.' });
channel.edit({ channel.edit({
name: `[CLOSED] ${channel.name}`, name: `[CLOSED] ${channel.name}`.slice(0, 100),
archived: true, archived: true,
locked: true locked: true
}); });
+14 -12
View File
@@ -1,23 +1,25 @@
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, ChannelType, ChatInputCommandInteraction, Client, Guild, GuildMember, ModalBuilder, PrivateThreadChannel, TextChannel, TextInputStyle, ThreadAutoArchiveDuration, ThreadChannel, UserContextMenuCommandInteraction } from 'discord.js'; import { ActionRowBuilder, ButtonBuilder, ButtonStyle, ChannelType, ChatInputCommandInteraction, Client, Guild, GuildMember, ModalBuilder, PrivateThreadChannel, TextChannel, TextInputStyle, ThreadAutoArchiveDuration, ThreadChannel, UserContextMenuCommandInteraction } from 'discord.js';
import { Database } from '../shared/Database'; import { Database } from '../shared/Database';
import { createTextInput, createYesNoMenu } from './modal-utils'; import { createTextInput, createYesNoMenu } from '.';
export async function closeOldTickets(client: Client) { export async function closeOldTickets(client: Client) {
for (const ticket of await Database.getAllOpenPrivateHelpTickets()) { for (const ticket of await Database.getAllOpenPrivateHelpTickets()) {
const thread = await client.channels.fetch(ticket.thread_id) as ThreadChannel;
const latestMessage = (await thread.messages.fetch({ limit: 1 })).at(0);
// We only process tickets older than 5 days.
if (latestMessage && latestMessage.createdTimestamp > Date.now() - 432e6) continue;
try { try {
const thread = await client.channels.fetch(ticket.thread_id) as ThreadChannel; await Database.closePrivateHelpTicket(thread.id);
const latestMessage = (await thread.messages.fetch({ limit: 1 })).at(0);
if (latestMessage && latestMessage.createdTimestamp <= Date.now() - 432e6) {
await Database.closePrivateHelpTicket(thread.id);
await thread.send('This ticket has been closed due to inactivity.'); await thread.send('This ticket has been closed due to inactivity.');
thread.edit({ await thread.edit({
name: `[CLOSED] ${thread.name}`, name: `[CLOSED] ${thread.name}`,
archived: true, archived: true,
locked: true locked: true,
}); });
}
} catch (e) { } catch (e) {
console.error('Error closing ticket due to inactivity:', e); console.error('Error closing ticket due to inactivity:', e);
} }