fix counter race condition
This commit is contained in:
parent
afcd63039c
commit
5152add32e
|
@ -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}\`\`\``
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue