|
1 | | -const { MessageFlags, userMention, channelMention, bold, ModalBuilder, LabelBuilder, UserSelectMenuBuilder, StringSelectMenuBuilder } = require("discord.js"); |
| 1 | +const { MessageFlags, userMention, channelMention, bold, ModalBuilder, LabelBuilder, UserSelectMenuBuilder, StringSelectMenuBuilder, PermissionFlagsBits, strikethrough } = require("discord.js"); |
2 | 2 | const { timeConversion } = require("../../../shared"); |
3 | | -const { commandMention, bountyEmbed, goalCompletionEmbed, sendRewardMessage, syncRankRoles, unarchiveAndUnlockThread, rewardSummary, consolidateHunterReceipts, refreshReferenceChannelScoreboardSeasonal, refreshReferenceChannelScoreboardOverall, sentenceListEN, butIgnoreInteractionCollectorErrors, selectOptionsFromBounties, butIgnoreErrorIf, isUnknownGuildScheduledEventError, isMissingPermissionError } = require("../../shared"); |
| 3 | +const { commandMention, bountyEmbed, goalCompletionEmbed, sendRewardMessage, syncRankRoles, unarchiveAndUnlockThread, rewardSummary, consolidateHunterReceipts, refreshReferenceChannelScoreboardSeasonal, refreshReferenceChannelScoreboardOverall, butIgnoreInteractionCollectorErrors, selectOptionsFromBounties, butIgnoreErrorIf, isUnknownGuildScheduledEventError, isMissingPermissionError, getBountyBoardThread, refreshBountyBoardThread, auditReasonBountyComplete } = require("../../shared"); |
4 | 4 | const { SubcommandWrapper } = require("../../classes"); |
5 | 5 | const { Company } = require("../../../database/models"); |
6 | 6 | const { SKIP_INTERACTION_HANDLING } = require("../../../constants"); |
@@ -111,20 +111,19 @@ module.exports = new SubcommandWrapper("complete", "Close one of your open bount |
111 | 111 | if (origin.company.bountyBoardId) { |
112 | 112 | acknowledgeOptions.content += `${channelMention(bounty.postingId)}, was completed!`; |
113 | 113 | modalSubmission.editReply(acknowledgeOptions); |
114 | | - const bountyBoard = await modalSubmission.guild.channels.fetch(origin.company.bountyBoardId); |
115 | | - bountyBoard.threads.fetch(bounty.postingId).then(async thread => { |
116 | | - await unarchiveAndUnlockThread(thread, "bounty complete"); |
117 | | - thread.setAppliedTags([origin.company.bountyBoardCompletedTagId]); |
118 | | - thread.send({ content: rewardMessageContent, flags: MessageFlags.SuppressNotifications }); |
119 | | - return thread.fetchStarterMessage(); |
120 | | - }).then(async posting => { |
121 | | - posting.edit({ |
122 | | - embeds: [bountyEmbed(bounty, modalSubmission.member, origin.hunter.getLevel(origin.company.xpCoefficient), true, origin.company, new Set([...validatedHunters.keys()]), await bounty.getScheduledEvent(modalSubmission.guild.scheduledEvents), goalProgress)], |
123 | | - components: [] |
124 | | - }).then(() => { |
125 | | - posting.channel.setArchived(true, "bounty completed"); |
126 | | - }); |
127 | | - }); |
| 114 | + |
| 115 | + const auditLogReason = auditReasonBountyComplete; |
| 116 | + const bountyThread = await getBountyBoardThread(modalSubmission.guild, origin.company.bountyBoardId, bounty.postingId); |
| 117 | + if (bountyThread) { |
| 118 | + if (modalSubmission.guild.members.me.permissions.has(PermissionFlagsBits.ManageThreads)) { |
| 119 | + refreshBountyBoardThread(await bountyThread.fetchStarterMessage(), { embed: bountyEmbed(bounty, modalSubmission.member, origin.hunter.getLevel(origin.company.xpCoefficient), true, origin.company, new Set([...validatedHunters.keys()]), await bounty.getScheduledEvent(modalSubmission.guild.scheduledEvents), goalProgress), title: strikethrough(bounty.title) }, auditLogReason); |
| 120 | + await unarchiveAndUnlockThread(bountyThread, auditLogReason); |
| 121 | + } |
| 122 | + if (bountyThread.sendable) { |
| 123 | + bountyThread.send({ content: rewardMessageContent, flags: MessageFlags.SuppressNotifications }); |
| 124 | + } |
| 125 | + bountyThread.edit({ archived: true, appliedTags: [origin.company.bountyBoardCompletedTagId], reason: auditLogReason }); |
| 126 | + } |
128 | 127 | } else { |
129 | 128 | acknowledgeOptions.content += `${bold(bounty.title)}, was completed!`; |
130 | 129 | modalSubmission.editReply(acknowledgeOptions).then(message => { |
|
0 commit comments