Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/experimental-raid-stats-no-authe…
Browse files Browse the repository at this point in the history
…ntication' into fix-signature-filter

# Conflicts:
#	src/main/java/com/danielvm/destiny2bot/filter/RequestBodyCacheFilter.java
#	src/test/java/com/danielvm/destiny2bot/factory/ApplicationCommandFactoryTest.java
#	src/test/java/com/danielvm/destiny2bot/integration/BaseIntegrationTest.java
  • Loading branch information
JVilla1997 committed Feb 16, 2024
2 parents 22a361c + cf9438a commit 45cbb30
Show file tree
Hide file tree
Showing 40 changed files with 570 additions and 578 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +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.util.MultiValueMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
Expand All @@ -26,8 +26,9 @@ public interface DiscordClient {
Mono<DiscordUserResponse> getUser(
@RequestHeader(HttpHeaders.AUTHORIZATION) String bearerToken);

@PatchExchange(value = "/webhooks/1109351854934065213/{interactionToken}/messages/@original", contentType = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
@PatchExchange(value = "/webhooks/{applicationId}/{interactionToken}/messages/@original", contentType = MediaType.APPLICATION_JSON_VALUE)
Mono<Void> editOriginalInteraction(
@PathVariable Long applicationId,
@PathVariable String interactionToken,
@RequestBody MultiValueMap<String, String> interactionResponse);
@RequestBody InteractionResponseData data);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.client.reactive.ClientHttpConnector;
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;
Expand Down Expand Up @@ -82,6 +84,8 @@ public BungieClient pgcrBungieClient(WebClient.Builder builder) {
.defaultHeader(API_KEY_HEADER_NAME, this.key)
.defaultHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.codecs(clientCodecConfigurer -> clientCodecConfigurer.defaultCodecs()
.maxInMemorySize(1024 * 1024 * 15))
.build();
return HttpServiceProxyFactory.builder()
.exchangeAdapter(WebClientAdapter.create(webClient))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public class DiscordConfiguration implements OAuth2Configuration {
*/
private List<String> scopes;

/**
* The applicationId for the discord bot
*/
private Long applicationId;

@Bean
public DiscordClient discordClient(WebClient.Builder defaultBuilder) {
var webClient = defaultBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.danielvm.destiny2bot.dto.discord.InteractionResponse;
import com.danielvm.destiny2bot.service.ImageAssetService;
import com.danielvm.destiny2bot.service.InteractionService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
Expand All @@ -27,12 +29,14 @@ public class InteractionsController {

private final InteractionService interactionService;
private final ImageAssetService imageAssetService;
private final ObjectMapper objectMapper;

public InteractionsController(
InteractionService interactionService,
ImageAssetService imageAssetService) {
ImageAssetService imageAssetService, ObjectMapper objectMapper) {
this.interactionService = interactionService;
this.imageAssetService = imageAssetService;
this.objectMapper = objectMapper;
}

/**
Expand All @@ -54,7 +58,13 @@ public Mono<ResponseEntity<?>> interactions(@RequestBody Interaction interaction
Mono.just(ResponseEntity.ok(response));
})
.doOnSubscribe(i -> log.info("Received interaction: [{}]", interaction))
.doOnSuccess(i -> log.info("Completed interaction: [{}]", i));
.doOnSuccess(i -> {
try {
log.info("Completed interaction: [{}]", objectMapper.writeValueAsString(i));
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
});
}

private Mono<ResponseEntity<MultiValueMap<String, HttpEntity<?>>>> multipartFormResponse(
Expand Down

This file was deleted.

This file was deleted.

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

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

@Data
@AllArgsConstructor
@NoArgsConstructor
public class RaidStatistics {

/**
* The name of the raid
*/
private String raidName;

/**
* Total amount of kills done for a raid
*/
private Integer totalKills;

/**
* Total amount of deaths done in a raid
*/
private Integer totalDeaths;

/**
* The fastest time a player has done in a raid
*/
private Integer fastestTime;

/**
* The average time a player finishes the raid
*/
private Integer averageTime;

/**
* The number of completed raids that user has for a specific raid
*/
private Integer partialClears;

/**
* The total amount of times a player has played this raid
*/
private Integer totalClears;

/**
* The total amount of full clears for a raid
*/
private Integer fullClears;

public RaidStatistics(String raidName) {
this.raidName = raidName;
this.totalKills = 0;
this.totalDeaths = 0;
this.fastestTime = Integer.MAX_VALUE;
this.averageTime = 0;
this.partialClears = 0;
this.totalClears = 0;
this.fullClears = 0;
}

public String toString() {
StringBuilder fastestRaidDuration = new StringBuilder();
int hours = (fastestTime / 3600) % 24;
int minutes = (fastestTime / 60) % 60;
if (hours > 0) {
fastestRaidDuration.append(hours).append("hr(s)").append(" ");
}
if (minutes > 0) {
fastestRaidDuration.append(minutes).append("mins");
}
StringBuilder raidTemplate = new StringBuilder();
raidTemplate.append(":crossed_swords: ").append("Kills: ").append(this.totalKills)
.append("\n");
raidTemplate.append(":skull_crossbones: ").append("Deaths: ").append(this.totalDeaths)
.append("\n");
if (!fastestRaidDuration.isEmpty()) {
raidTemplate.append(":first_place: ").append("Fastest: ").append(fastestRaidDuration)
.append("\n");
}
raidTemplate.append(":bar_chart: ").append("Total Clears: ").append(this.totalClears)
.append("\n");
raidTemplate.append(":trophy: ").append("Full Clears: ").append(this.fullClears)
.append("\n");
return raidTemplate.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class Embedded {

private Object video;

private Object provider;
private EmbeddedProvider provider;

private EmbeddedAuthor author;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.danielvm.destiny2bot.dto.discord;

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

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class EmbeddedProvider {

private String name;

private String url;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ public class InvalidSignatureException extends BaseException {
public InvalidSignatureException(String message, Throwable throwable) {
super(message, HttpStatus.BAD_REQUEST, throwable);
}

public InvalidSignatureException(String message) {
super(message, HttpStatus.BAD_REQUEST);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import com.danielvm.destiny2bot.enums.SlashCommand;
import com.danielvm.destiny2bot.exception.ResourceNotFoundException;
import com.danielvm.destiny2bot.factory.creator.ApplicationCommandSource;
import com.danielvm.destiny2bot.factory.creator.AuthorizeMessageCreator;
import com.danielvm.destiny2bot.factory.creator.ExperimentalRaidStatsCreator;
import com.danielvm.destiny2bot.factory.creator.RaidMapMessageCreator;
import com.danielvm.destiny2bot.factory.creator.WeeklyDungeonMessageCreator;
import com.danielvm.destiny2bot.factory.creator.WeeklyRaidMessageCreator;
import com.danielvm.destiny2bot.factory.handler.ApplicationCommandSource;
import com.danielvm.destiny2bot.factory.handler.AuthorizeHandler;
import com.danielvm.destiny2bot.factory.handler.RaidStatsHandler;
import com.danielvm.destiny2bot.factory.handler.RaidMapHandler;
import com.danielvm.destiny2bot.factory.handler.WeeklyDungeonHandler;
import com.danielvm.destiny2bot.factory.handler.WeeklyRaidHandler;
import java.util.Map;
import java.util.Objects;
import org.springframework.stereotype.Component;
Expand All @@ -17,22 +17,22 @@
* their corresponding message creation services.
*/
@Component
public class ApplicationCommandFactory implements InteractionFactory<ApplicationCommandSource> {
public class ApplicationCommandFactory implements SlashCommandHandler<ApplicationCommandSource> {

private final Map<SlashCommand, ApplicationCommandSource> messageFactory;

public ApplicationCommandFactory(
RaidMapMessageCreator raidMapMessageCreator,
WeeklyRaidMessageCreator weeklyRaidMessageCreator,
WeeklyDungeonMessageCreator weeklyDungeonMessageCreator,
AuthorizeMessageCreator authorizeMessageCreator,
ExperimentalRaidStatsCreator experimentalRaidStatsCreator) {
RaidMapHandler raidMapHandler,
WeeklyRaidHandler weeklyRaidHandler,
WeeklyDungeonHandler weeklyDungeonHandler,
AuthorizeHandler authorizeMessageHandler,
RaidStatsHandler raidStatsHandler) {
this.messageFactory = Map.of(
SlashCommand.WEEKLY_RAID, weeklyRaidMessageCreator,
SlashCommand.WEEKLY_DUNGEON, weeklyDungeonMessageCreator,
SlashCommand.AUTHORIZE, authorizeMessageCreator,
SlashCommand.RAID_MAP, raidMapMessageCreator,
SlashCommand.EXPERIMENTAL_RAID_STATS, experimentalRaidStatsCreator);
SlashCommand.WEEKLY_RAID, weeklyRaidHandler,
SlashCommand.WEEKLY_DUNGEON, weeklyDungeonHandler,
SlashCommand.AUTHORIZE, authorizeMessageHandler,
SlashCommand.RAID_MAP, raidMapHandler,
SlashCommand.EXPERIMENTAL_RAID_STATS, raidStatsHandler);
}

@Override
Expand Down
Loading

0 comments on commit 45cbb30

Please sign in to comment.