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" ) ;
22const { EmbedLimits } = require ( "@sapphire/discord.js-utilities" ) ;
33const { SubcommandWrapper } = require ( "../../classes" ) ;
44const { 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" ) ;
66const { timeConversion } = require ( "../../../shared" ) ;
77const { 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