From 5152add32e8247b99ae28b973278341cd495671f Mon Sep 17 00:00:00 2001 From: "Jill \"oatmealine\" Monoids" Date: Sun, 12 Nov 2023 16:35:04 +0300 Subject: [PATCH] fix counter race condition --- src/lib/counter.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib/counter.ts b/src/lib/counter.ts index 9b39ef8..415a839 100644 --- a/src/lib/counter.ts +++ b/src/lib/counter.ts @@ -36,11 +36,11 @@ export async function getCounterData(type: string) { return counter; } -export async function updateCounter(bot: Client, counter: Counter) { +export async function updateCounter(bot: Client, counter: Counter, value: number) { const channel = await bot.channels.fetch(counter.channel) as TextChannel; const messageID = counter.message; - const content = `[${counter.emoji}] x${counter.value}`; + const content = `[${counter.emoji}] x${value}`; // bit janky // yeah you don't say @@ -64,7 +64,7 @@ export async function updateCounter(bot: Client, counter: Counter) { } } -export async function announceCounterUpdate(bot: Client, member: GuildMember, delta: number, counter: Counter) { +export async function announceCounterUpdate(bot: Client, member: GuildMember, delta: number, counter: Counter, value: number) { const channel = await bot.channels.fetch(counter.channel) as TextChannel; const embed = new EmbedBuilder() @@ -76,7 +76,7 @@ export async function announceCounterUpdate(bot: Client, member: GuildMember, de .setColor(member.displayColor) .setTimestamp() .setFooter({ - text: `[${counter.emoji}] x${counter.value}` + text: `[${counter.emoji}] x${value}` }); await channel.send({ @@ -88,8 +88,8 @@ export async function changeCounterInteraction(interaction: CommandInteraction, const counter = await getCounterData(type); const newCount = await changeCounter(amount, type); - await updateCounter(interaction.client, counter); - await announceCounterUpdate(interaction.client, member, amount, counter); + await updateCounter(interaction.client, counter, newCount); + await announceCounterUpdate(interaction.client, member, amount, counter, newCount); interaction.followUp({ content: `${counter.emoji} **You have ${amount > 0 ? 'increased' : 'decreased'} the counter.**\n\`\`\`diff\n ${newCount - amount}\n${getSign(amount)}${Math.abs(amount)}\n ${newCount}\`\`\`` });