2 Commits
Author SHA1 Message Date
nxbat 5173b3fd2a (utils): Slice threads to 100 characters & await thread edits. 2026-10-09 08:57:32 +08:00
nxbat eecfde1568 (buttons): Ticket threads now prefix [CLOSED].
This applies to both tickets closed manually & tickets closed after 5 days of inactivity.
2026-10-08 23:05:20 +08:00
3 changed files with 22 additions and 18 deletions
+1
View File
@@ -24,6 +24,7 @@ export default {
await interaction.editReply({ content: 'Ticket closed.' }); await interaction.editReply({ content: 'Ticket closed.' });
channel.edit({ channel.edit({
name: `[CLOSED] ${channel.name}`.slice(0, 100),
archived: true, archived: true,
locked: true locked: true
}); });
+1
View File
@@ -21,6 +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}`.slice(0, 100),
archived: true, archived: true,
locked: true locked: true
}); });
+20 -18
View File
@@ -1,35 +1,37 @@
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({
archived: true, name: `[CLOSED] ${thread.name}`,
locked: true archived: true,
}); locked: true,
} });
} catch (e) { } catch (e) {
console.error('Error closing ticket due to inactivity:'); console.error('Error closing ticket due to inactivity:', e);
console.error(e);
} }
} }
} }
export async function createPrivateHelpTicketThread(client: Client, guild: Guild, creator: GuildMember | null, reason: string, customTitle: string = '', additionalMembersToAdd: string[] = []): Promise<PrivateThreadChannel | null> { export async function createPrivateHelpTicketThread(client: Client, guild: Guild, creator: GuildMember | null, reason: string, customTitle: string = '', additionalMembersToAdd: string[] = []): Promise<PrivateThreadChannel | null> {
const guildSettings = await Database.getOrCreateSettings(guild.id); const settings = await Database.getOrCreateSettings(guild.id);
if (!guildSettings || !guildSettings.private_help_channel_id || !guildSettings.private_help_role_id) return null; if (!settings.private_help_channel_id || !settings.private_help_role_id) return null;
const channel = await client.channels.fetch(guildSettings.private_help_channel_id) as TextChannel; const channel = await client.channels.fetch(settings.private_help_channel_id) as TextChannel;
const thread = await channel.threads.create({ const thread = await channel.threads.create({
name: customTitle ? customTitle : (creator ? `${creator.displayName}'s Ticket` : 'Mod Ticket'), name: customTitle ? customTitle : (creator ? `${creator.displayName}'s Ticket` : 'Mod Ticket'),
@@ -54,11 +56,11 @@ export async function createPrivateHelpTicketThread(client: Client, guild: Guild
const row = new ActionRowBuilder<ButtonBuilder>().addComponents(closeButton, claimButton); const row = new ActionRowBuilder<ButtonBuilder>().addComponents(closeButton, claimButton);
await thread.send({ await thread.send({
content: `${creator} feel free to direct your questions at any <@&${guildSettings.private_help_role_id}>. Only you and staff members can see this channel.\n\n**Reason for contact:**\n${reason}\n\n-# Tickets will automatically close after 5 days of inactivity.`, content: `${creator} feel free to direct your questions at any <@&${settings.private_help_role_id}>. Only you and staff members can see this channel.\n\n**Reason for contact:**\n${reason}\n\n-# Tickets will automatically close after 5 days of inactivity.`,
components: [row], components: [row],
allowedMentions: { allowedMentions: {
users: [creator.id], users: [creator.id],
roles: [guildSettings.private_help_role_id] roles: [settings.private_help_role_id]
} }
}); });
} else { } else {