fix: sync and close error handling

This commit is contained in:
Isaac
2025-03-18 00:54:53 +00:00
parent 205d1c2329
commit c0bea3d32d
2 changed files with 28 additions and 15 deletions

View File

@@ -43,7 +43,12 @@ module.exports = async client => {
const guild = client.guilds.cache.get(ticket.guildId);
if (guild && guild.available && !client.channels.cache.has(ticket.id)) {
deleted += 0;
await client.tickets.finallyClose(ticket.id, { reason: 'channel deleted' });
try {
await client.tickets.finallyClose(ticket.id, { reason: 'channel deleted' });
} catch (error) {
client.log.warn('Failed to close ticket', ticket.id);
client.log.error(error);
}
}
}

View File

@@ -1216,11 +1216,8 @@ module.exports = class TicketManager {
closedBy = null,
reason = null,
}) {
if (this.$stale.has(ticketId)) this.$stale.delete(ticketId);
let ticket = await this.getTicket(ticketId);
const getMessage = this.client.i18n.getLocale(ticket.guild.locale);
this.$count.categories[ticket.categoryId].total -= 1;
this.$count.categories[ticket.categoryId][ticket.createdById] -= 1;
const { _count: { archivedMessages } } = await this.client.prisma.ticket.findUnique({
select: { _count: { select: { archivedMessages: true } } },
@@ -1248,15 +1245,26 @@ module.exports = class TicketManager {
data.pinnedMessageIds = [...pinned.keys()];
}
ticket = await this.client.prisma.ticket.update({
data,
include: {
category: true,
feedback: true,
guild: true,
},
where: { id: ticket.id },
});
try {
ticket = await this.client.prisma.ticket.update({
data,
include: {
category: true,
feedback: true,
guild: true,
},
where: { id: ticket.id },
});
if (this.$stale.has(ticketId)) this.$stale.delete(ticketId);
this.$count.categories[ticket.categoryId] ??= {};
this.$count.categories[ticket.categoryId].total -= 1;
this.$count.categories[ticket.categoryId][ticket.createdById] -= 1;
} catch (error) {
this.client.log.error(error);
return;
}
const guild = this.client.guilds.cache.get(ticket.guildId);
if (channel?.deletable) {
const member = closedBy ? channel.guild.members.cache.get(closedBy) : null;
@@ -1329,7 +1337,7 @@ module.exports = class TicketManager {
};
const dmEmbed = new ExtendedEmbedBuilder({
iconURL: channel.guild.iconURL(),
iconURL: guild.iconURL(),
text: ticket.guild.footer,
})
.setColor(ticket.guild.primaryColour)
@@ -1344,7 +1352,7 @@ module.exports = class TicketManager {
if (reason) dmEmbed.addFields(fields.reason);
try {
const creator = channel?.guild.members.cache.get(ticket.createdById);
const creator = guild.members.cache.get(ticket.createdById);
if (creator) {
await creator.send({
components,