fix counter race condition

This commit is contained in:
Jill 2023-11-12 16:35:04 +03:00
parent afcd63039c
commit 5152add32e
Signed by: oat
GPG Key ID: 33489AA58A955108
1 changed files with 6 additions and 6 deletions

View File

@ -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}\`\`\``
});