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

View File

@@ -71,6 +71,7 @@ public class ReactionReportServiceBean implements ReactionReportService {
private static final String REACTION_REPORT_TEMPLATE_KEY = "reactionReport_notification"; 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_MODAL_ORIGIN = "reportMessageModal";
public static final String REACTION_REPORT_RESPONSE_TEMPLATE = "reactionReport_response"; 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_COOLDOWN_RESPONSE_TEMPLATE = "reactionReport_cooldown_response";
public static final String REACTION_REPORT_OWN_MESSAGE_RESPONSE_TEMPLATE = "reactionReport_own_message_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 @Override
public void onModalInteraction(@Nonnull ModalInteractionEvent event) { public void onModalInteraction(@Nonnull ModalInteractionEvent event) {
if(listenerList == null) return; if(listenerList == null) return;
// TODO remove this and make this configurable
event.deferEdit().queue();
CompletableFuture.runAsync(() -> self.executeListenerLogic(event), modalInteractionExecutor).exceptionally(throwable -> { CompletableFuture.runAsync(() -> self.executeListenerLogic(event), modalInteractionExecutor).exceptionally(throwable -> {
log.error("Failed to execute listener logic in modal interaction event.", throwable); log.error("Failed to execute listener logic in modal interaction event.", throwable);
return null; return null;