mirror of
https://github.com/nx-bat/discordbot-ng.git
synced 2026-11-11 07:13:37 -05:00
(utils): Slice threads to 100 characters & await thread edits.
This commit is contained in:
@@ -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
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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()) {
|
||||||
try {
|
|
||||||
const thread = await client.channels.fetch(ticket.thread_id) as ThreadChannel;
|
const thread = await client.channels.fetch(ticket.thread_id) as ThreadChannel;
|
||||||
const latestMessage = (await thread.messages.fetch({ limit: 1 })).at(0);
|
const latestMessage = (await thread.messages.fetch({ limit: 1 })).at(0);
|
||||||
if (latestMessage && latestMessage.createdTimestamp <= Date.now() - 432e6) {
|
|
||||||
|
// We only process tickets older than 5 days.
|
||||||
|
if (latestMessage && latestMessage.createdTimestamp > Date.now() - 432e6) continue;
|
||||||
|
|
||||||
|
try {
|
||||||
await Database.closePrivateHelpTicket(thread.id);
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user