mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2025-09-05 09:41:27 +03:00
fix: sync and close error handling
This commit is contained in:
@@ -43,7 +43,12 @@ module.exports = async client => {
|
|||||||
const guild = client.guilds.cache.get(ticket.guildId);
|
const guild = client.guilds.cache.get(ticket.guildId);
|
||||||
if (guild && guild.available && !client.channels.cache.has(ticket.id)) {
|
if (guild && guild.available && !client.channels.cache.has(ticket.id)) {
|
||||||
deleted += 0;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1216,11 +1216,8 @@ module.exports = class TicketManager {
|
|||||||
closedBy = null,
|
closedBy = null,
|
||||||
reason = null,
|
reason = null,
|
||||||
}) {
|
}) {
|
||||||
if (this.$stale.has(ticketId)) this.$stale.delete(ticketId);
|
|
||||||
let ticket = await this.getTicket(ticketId);
|
let ticket = await this.getTicket(ticketId);
|
||||||
const getMessage = this.client.i18n.getLocale(ticket.guild.locale);
|
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({
|
const { _count: { archivedMessages } } = await this.client.prisma.ticket.findUnique({
|
||||||
select: { _count: { select: { archivedMessages: true } } },
|
select: { _count: { select: { archivedMessages: true } } },
|
||||||
@@ -1248,15 +1245,26 @@ module.exports = class TicketManager {
|
|||||||
data.pinnedMessageIds = [...pinned.keys()];
|
data.pinnedMessageIds = [...pinned.keys()];
|
||||||
}
|
}
|
||||||
|
|
||||||
ticket = await this.client.prisma.ticket.update({
|
try {
|
||||||
data,
|
ticket = await this.client.prisma.ticket.update({
|
||||||
include: {
|
data,
|
||||||
category: true,
|
include: {
|
||||||
feedback: true,
|
category: true,
|
||||||
guild: true,
|
feedback: true,
|
||||||
},
|
guild: true,
|
||||||
where: { id: ticket.id },
|
},
|
||||||
});
|
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) {
|
if (channel?.deletable) {
|
||||||
const member = closedBy ? channel.guild.members.cache.get(closedBy) : null;
|
const member = closedBy ? channel.guild.members.cache.get(closedBy) : null;
|
||||||
@@ -1329,7 +1337,7 @@ module.exports = class TicketManager {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const dmEmbed = new ExtendedEmbedBuilder({
|
const dmEmbed = new ExtendedEmbedBuilder({
|
||||||
iconURL: channel.guild.iconURL(),
|
iconURL: guild.iconURL(),
|
||||||
text: ticket.guild.footer,
|
text: ticket.guild.footer,
|
||||||
})
|
})
|
||||||
.setColor(ticket.guild.primaryColour)
|
.setColor(ticket.guild.primaryColour)
|
||||||
@@ -1344,7 +1352,7 @@ module.exports = class TicketManager {
|
|||||||
if (reason) dmEmbed.addFields(fields.reason);
|
if (reason) dmEmbed.addFields(fields.reason);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const creator = channel?.guild.members.cache.get(ticket.createdById);
|
const creator = guild.members.cache.get(ticket.createdById);
|
||||||
if (creator) {
|
if (creator) {
|
||||||
await creator.send({
|
await creator.send({
|
||||||
components,
|
components,
|
||||||
|
Reference in New Issue
Block a user