Skip to content

Commit

Permalink
fix: creating the first ticket in a new guild
Browse files Browse the repository at this point in the history
Previously required `sync`ing (or restarting) to avoid the ticket number error.
  • Loading branch information
eartharoid committed May 31, 2023
1 parent 2e18fbb commit eccca34
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/lib/tickets/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,14 @@ module.exports = class TicketManager {
return await this.client.keyv.get(cacheKey);
}

getNextNumber(guildId) {
async getNextNumber(guildId) {
if (this.$numbers[guildId] === undefined) {
const { _max: { number: max } } = await this.client.prisma.ticket.aggregate({
_max: { number: true },
where: { guildId },
});
this.client.tickets.$numbers[guildId] = max ?? 0;
}
this.$numbers[guildId] += 1;
return this.$numbers[guildId];
}
Expand Down Expand Up @@ -379,7 +386,7 @@ module.exports = class TicketManager {
const guild = this.client.guilds.cache.get(category.guild.id);
const getMessage = this.client.i18n.getLocale(category.guild.locale);
const creator = await guild.members.fetch(interaction.user.id);
const number = this.getNextNumber(category.guild.id);
const number = await this.getNextNumber(category.guild.id);
const channelName = category.channelName
.replace(/{+\s?(user)?name\s?}+/gi, creator.user.username)
.replace(/{+\s?(nick|display)(name)?\s?}+/gi, creator.displayName)
Expand Down

0 comments on commit eccca34

Please sign in to comment.