Skip to content

Commit

Permalink
So much stuff worked on, for this PR
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Villavicencio authored and Daniel Villavicencio committed Mar 7, 2024
1 parent dad2ad7 commit 59cc1ae
Show file tree
Hide file tree
Showing 48 changed files with 367 additions and 715 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import java.nio.charset.StandardCharsets;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.CacheManager;
Expand All @@ -24,6 +25,7 @@
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Mono;

@Slf4j
@EnableCaching
@SpringBootApplication
@EnableAspectJAutoProxy
Expand All @@ -38,7 +40,7 @@ RouterFunction<ServerResponse> interactionFilterFunction(
InteractionHandler interactionHandler,
SignatureFilterFunction signatureFilterFunction) {
return RouterFunctions.route()
.POST("/interactions", interactionHandler::handleInteraction)
.POST("/interactions", interactionHandler::handle)
.filter(signatureFilterFunction)
.build();
}
Expand Down
26 changes: 7 additions & 19 deletions src/main/java/com/danielvm/destiny2bot/client/BungieClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@
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.MembershipResponse;
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;
import com.danielvm.destiny2bot.dto.destiny.manifest.ResponseFields;
import com.danielvm.destiny2bot.dto.destiny.membership.MembershipResponse;
import com.danielvm.destiny2bot.dto.destiny.milestone.MilestoneEntry;
import com.danielvm.destiny2bot.enums.ManifestEntity;
import java.util.Map;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
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.bind.annotation.RequestParam;
import org.springframework.web.service.annotation.GetExchange;
import org.springframework.web.service.annotation.PostExchange;
Expand All @@ -28,24 +25,15 @@
public interface BungieClient {

/**
* Gets the membership info for the current user
* Gets the membership info for a user using their membershipId and their membershipType
*
* @param bearerToken The user's bearer token
* @param membershipType The membership type of the user
* @param membershipId The membershipId of the user
* @return {@link MembershipResponse}
*/
@GetExchange("/User/GetMembershipsForCurrentUser/")
ResponseEntity<MembershipResponse> getMembershipForCurrentUser(
@RequestHeader(name = HttpHeaders.AUTHORIZATION) String bearerToken);

/**
* Gets the membership info for the current user in a reactive way
*
* @param bearerToken The user's bearer token
* @return {@link MembershipResponse}
*/
@GetExchange("/User/GetMembershipsForCurrentUser/")
Mono<MembershipResponse> getMembershipInfoForCurrentUser(
@RequestHeader(name = HttpHeaders.AUTHORIZATION) String bearerToken);
@GetExchange("/User/GetMembershipsById/{membershipId}/{membershipType}/")
Mono<BungieResponse<MembershipResponse>> getMembershipInfoById(
@PathVariable String membershipId, @PathVariable Integer membershipType);

/**
* Ges a manifest entity from the Manifest API asynchronously
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ public interface DiscordClient {
Mono<DiscordUserResponse> getUser(
@RequestHeader(HttpHeaders.AUTHORIZATION) String bearerToken);

/**
* Edit an interaction that was sent already
*
* @param applicationId The id of the application
* @param interactionToken The interaction token of the original interaction to edit
* @param data The data to send
*/
@PatchExchange(value = "/webhooks/{applicationId}/{interactionToken}/messages/@original", contentType = MediaType.APPLICATION_JSON_VALUE)
Mono<Void> editOriginalInteraction(
@PathVariable Long applicationId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.support.WebClientAdapter;
import org.springframework.web.service.invoker.HttpServiceProxyFactory;
import reactor.netty.http.client.HttpClient;

@Data
@Configuration
Expand Down Expand Up @@ -69,8 +71,11 @@ public class BungieConfiguration {
*/
@Bean("defaultBungieClient")
public BungieClient bungieCharacterClient(WebClient.Builder builder) {
HttpClient httpClient = HttpClient.create()
.keepAlive(false);
var webClient = builder
.baseUrl(this.baseUrl)
.clientConnector(new ReactorClientHttpConnector(httpClient))
.defaultHeader(API_KEY_HEADER_NAME, this.key)
.codecs(clientCodecConfigurer -> clientCodecConfigurer.defaultCodecs()
.maxInMemorySize(1024 * 1024))
Expand All @@ -89,8 +94,12 @@ public BungieClient bungieCharacterClient(WebClient.Builder builder) {
*/
@Bean(name = "pgcrBungieClient")
public BungieClient pgcrBungieClient(WebClient.Builder builder) {
// Don't keep alive connections with Bungie.net
HttpClient httpClient = HttpClient.create()
.keepAlive(false);
var webClient = builder
.baseUrl(this.statsBaseUrl)
.clientConnector(new ReactorClientHttpConnector(httpClient))
.defaultHeader(API_KEY_HEADER_NAME, this.key)
.defaultHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.danielvm.destiny2bot.dto.destiny;

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

@Data
@AllArgsConstructor
@NoArgsConstructor
public class BungieNetMembership {

private String membershipId;

private String uniqueName;

private String displayName;

private Boolean isDeleted;

private String locale;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.danielvm.destiny2bot.dto.destiny;

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

@Data
@AllArgsConstructor
@NoArgsConstructor
public class BungieUserResponse {

private String membershipId;

private String uniqueName;

private Boolean isDeleted;

private String locale;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.danielvm.destiny2bot.dto.destiny;

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

@Data
@AllArgsConstructor
@NoArgsConstructor
public final class DestinyMembershipData {

private Integer membershipType;

private String membershipId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.danielvm.destiny2bot.dto.destiny;

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

@Data
@AllArgsConstructor
@NoArgsConstructor
public final class MembershipResponse {

private List<DestinyMembershipData> destinyMemberships;

private String primaryMembershipId;

private BungieNetMembership bungieNetUser;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.danielvm.destiny2bot.dto.destiny;

import com.danielvm.destiny2bot.dto.destiny.membership.DestinyMembershipData;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Data;
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

22 changes: 22 additions & 0 deletions src/main/java/com/danielvm/destiny2bot/dto/discord/Component.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,28 @@ public class Component {
*/
private String url;

/**
* Emoji for this component
*/
private Emoji emoji;

/**
* Placeholder value for a select menu before choosing
*/
private String placeholder;

/**
* Minimum amount of select values in a select menu
*/
@JsonProperty("min_values")
private Integer minValues;

/**
* Minimum amount of select values in a select menu
*/
@JsonProperty("max_values")
private Integer maxValues;

/**
* Array of options for select menu
*/
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/danielvm/destiny2bot/dto/discord/Emoji.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ public class Emoji {
* Name of the emoji
*/
private String name;

/**
* Whether this emoji is animated or not
*/
private Boolean animated;
}
Loading

0 comments on commit 59cc1ae

Please sign in to comment.