Skip to content

Commit 2ab4f54

Browse files
authored
#653: fix crash on attempt to make bounty event while missing permission (#660)
* #653: fix crash on attempt to make bounty event while missing permission * check permission instead of sending request and catching error * update changelog
1 parent f4e736f commit 2ab4f54

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# BountyBot Change Log
22
## BountyBot Version 2.11.1ib:
3+
- Fixed a crash when attempting to make an event for a bounty while missing permission
34
- Fixed some issues where rank calculation was assigning the incorrect rank or failing to announce rank ups
45
## BountyBot Version 2.11.0fib:
56
### Reaction Toasts

source/frontend/commands/bounty/post.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const { ActionRowBuilder, StringSelectMenuBuilder, ModalBuilder, TextInputBuilder, TextInputStyle, MessageFlags, ComponentType, unorderedList, LabelBuilder, FileUploadBuilder } = require("discord.js");
1+
const { ActionRowBuilder, StringSelectMenuBuilder, ModalBuilder, TextInputBuilder, TextInputStyle, MessageFlags, ComponentType, unorderedList, LabelBuilder, FileUploadBuilder, PermissionFlagsBits } = require("discord.js");
22
const { EmbedLimits } = require("@sapphire/discord.js-utilities");
33
const { SubcommandWrapper } = require("../../classes");
44
const { Bounty, Hunter } = require("../../../database/models");
5-
const { emojiFromNumber, textsHaveAutoModInfraction, commandMention, bountyEmbed, bountyControlPanelSelectRow, addCompanyAnnouncementPrefix, syncRankRoles, validateScheduledEventTimestamps, bountyScheduledEventPayload, butIgnoreInteractionCollectorErrors, refreshReferenceChannelScoreboardSeasonal, refreshReferenceChannelScoreboardOverall } = require("../../shared");
5+
const { emojiFromNumber, textsHaveAutoModInfraction, commandMention, bountyEmbed, bountyControlPanelSelectRow, addCompanyAnnouncementPrefix, syncRankRoles, validateScheduledEventTimestamps, bountyScheduledEventPayload, butIgnoreInteractionCollectorErrors, refreshReferenceChannelScoreboardSeasonal, refreshReferenceChannelScoreboardOverall, isMissingPermissionError } = require("../../shared");
66
const { timeConversion } = require("../../../shared");
77
const { SKIP_INTERACTION_HANDLING } = require("../../../constants");
88

@@ -129,6 +129,7 @@ module.exports = new SubcommandWrapper("post", "Post your own bounty (+1 XP)",
129129
rawBounty.description = description;
130130
}
131131
const errors = [];
132+
const warnings = [];
132133

133134
const attachmentFileCollection = modalSubmission.fields.getUploadedFiles(imageId);
134135
if (attachmentFileCollection) {
@@ -141,7 +142,7 @@ module.exports = new SubcommandWrapper("post", "Post your own bounty (+1 XP)",
141142
const startTimestamp = parseInt(modalSubmission.fields.getTextInputValue(startTimestampId));
142143
const endTimestamp = parseInt(modalSubmission.fields.getTextInputValue(endTimestampId));
143144
if (startTimestamp || endTimestamp) {
144-
errors.push(...validateScheduledEventTimestamps(startTimestamp, endTimestamp))
145+
errors.push(...validateScheduledEventTimestamps(startTimestamp, endTimestamp));
145146
}
146147

147148
if (errors.length > 0) {
@@ -167,8 +168,12 @@ module.exports = new SubcommandWrapper("post", "Post your own bounty (+1 XP)",
167168
let event = null;
168169
if (startTimestamp && endTimestamp) {
169170
const eventPayload = bountyScheduledEventPayload(title, modalSubmission.member.displayName, rawBounty.slotNumber, description, rawBounty.attachmentURL, startTimestamp, endTimestamp);
170-
event = await modalSubmission.guild.scheduledEvents.create(eventPayload);
171-
rawBounty.scheduledEventId = event.id;
171+
if (modalSubmission.guild.members.me.permissions.has(PermissionFlagsBits.CreateEvents)) {
172+
event = await modalSubmission.guild.scheduledEvents.create(eventPayload);
173+
rawBounty.scheduledEventId = event.id;
174+
} else {
175+
warnings.push(`Could not create an Event for this bounty; ${modalSubmission.client.user} is missing permission to create Events.`);
176+
}
172177
}
173178

174179
const bounty = await logicLayer.bounties.createBounty(rawBounty);
@@ -177,6 +182,9 @@ module.exports = new SubcommandWrapper("post", "Post your own bounty (+1 XP)",
177182
await origin.hunter.reload();
178183
const embeds = [bountyEmbed(bounty, modalSubmission.member, origin.hunter.getLevel(origin.company.xpCoefficient), false, origin.company, new Set(), event)];
179184
modalSubmission.reply(addCompanyAnnouncementPrefix(origin.company, { content: `${modalSubmission.member} has posted a new bounty:`, embeds })).then(() => {
185+
if (warnings.length > 0) {
186+
modalSubmission.followUp({ content: `The following issues were encountered while posting your bounty (your bounty was still posted):\n${unorderedList(warnings)}`, flags: MessageFlags.Ephemeral });
187+
}
180188
if (origin.company.bountyBoardId) {
181189
modalSubmission.guild.channels.fetch(origin.company.bountyBoardId).then(bountyBoard => {
182190
return bountyBoard.threads.create({

0 commit comments

Comments
 (0)