Close tickets after 5 days of inactivity

This commit is contained in:
Tarrgon
2026-01-16 09:17:53 -05:00
parent 09280d6eb1
commit 8c677dcf21
6 changed files with 38 additions and 3 deletions
+1
View File
@@ -17,6 +17,7 @@ export * from './ms-to-human';
export * from './name-sync';
export * from './note-utils';
export * from './oauth2';
export * from './private-help-utils';
export * from './record-utils';
export * from './refresh-commands';
export * from './search-regex';
+24
View File
@@ -0,0 +1,24 @@
import { Client, ThreadChannel } from 'discord.js';
import { Database } from '../shared/Database';
export async function closeOldTickets(client: Client) {
for (const ticket of await Database.getAllOpenPrivateHelpTickets()) {
try {
const thread = await client.channels.fetch(ticket.thread_id) as ThreadChannel;
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.');
thread.edit({
archived: true,
locked: true
});
}
} catch (e) {
console.error('Error closing ticket due to inactivity:');
console.error(e);
}
}
}