Drop: Update claim messages to show the character name once cards are revealed

This commit is contained in:
2022-08-31 23:57:06 +02:00
parent 5d24a580d0
commit e1f1ad79e8

View File

@@ -65,6 +65,7 @@ module.exports = {
const filter = m => m.author.id === interaction.user.id; const filter = m => m.author.id === interaction.user.id;
const collector = message.createMessageComponentCollector({ componentType: ComponentType.Button, time: 25000 }); const collector = message.createMessageComponentCollector({ componentType: ComponentType.Button, time: 25000 });
let collectionReplies = [];
collector.on('collect', async i => { collector.on('collect', async i => {
let cardId = i.customId.split("-")[1]; let cardId = i.customId.split("-")[1];
if (await cards[cardId].userId) { i.reply({ content: "This card has already been claimed!", ephemeral: true }); return; } if (await cards[cardId].userId) { i.reply({ content: "This card has already been claimed!", ephemeral: true }); return; }
@@ -92,7 +93,8 @@ module.exports = {
id: cards[cardId].characterId id: cards[cardId].characterId
} }
}); });
i.reply({ content: `${i.user} (${claimUser.id}) claimed a card! [${cards[cardId].identifier}]`, ephemeral: false }); let reply = await i.reply({ content: `${i.user} (${claimUser.id}) claimed a card! [${cards[cardId].identifier}]`, ephemeral: false, fetchReply: true });
collectionReplies.push({ ref: reply, characterName: character.name });
let newRow = ReplyUtils.recreateComponents(i.message.components); let newRow = ReplyUtils.recreateComponents(i.message.components);
newRow.components[cardId].setLabel("Claimed"); newRow.components[cardId].setLabel("Claimed");
newRow.components[cardId].setStyle(ButtonStyle.Success); newRow.components[cardId].setStyle(ButtonStyle.Success);
@@ -104,7 +106,10 @@ module.exports = {
collector.on('end', async collected => { collector.on('end', async collected => {
let dropHistory = {}; let dropHistory = {};
for (reply of collectionReplies) {
//TODO: strings shouldn't be inlined. Needs refactoring
reply.ref.edit({ content: `${reply.ref.content.replace('a card', reply.characterName)}` });
}
console.log(`Collected ${collected.size} interactions.`); console.log(`Collected ${collected.size} interactions.`);
for (let card of cards) { for (let card of cards) {
if (!card.userId) { if (!card.userId) {