eco-bet: use askYesOrNo to clean up

This commit is contained in:
フズキ 2021-01-26 19:37:31 +01:00
parent 499aea9e66
commit 055a57e928
No known key found for this signature in database
GPG key ID: AD7750AB4625F1DD

View file

@ -75,17 +75,13 @@ export const BetCommand = new Command({
// else if (duration >= {threshold})
// return channel.send("Too long idk");
// [Potential pertinence to use the ask later on?]
// Ask target whether or not they want to take the bet.
const msg = await channel.send(`<@${target.id}>, do you want to take this bet of ${$(amount).pluralise("Mon", "s")}`);
await msg.react("✅");
await msg.react("⛔");
const takeBet = await askYesOrNo(
await channel.send(`<@${target.id}>, do you want to take this bet of ${$(amount).pluralise("Mon", "s")}`),
target.id
);
// Wait for a reaction.
msg.awaitReactions(
async (reaction, user) => {
// If target accepts: set bet up.
if (user.id === target.id && reaction.emoji.name === "✅") {
if (takeBet) {
// [ISSUE: volatile storage]
// Remove amount money from both parts to avoid duplication of money.
sender.money -= amount;
@ -101,19 +97,19 @@ export const BetCommand = new Command({
// When bet is over, give a vote to ask people their thoughts.
const voteMsg = await channel.send(`VOTE: do you think that <@${target.id}> has won the bet?`);
await voteMsg.react("✅");
await voteMsg.react("");
await voteMsg.react("");
// Filter reactions to only collect the pertinent ones.
voteMsg.awaitReactions(
(reaction, user) => {
return ["✅", ""].includes(reaction.emoji.name);
return ["✅", ""].includes(reaction.emoji.name);
},
// [Pertinence to make configurable on the fly.]
{ time: parseDuration("2m") }
).then(reactions => {
// Count votes
const ok = reactions.filter(reaction => reaction.emoji.name === "✅").size;
const no = reactions.filter(reaction => reaction.emoji.name === "").size;
const no = reactions.filter(reaction => reaction.emoji.name === "").size;
if (ok > no) {
receiver.money += amount * 2;
@ -132,16 +128,8 @@ export const BetCommand = new Command({
});
}, duration);
}
// If target refuses: notify and stop.
else if (user.id === target.id && reaction.emoji.name === "⛔")
else
await channel.send(`<@${target.id}> has rejected your bet, <@${author.id}>`);
return false;
},
// [Lesser pertinence to make configurable on the fly.]
// Wait for a minute, and delete the asking message after that.
{ time: 60000 }
).then(() => msg.delete());
}
}
})