Skip to content

Commit 2e6b658

Browse files
authored
seconding fixes (#658)
- fix seconding a toast removing seconder from recipients on embed - `toastEmbed` takes array of ids instead of set of ids (most flows submit an array of a single id, set deduping only used in one flow) - fix reward summary early out not catching no reciept state (companyReciept guaranteed to include 1 or more keys)
1 parent 2ab4f54 commit 2e6b658

7 files changed

Lines changed: 15 additions & 21 deletions

File tree

source/frontend/buttons/secondtoast.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,9 @@ module.exports = new ButtonWrapper(mainId, 3000,
2929
const [season] = await logicLayer.seasons.findOrCreateCurrentSeason(interaction.guild.id);
3030
const previousCompanyLevel = Company.getLevel(origin.company.getXP(await logicLayer.hunters.getCompanyHunterMap(interaction.guild.id)));
3131

32-
const recipientIds = [];
33-
originalToast.Recipients.forEach(reciept => {
34-
if (reciept.recipientId !== interaction.user.id) {
35-
recipientIds.push(reciept.recipientId);
36-
}
37-
});
32+
const recipientIds = originalToast.Recipients.map(receipt => receipt.recipientId);
3833

39-
const hunterReceipts = await logicLayer.toasts.secondToast(origin.hunter, originalToast, origin.company, recipientIds, season.id);
34+
const hunterReceipts = await logicLayer.toasts.secondToast(origin.hunter, originalToast, origin.company, recipientIds.filter(id => id !== interaction.user.id), season.id);
4035

4136
const { companyReceipt, goalProgress } = await logicLayer.goals.progressGoal(origin.company, "secondings", origin.hunter, season);
4237
companyReceipt.guildName = interaction.guild.name;

source/frontend/commands/toast.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ module.exports = new CommandWrapper(mainId, "Raise a toast to other bounty hunte
7171
let hunterMap = await logicLayer.hunters.getCompanyHunterMap(interaction.guild.id);
7272

7373
const previousCompanyLevel = Company.getLevel(origin.company.getXP(hunterMap));
74-
const { toastId, hunterReceipts } = await logicLayer.toasts.raiseToast(interaction.guild, origin.company, interaction.user.id, validatedToasteeIds, hunterMap, season.id, toastText, imageURL);
74+
const { toastId, hunterReceipts } = await logicLayer.toasts.raiseToast(interaction.guild, origin.company, interaction.user.id, Array.from(validatedToasteeIds), hunterMap, season.id, toastText, imageURL);
7575
let goalProgress = { goalCompleted: false, currentGP: 0, requiredGP: 0 };
7676
let companyReceipt = {};
7777
if (hunterReceipts.size > 0) {
@@ -87,7 +87,7 @@ module.exports = new CommandWrapper(mainId, "Raise a toast to other bounty hunte
8787
}
8888
companyReceipt.guildName = interaction.guild.name;
8989

90-
const embeds = [toastEmbed(origin.company.toastThumbnailURL, toastText, validatedToasteeIds, interaction.member, goalProgress, imageURL)];
90+
const embeds = [toastEmbed(origin.company.toastThumbnailURL, toastText, Array.from(validatedToasteeIds), interaction.member, goalProgress, imageURL)];
9191
if (goalProgress.goalCompleted) {
9292
embeds.push(goalCompletionEmbed(goalProgress.contributorIds));
9393
}

source/frontend/context_menus/Raise_a_Toast.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ module.exports = new UserContextMenuWrapper(mainId, PermissionFlagsBits.SendMess
5353
let hunterMap = await logicLayer.hunters.getCompanyHunterMap(interaction.guild.id);
5454

5555
const previousCompanyLevel = Company.getLevel(origin.company.getXP(hunterMap));
56-
const { toastId, hunterReceipts } = await logicLayer.toasts.raiseToast(modalSubmission.guild, origin.company, interaction.user.id, new Set([interaction.targetId]), hunterMap, season.id, toastText, null);
56+
const { toastId, hunterReceipts } = await logicLayer.toasts.raiseToast(modalSubmission.guild, origin.company, interaction.user.id, [interaction.targetId], hunterMap, season.id, toastText, null);
5757
let goalProgress = { goalCompleted: false, currentGP: 0, requiredGP: 0 };
5858
let companyReceipt = {};
5959
if (hunterReceipts.size > 0) {
@@ -69,7 +69,7 @@ module.exports = new UserContextMenuWrapper(mainId, PermissionFlagsBits.SendMess
6969
}
7070
companyReceipt.guildName = interaction.guild.name;
7171

72-
const embeds = [toastEmbed(origin.company.toastThumbnailURL, toastText, new Set([interaction.targetId]), modalSubmission.member, goalProgress)];
72+
const embeds = [toastEmbed(origin.company.toastThumbnailURL, toastText, [interaction.targetId], modalSubmission.member, goalProgress)];
7373
if (goalProgress.goalCompleted) {
7474
embeds.push(goalCompletionEmbed(goalProgress.contributorIds));
7575
}

source/frontend/shared/dAPISerializers.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,17 +543,17 @@ function bountyEmbed(bounty, posterGuildMember, posterLevel, shouldOmitRewardsFi
543543
/**
544544
* @param {string} thumbnailURL
545545
* @param {string} toastText
546-
* @param {Set<string>} recipientIdSet
546+
* @param {string[]} recipientIds
547547
* @param {GuildMember} senderMember
548548
* @param {{ goalCompleted: boolean; currentGP: number; requiredGP: number; }} goalProgress
549549
* @param {string | null} imageURL
550550
* @param {string[] | undefined} seconderMentions
551551
*/
552-
function toastEmbed(thumbnailURL, toastText, recipientIdSet, senderMember, goalProgress, imageURL, seconderMentions) {
552+
function toastEmbed(thumbnailURL, toastText, recipientIds, senderMember, goalProgress, imageURL, seconderMentions) {
553553
const embed = new EmbedBuilder().setColor("e5b271")
554554
.setThumbnail(thumbnailURL)
555555
.setTitle(toastText)
556-
.setDescription(`A toast to ${sentenceListEN(Array.from(recipientIdSet).map(id => userMention(id)))}!`)
556+
.setDescription(`A toast to ${sentenceListEN(recipientIds.map(id => userMention(id)))}!`)
557557
.setFooter({ text: senderMember.displayName, iconURL: senderMember.user.avatarURL() });
558558
if (goalProgress.goalCompleted) {
559559
embed.addFields({ name: "Server Goal", value: `${fillableTextBar(15, 15, 15)} Complete!` });

source/frontend/shared/stringConstructors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function sentenceListEN(texts, isMutuallyExclusive) {
9797
* @param {number} companyMaxBountySlots
9898
*/
9999
function rewardSummary(actionType, companyReceipt, hunterReceipts, companyMaxBountySlots) {
100-
if (Object.keys(companyReceipt).length + hunterReceipts.size === 0) {
100+
if (Object.keys(companyReceipt).length + hunterReceipts.size === 1) { // `guildName` is a guaranteed key in `companyReciept`
101101
return "";
102102
}
103103

source/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,9 @@ dAPIClient.on(Events.MessageReactionAdd, async (reaction, user) => {
290290
const descendingRanks = await logicBlob.ranks.findAllRanks(guild.id);
291291
const guildRoles = await guild.roles.fetch();
292292
let goalProgress;
293+
const recipientIds = [hostMessage.author.id];
293294
if (existingToast) {
294295
// If extant toast, create Seconding
295-
const recipientIds = [hostMessage.author.id];
296296
const companyReceipt = { guildName: guild.name };
297297
goalProgress = await logicBlob.goals.progressGoal(company, "secondings", interactingHunter, season);
298298
if (goalProgress.gpContributed > 0) {
@@ -320,9 +320,8 @@ dAPIClient.on(Events.MessageReactionAdd, async (reaction, user) => {
320320
} else {
321321
// If no extant toast, create Toast
322322
const hunterMap = await logicBlob.hunters.getCompanyHunterMap(guild.id);
323-
const recipientSet = new Set([hostMessage.author.id]);
324323
const toastText = `${randomCongratulatoryPhrase()}! Reaction Toast: ${hostMessage.url}`;
325-
const { toastId, hunterReceipts } = await logicBlob.toasts.raiseToast(guild, company, user.id, recipientSet, hunterMap, season.id, toastText, null, hostMessage.id);
324+
const { toastId, hunterReceipts } = await logicBlob.toasts.raiseToast(guild, company, user.id, recipientIds, hunterMap, season.id, toastText, null, hostMessage.id);
326325

327326
const companyReceipt = { guildName: guild.name };
328327
const currentCompanyLevel = Company.getLevel(company.getXP(await logicBlob.hunters.getCompanyHunterMap(guild.id)));
@@ -335,7 +334,7 @@ dAPIClient.on(Events.MessageReactionAdd, async (reaction, user) => {
335334
}
336335

337336
reaction.message.channel.send({
338-
embeds: [toastEmbed(company.toastThumbnailURL, toastText, recipientSet, await guild.members.fetch(user.id), goalProgress)],
337+
embeds: [toastEmbed(company.toastThumbnailURL, toastText, recipientIds, await guild.members.fetch(user.id), goalProgress)],
339338
components: [secondingButtonRow(toastId)],
340339
}).then(async message => {
341340
await logicBlob.toasts.setToastMessageId(toastId, message.id);

source/logic/toasts.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function isToastCrit(critRoll, effectiveToastLevel) {
8585
* @param {Guild} guild
8686
* @param {Company} company
8787
* @param {string} senderId
88-
* @param {Set<string>} toasteeIds
88+
* @param {string[]} toasteeIds
8989
* @param {Map<string, Hunter>} hunterMap
9090
* @param {string} seasonId
9191
* @param {string} toastText
@@ -123,7 +123,7 @@ async function raiseToast(guild, company, senderId, toasteeIds, hunterMap, seaso
123123
let critValue = 0;
124124
const startingSenderLevel = hunterMap.get(senderId).getLevel(company.xpCoefficient);
125125
const xpMultiplierString = company.festivalMultiplierString("xp");
126-
for (const id of toasteeIds.values()) {
126+
for (const id of toasteeIds) {
127127
const rawToast = { toastId: toast.id, recipientId: id, isRewarded: !hunterIdsToastedInLastDay.has(id) && rewardsAvailable > 0, wasCrit: false };
128128
if (rawToast.isRewarded) {
129129
const hunterReceipt = {};

0 commit comments

Comments
 (0)