Skip to content

Commit

Permalink
This new branch will be the one with the actual changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Villavicencio authored and Daniel Villavicencio committed Feb 15, 2024
1 parent 9f312c2 commit 5cfb937
Show file tree
Hide file tree
Showing 45 changed files with 640 additions and 639 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-r2dbc'
implementation 'org.springframework.session:spring-session-data-redis'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.springframework.boot:spring-boot-starter-web'
// implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-devtools'
implementation "net.i2p.crypto:eddsa:${i2pCryptoVersion}"
implementation "commons-io:commons-io:${IOCommonsVersion}"
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/com/danielvm/destiny2bot/Destiny2botApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

import com.danielvm.destiny2bot.exception.ExternalServiceException;
import com.danielvm.destiny2bot.exception.InternalServerException;
import com.danielvm.destiny2bot.filter.CachingRequestBodyFilter;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import java.nio.charset.StandardCharsets;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
Expand Down Expand Up @@ -44,14 +42,6 @@ CacheManager inMemoryCacheManager() {
return new ConcurrentMapCacheManager();
}

@Bean
public FilterRegistrationBean<CachingRequestBodyFilter> signatureValidationFilterBean() {
FilterRegistrationBean<CachingRequestBodyFilter> registrationBean = new FilterRegistrationBean<>();
registrationBean.setFilter(new CachingRequestBodyFilter());
registrationBean.addUrlPatterns("/interactions");
return registrationBean;
}

/**
* Prepares a WebClient.Builder bean that has standard status handlers
*
Expand Down

This file was deleted.

10 changes: 8 additions & 2 deletions src/main/java/com/danielvm/destiny2bot/client/BungieClient.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.danielvm.destiny2bot.client;

import com.danielvm.destiny2bot.dto.destiny.ActivitiesResponse;
import com.danielvm.destiny2bot.dto.destiny.BungieResponse;
import com.danielvm.destiny2bot.dto.destiny.MemberGroupResponse;
import com.danielvm.destiny2bot.dto.destiny.PostGameCarnageReport;
import com.danielvm.destiny2bot.dto.destiny.SearchResult;
import com.danielvm.destiny2bot.dto.destiny.UserGlobalSearchBody;
import com.danielvm.destiny2bot.dto.destiny.characters.CharactersResponse;
Expand Down Expand Up @@ -90,8 +92,12 @@ Mono<BungieResponse<MemberGroupResponse>> getGroupsForMember(
);

@GetExchange("/Destiny2/{membershipType}/Account/{destinyMembershipId}/Character/{characterId}/Stats/Activities/")
Mono<> getActivityHistory(@PathVariable Integer membershipType,
@PathVariable Long destinyMembershipId, @PathVariable Long characterId,
Mono<BungieResponse<ActivitiesResponse>> getActivityHistory(@PathVariable Integer membershipType,
@PathVariable String destinyMembershipId, @PathVariable String characterId,
@RequestParam Integer count, @RequestParam Integer mode, @RequestParam Integer page);

@GetExchange("/Destiny2/Stats/PostGameCarnageReport/{activityId}/")
Mono<BungieResponse<PostGameCarnageReport>> getPostGameCarnageReport(
@PathVariable Long activityId
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,32 @@
import com.danielvm.destiny2bot.dto.destiny.BungieResponse;
import com.danielvm.destiny2bot.dto.destiny.manifest.ResponseFields;
import com.danielvm.destiny2bot.enums.ManifestEntity;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;

@Service
@RequiredArgsConstructor
@Slf4j
public class BungieClientWrapper {

private final BungieClient bungieClient;
private final BungieClient defaultBungieClient;

public BungieClientWrapper(BungieClient defaultBungieClient) {
this.defaultBungieClient = defaultBungieClient;
}

/**
* Wraps the client call to the Manifest with a Cacheable method
*
* @param entityType The entity type (see
* {@link ManifestEntity})
* @param entityType The entity type (see {@link ManifestEntity})
* @param hashIdentifier The hash identifier
* @return {@link BungieResponse} of {@link ResponseFields}
*/
@Cacheable(cacheNames = "entity", cacheManager = "inMemoryCacheManager")
public Mono<BungieResponse<ResponseFields>> getManifestEntityRx(
ManifestEntity entityType, String hashIdentifier) {
return bungieClient.getManifestEntityRx(entityType.getId(), hashIdentifier).cache();
return defaultBungieClient.getManifestEntityRx(entityType.getId(), hashIdentifier).cache();
}

}
11 changes: 10 additions & 1 deletion src/main/java/com/danielvm/destiny2bot/client/DiscordClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

import com.danielvm.destiny2bot.dto.discord.DiscordUserResponse;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.http.MediaType;
import org.springframework.util.MultiValueMap;
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 @@ -21,4 +25,9 @@ public interface DiscordClient {
@GetExchange("/users/@me")
Mono<DiscordUserResponse> getUser(
@RequestHeader(HttpHeaders.AUTHORIZATION) String bearerToken);

@PatchExchange(value = "/webhooks/1109351854934065213/{interactionToken}/messages/@original", contentType = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
Mono<Void> editOriginalInteraction(
@PathVariable String interactionToken,
@RequestBody MultiValueMap<String, String> interactionResponse);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.support.WebClientAdapter;
import org.springframework.web.service.invoker.HttpServiceProxyFactory;
Expand Down Expand Up @@ -39,6 +41,11 @@ public class BungieConfiguration implements OAuth2Configuration {
*/
private String baseUrl;

/**
* Base URL for stats endpoint
*/
private String statsBaseUrl;

/**
* Url for Bungie Token endpoint
*/
Expand All @@ -54,11 +61,27 @@ public class BungieConfiguration implements OAuth2Configuration {
*/
private String callbackUrl;

@Bean
@Bean("defaultBungieClient")
public BungieClient bungieCharacterClient(WebClient.Builder builder) {
var webClient = builder
.baseUrl(this.baseUrl)
.defaultHeader(API_KEY_HEADER_NAME, this.key)
.codecs(clientCodecConfigurer -> clientCodecConfigurer.defaultCodecs()
.maxInMemorySize(1024 * 1024))
.build();
return HttpServiceProxyFactory.builder()
.exchangeAdapter(WebClientAdapter.create(webClient))
.build()
.createClient(BungieClient.class);
}

@Bean(name = "pgcrBungieClient")
public BungieClient pgcrBungieClient(WebClient.Builder builder) {
var webClient = builder
.baseUrl(this.statsBaseUrl)
.defaultHeader(API_KEY_HEADER_NAME, this.key)
.defaultHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.build();
return HttpServiceProxyFactory.builder()
.exchangeAdapter(WebClientAdapter.create(webClient))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static com.danielvm.destiny2bot.util.HttpUtil.prepareMultipartPayload;

import com.danielvm.destiny2bot.annotation.ValidSignature;
import com.danielvm.destiny2bot.dto.discord.Interaction;
import com.danielvm.destiny2bot.dto.discord.InteractionResponse;
import com.danielvm.destiny2bot.service.ImageAssetService;
Expand All @@ -19,7 +18,6 @@
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.util.ContentCachingRequestWrapper;
import reactor.core.publisher.Mono;

@Slf4j
Expand Down Expand Up @@ -47,9 +45,7 @@ public InteractionsController(
* corresponding bytes, else an {@link InteractionResponse}
*/
@PostMapping("/interactions")
public Mono<ResponseEntity<?>> interactions(
@RequestBody Interaction interaction,
@ValidSignature ContentCachingRequestWrapper request) {
public Mono<ResponseEntity<?>> interactions(@RequestBody Interaction interaction) {
return interactionService.handleInteraction(interaction)
.flatMap(response -> {
boolean containsAttachments = response.getType() != 1 && CollectionUtils.isNotEmpty(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.danielvm.destiny2bot.controller;

import com.danielvm.destiny2bot.dto.destiny.CharacterRaidStatistics;
import com.danielvm.destiny2bot.dto.discord.Interaction;
import com.danielvm.destiny2bot.dto.discord.InteractionData;
import com.danielvm.destiny2bot.dto.discord.Option;
import com.danielvm.destiny2bot.service.RaidStatsService;
import java.util.List;
import java.util.Map;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.service.annotation.GetExchange;
import reactor.core.publisher.Mono;

@RestController
public class TestController {

private final RaidStatsService raidStatsService;

public TestController(RaidStatsService raidStatsService) {
this.raidStatsService = raidStatsService;
}

@GetExchange("/stats")
public Mono<Map<String, CharacterRaidStatistics>> test() {
return raidStatsService.retrieveRaidStatsForUser(Interaction.builder()
.data(InteractionData.builder()
.options(List.of(new Option("username", 1, "4611686018468622561", null)))
.build())
.build());
}
}
27 changes: 27 additions & 0 deletions src/main/java/com/danielvm/destiny2bot/dto/RaidEntry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.danielvm.destiny2bot.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class RaidEntry {

private String raidName;

private Long instanceId;

private Integer totalDeaths;

private Integer totalKills;

private Double kda;

private Integer duration;

private Boolean isCompleted;

private Boolean isFromBeginning;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.danielvm.destiny2bot.dto.destiny;

import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ActivitiesResponse {

private List<Activity> activities;
}
19 changes: 19 additions & 0 deletions src/main/java/com/danielvm/destiny2bot/dto/destiny/Activity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.danielvm.destiny2bot.dto.destiny;

import java.time.ZonedDateTime;
import java.util.Map;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Activity {

private ZonedDateTime period;

private ActivityDetails activityDetails;

private Map<String, ValueEntry> values;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.danielvm.destiny2bot.dto.destiny;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ActivityDetails {

private Long directorActivityHash;

private Long instanceId;

private Integer mode;
}
Loading

0 comments on commit 5cfb937

Please sign in to comment.