Skip to content

Commit

Permalink
final refacoring and revision
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Villavicencio authored and Daniel Villavicencio committed Apr 24, 2024
1 parent aa16bac commit fc56976
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 23 deletions.
14 changes: 0 additions & 14 deletions src/main/java/com/danielvm/destiny2bot/client/DiscordClient.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package com.danielvm.destiny2bot.client;

import com.danielvm.destiny2bot.dto.discord.DiscordUserResponse;
import com.danielvm.destiny2bot.dto.discord.InteractionResponseData;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.service.annotation.GetExchange;
import org.springframework.web.service.annotation.PatchExchange;
import reactor.core.publisher.Mono;

Expand All @@ -16,16 +12,6 @@
*/
public interface DiscordClient {

/**
* Gets the current Discord user details
*
* @param bearerToken The bearer token of the Discord user
* @return {@link DiscordUserResponse}
*/
@GetExchange("/users/@me")
Mono<DiscordUserResponse> getUser(
@RequestHeader(HttpHeaders.AUTHORIZATION) String bearerToken);

/**
* Edit an interaction that was sent already
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import lombok.Getter;

public enum SlashCommand {

TEST("test", false),

WEEKLY_DUNGEON("weekly_dungeon", false),
WEEKLY_RAID("weekly_raid", false),
RAID_STATS("raid_stats", true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ public Mono<ServerResponse> handle(ServerRequest request) {
ParameterizedTypeReference<MultiValueMap<String, HttpEntity<?>>> multiValueReference =
new ParameterizedTypeReference<>() {
};
return resolveResponse(interaction, interactionType)

Mono<InteractionResponse> interactionResponse = resolveResponse(interaction,
interactionType);
return interactionResponse
.flatMap(response -> {
boolean hasAttachments =
!Objects.equals(response.getType(), InteractionResponseType.PONG.getType())
Expand All @@ -71,10 +74,10 @@ public Mono<ServerResponse> handle(ServerRequest request) {
BodyInserters.fromValue(response));
})
.onErrorResume(BaseException.class,
ex -> {
ProblemDetail problemDetail = ProblemDetail.forStatus(ex.getStatus());
problemDetail.setDetail(ex.getMessage());
return ServerResponse.status(ex.getStatus())
error -> {
ProblemDetail problemDetail = ProblemDetail.forStatus(error.getStatus());
problemDetail.setDetail(error.getMessage());
return ServerResponse.status(error.getStatus())
.body(BodyInserters.fromValue(problemDetail));
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
@Slf4j
public class PostGameCarnageService {

private static final String PGCR_ENDPOINT_URL = "/Destiny2/Stats/PostGameCarnageReport/{activityId}/";
private static final RateLimiter PGCR_RATE_LIMITER = RateLimiter.of("pgcr-rate-limiter",
RateLimiterConfig.custom()
.limitForPeriod(23)
Expand Down Expand Up @@ -59,7 +60,7 @@ public Mono<PGCRDetails> retrievePGCR(Long activityInstanceId) {
WebClient webClient = builder.build();

Flux<DataBuffer> dataChunks = webClient.get()
.uri("/Destiny2/Stats/PostGameCarnageReport/{activityId}/", activityInstanceId)
.uri(PGCR_ENDPOINT_URL, activityInstanceId)
.exchangeToFlux(clientResponse -> clientResponse.body(BodyExtractors.toDataBuffers())
.concatMap(dataBuffer -> {
AtomicInteger currentSize = new AtomicInteger(0);
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/__files/bungie/milestone-response.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"response":{"3021174356":{"milestoneHash":3021174356,"startDate":null,"endDate":null,"activities":null},"644555645":{"milestoneHash":644555645,"startDate":null,"endDate":null,"activities":null},"3181387331":{"milestoneHash":3181387331,"startDate":1701795600.000000000,"endDate":1702400400.000000000,"activities":[{"activityHash":2122313384,"challengeObjectiveHashes":[]}]},"4253138191":{"milestoneHash":4253138191,"startDate":1701795600.000000000,"endDate":1702400400.000000000,"activities":null},"3603098564":{"milestoneHash":3603098564,"startDate":1701795600.000000000,"endDate":1702400400.000000000,"activities":null},"3802603984":{"milestoneHash":3802603984,"startDate":null,"endDate":null,"activities":null},"2709491520":{"milestoneHash":2709491520,"startDate":null,"endDate":null,"activities":null},"2594202463":{"milestoneHash":2594202463,"startDate":null,"endDate":null,"activities":null},"3899487295":{"milestoneHash":3899487295,"startDate":null,"endDate":null,"activities":null},"2712317338":{"milestoneHash":2712317338,"startDate":1713283200.000000000,"endDate":1713888000.000000000,"activities":[{"activityHash":1042180643,"challengeObjectiveHashes":["2398860795"]}]},"541780856":{"milestoneHash":541780856,"startDate":1701795600.000000000,"endDate":1702400400.000000000,"activities":[{"activityHash":910380154,"challengeObjectiveHashes":[]}]},"526718853":{"milestoneHash":526718853,"startDate":1713283200.000000000,"endDate":1713888000.000000000,"activities":[{"activityHash":1262462921,"challengeObjectiveHashes":["3211393925"]},{"activityHash":2296818662,"challengeObjectiveHashes":["3211393925"]}]}}}
{"response":{"3021174356":{"milestoneHash":3021174356,"startDate":null,"endDate":null,"activities":null},"644555645":{"milestoneHash":644555645,"startDate":null,"endDate":null,"activities":null},"3181387331":{"milestoneHash":3181387331,"startDate":1701795600.000000000,"endDate":1702400400.000000000,"activities":[{"activityHash":2122313384,"challengeObjectiveHashes":[]}]},"4253138191":{"milestoneHash":4253138191,"startDate":1701795600.000000000,"endDate":1702400400.000000000,"activities":null},"3603098564":{"milestoneHash":3603098564,"startDate":1701795600.000000000,"endDate":1702400400.000000000,"activities":null},"3802603984":{"milestoneHash":3802603984,"startDate":null,"endDate":null,"activities":null},"2709491520":{"milestoneHash":2709491520,"startDate":null,"endDate":null,"activities":null},"2594202463":{"milestoneHash":2594202463,"startDate":null,"endDate":null,"activities":null},"3899487295":{"milestoneHash":3899487295,"startDate":null,"endDate":null,"activities":null},"2712317338":{"milestoneHash":2712317338,"startDate":1713888000.000000000,"endDate":1714492800.000000000,"activities":[{"activityHash":1042180643,"challengeObjectiveHashes":["2398860795"]}]},"541780856":{"milestoneHash":541780856,"startDate":1701795600.000000000,"endDate":1702400400.000000000,"activities":[{"activityHash":910380154,"challengeObjectiveHashes":[]}]},"526718853":{"milestoneHash":526718853,"startDate":1713888000.000000000,"endDate":1714492800.000000000,"activities":[{"activityHash":1262462921,"challengeObjectiveHashes":["3211393925"]},{"activityHash":2296818662,"challengeObjectiveHashes":["3211393925"]}]}}}

0 comments on commit fc56976

Please sign in to comment.