Skip to content

Commit

Permalink
Remove /raid_map related code (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Villavicencio authored Jun 21, 2024
1 parent 23715b2 commit ff8ccde
Show file tree
Hide file tree
Showing 52 changed files with 7 additions and 1,034 deletions.
61 changes: 0 additions & 61 deletions src/main/java/com/deahtstroke/rivenbot/enums/Raid.java

This file was deleted.

110 changes: 0 additions & 110 deletions src/main/java/com/deahtstroke/rivenbot/enums/RaidEncounter.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.deahtstroke.rivenbot.enums.SlashCommand;
import com.deahtstroke.rivenbot.exception.ResourceNotFoundException;
import com.deahtstroke.rivenbot.handler.ApplicationCommandSource;
import com.deahtstroke.rivenbot.handler.RaidMapHandler;
import com.deahtstroke.rivenbot.handler.RaidStatsHandler;
import com.deahtstroke.rivenbot.handler.WeeklyDungeonHandler;
import com.deahtstroke.rivenbot.handler.WeeklyRaidHandler;
Expand All @@ -21,14 +20,12 @@ public class ApplicationCommandFactory implements SlashCommandHandler<Applicatio
private final Map<SlashCommand, ApplicationCommandSource> messageFactory;

public ApplicationCommandFactory(
RaidMapHandler raidMapHandler,
WeeklyRaidHandler weeklyRaidHandler,
WeeklyDungeonHandler weeklyDungeonHandler,
RaidStatsHandler raidStatsHandler) {
this.messageFactory = Map.of(
SlashCommand.WEEKLY_RAID, weeklyRaidHandler,
SlashCommand.WEEKLY_DUNGEON, weeklyDungeonHandler,
SlashCommand.RAID_MAP, raidMapHandler,
SlashCommand.RAID_STATS, raidStatsHandler);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.deahtstroke.rivenbot.enums.SlashCommand;
import com.deahtstroke.rivenbot.exception.ResourceNotFoundException;
import com.deahtstroke.rivenbot.handler.AutocompleteSource;
import com.deahtstroke.rivenbot.handler.RaidMapHandler;
import com.deahtstroke.rivenbot.handler.RaidStatsHandler;
import java.util.Map;
import java.util.Objects;
Expand All @@ -15,10 +14,8 @@ public class AutocompleteFactory implements SlashCommandHandler<AutocompleteSour
private final Map<SlashCommand, AutocompleteSource> autocompleteFactory;

public AutocompleteFactory(
RaidMapHandler raidMapHandler,
RaidStatsHandler raidStatsHandler) {
this.autocompleteFactory = Map.of(
SlashCommand.RAID_MAP, raidMapHandler,
SlashCommand.RAID_STATS, raidStatsHandler);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,15 @@

import com.deahtstroke.rivenbot.dto.discord.Interaction;
import com.deahtstroke.rivenbot.dto.discord.InteractionResponse;
import com.deahtstroke.rivenbot.enums.InteractionResponseType;
import com.deahtstroke.rivenbot.enums.InteractionType;
import com.deahtstroke.rivenbot.enums.SlashCommand;
import com.deahtstroke.rivenbot.exception.BaseException;
import com.deahtstroke.rivenbot.factory.ApplicationCommandFactory;
import com.deahtstroke.rivenbot.factory.AutocompleteFactory;
import com.deahtstroke.rivenbot.factory.MessageComponentFactory;
import com.deahtstroke.rivenbot.service.RaidInfographicsService;
import com.deahtstroke.rivenbot.util.HttpResponseUtils;
import java.io.IOException;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.ProblemDetail;
import org.springframework.stereotype.Service;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.reactive.function.server.ServerResponse;
Expand All @@ -32,17 +23,14 @@ public class InteractionHandler {
private final ApplicationCommandFactory applicationCommandFactory;
private final AutocompleteFactory autocompleteFactory;
private final MessageComponentFactory messageComponentFactory;
private final RaidInfographicsService raidInfographicsService;

public InteractionHandler(
ApplicationCommandFactory applicationCommandFactory,
AutocompleteFactory autocompleteFactory,
MessageComponentFactory messageComponentFactory,
RaidInfographicsService raidInfographicsService) {
MessageComponentFactory messageComponentFactory) {
this.applicationCommandFactory = applicationCommandFactory;
this.autocompleteFactory = autocompleteFactory;
this.messageComponentFactory = messageComponentFactory;
this.raidInfographicsService = raidInfographicsService;
}

/**
Expand All @@ -56,23 +44,10 @@ public Mono<ServerResponse> handle(ServerRequest request) {
return request.bodyToMono(Interaction.class)
.flatMap(interaction -> {
InteractionType interactionType = InteractionType.findByValue(interaction.getType());
ParameterizedTypeReference<MultiValueMap<String, HttpEntity<?>>> multiValueReference =
new ParameterizedTypeReference<>() {
};

Mono<InteractionResponse> interactionResponse = resolveResponse(interaction,
interactionType);
return interactionResponse
.flatMap(response -> {
boolean hasAttachments =
!Objects.equals(response.getType(), InteractionResponseType.PONG.getType())
&& CollectionUtils.isNotEmpty(response.getData().getAttachments());

return ServerResponse.ok().body(hasAttachments ?
BodyInserters.fromProducer(attachmentsResponse(interaction, response),
multiValueReference) :
BodyInserters.fromValue(response));
})
.flatMap(response -> ServerResponse.ok().body(BodyInserters.fromValue(response)))
.onErrorResume(BaseException.class,
error -> {
ProblemDetail problemDetail = ProblemDetail.forStatus(error.getStatus());
Expand Down Expand Up @@ -103,11 +78,4 @@ private Mono<InteractionResponse> resolveResponse(Interaction interaction,
case PING -> Mono.just(InteractionResponse.PING());
};
}

private Mono<MultiValueMap<String, HttpEntity<?>>> attachmentsResponse(
Interaction interaction, InteractionResponse interactionResponse) {
return raidInfographicsService.retrieveEncounterImages(interaction)
.map(assets -> HttpResponseUtils.filesResponse(interactionResponse, assets));
}

}
Loading

0 comments on commit ff8ccde

Please sign in to comment.