[AB-77] deferring the reply for report with context interactions

do not defer the interaction all the time for modal interactions
This commit is contained in:
Sheldan
2022-12-10 12:59:47 +01:00
parent 072f32975a
commit 0461c8e4ec
3 changed files with 29 additions and 21 deletions

View File

@@ -17,6 +17,7 @@ import net.dv8tion.jda.api.interactions.modals.ModalMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import static dev.sheldan.abstracto.moderation.service.ReactionReportServiceBean.REACTION_REPORT_FAILURE_RESPONSE_TEMPLATE;
import static dev.sheldan.abstracto.moderation.service.ReactionReportServiceBean.REACTION_REPORT_RESPONSE_TEMPLATE;
@Component
@@ -46,27 +47,35 @@ public class ReportContextModalListener implements ModalInteractionListener {
.map(ModalMapping::getAsString)
.findFirst()
.orElse(null);
messageCache.getMessageFromCache(payload.getServerId(), payload.getChannelId(), payload.getMessageId()).thenAccept(cachedMessage -> {
ServerUser userReporting = ServerUser
.builder()
.serverId(model.getServerId())
.userId(cachedMessage.getAuthor().getAuthorId())
.isBot(cachedMessage.getAuthor().getIsBot())
.build();
reactionReportService.createReactionReport(cachedMessage, userReporting, context)
.thenAccept(unused -> {
interactionService.replyEmbed(REACTION_REPORT_RESPONSE_TEMPLATE, new Object(), model.getEvent());
log.info("Handled modal for message report with id {} in guild {} in channel {} on message {}",
model.getEvent().getModalId(), payload.getServerId(), payload.getChannelId(), payload.getMessageId());
componentPayloadManagementService.deletePayload(payload.getModalId());
}).exceptionally(throwable -> {
log.error("Failed to create reaction report in server {} on message {} in channel {} with interaction.",
model.getServerId(), cachedMessage.getMessageId(), model.getEvent().getChannel().getIdLong(), throwable);
model.getEvent().deferReply(true).queue(interactionHook -> {
messageCache.getMessageFromCache(payload.getServerId(), payload.getChannelId(), payload.getMessageId()).thenAccept(cachedMessage -> {
ServerUser userReporting = ServerUser
.builder()
.serverId(model.getServerId())
.userId(cachedMessage.getAuthor().getAuthorId())
.isBot(cachedMessage.getAuthor().getIsBot())
.build();
reactionReportService.createReactionReport(cachedMessage, userReporting, context)
.thenAccept(unused -> {
interactionService.sendMessageToInteraction(REACTION_REPORT_RESPONSE_TEMPLATE, new Object(), interactionHook);
log.info("Handled modal for message report with id {} in guild {} in channel {} on message {}",
model.getEvent().getModalId(), payload.getServerId(), payload.getChannelId(), payload.getMessageId());
componentPayloadManagementService.deletePayload(payload.getModalId());
}).exceptionally(throwable -> {
interactionService.sendMessageToInteraction(REACTION_REPORT_FAILURE_RESPONSE_TEMPLATE, new Object(), interactionHook);
log.error("Failed to create reaction report in server {} on message {} in channel {} with interaction.",
model.getServerId(), cachedMessage.getMessageId(), model.getEvent().getChannel().getIdLong(), throwable);
return null;
});
}).exceptionally(throwable -> {
interactionService.sendMessageToInteraction(REACTION_REPORT_FAILURE_RESPONSE_TEMPLATE, new Object(), interactionHook);
log.error("Failed to load reported message for reporting message {} in channel {} with context.",
model.getEvent().getMessage().getIdLong(), model.getEvent().getChannel().getIdLong(), throwable);
return null;
});
}).exceptionally(throwable -> {
log.error("Failed to load reported message.", throwable);
return null;
}, throwable -> {
log.error("Failed to acknowledge modal interaction for report context modal listener in guild {} on message {}.", model.getServerId(),
model.getEvent().getMessage() != null ? model.getEvent().getMessage().getIdLong() : 0, throwable);
});
return ModalInteractionListenerResult.ACKNOWLEDGED;

View File

@@ -71,6 +71,7 @@ public class ReactionReportServiceBean implements ReactionReportService {
private static final String REACTION_REPORT_TEMPLATE_KEY = "reactionReport_notification";
public static final String REACTION_REPORT_MODAL_ORIGIN = "reportMessageModal";
public static final String REACTION_REPORT_RESPONSE_TEMPLATE = "reactionReport_response";
public static final String REACTION_REPORT_FAILURE_RESPONSE_TEMPLATE = "reactionReport_failure_response";
public static final String REACTION_REPORT_COOLDOWN_RESPONSE_TEMPLATE = "reactionReport_cooldown_response";
public static final String REACTION_REPORT_OWN_MESSAGE_RESPONSE_TEMPLATE = "reactionReport_own_message_response";

View File

@@ -62,8 +62,6 @@ public class ModalInteractionListenerBean extends ListenerAdapter {
@Override
public void onModalInteraction(@Nonnull ModalInteractionEvent event) {
if(listenerList == null) return;
// TODO remove this and make this configurable
event.deferEdit().queue();
CompletableFuture.runAsync(() -> self.executeListenerLogic(event), modalInteractionExecutor).exceptionally(throwable -> {
log.error("Failed to execute listener logic in modal interaction event.", throwable);
return null;