-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Daniel Villavicencio
authored and
Daniel Villavicencio
committed
Jul 21, 2024
1 parent
9c175b7
commit 6dc4437
Showing
31 changed files
with
599 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 0 additions & 24 deletions
24
src/main/java/com/deahtstroke/rivenbot/dto/destiny/BungieErrorDto.java
This file was deleted.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
src/main/java/com/deahtstroke/rivenbot/dto/destiny/BungieUserResponse.java
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
src/main/java/com/deahtstroke/rivenbot/dto/discord/DiscordUserResponse.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 0 additions & 21 deletions
21
src/main/java/com/deahtstroke/rivenbot/dto/discord/Message.java
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
src/main/java/com/deahtstroke/rivenbot/dto/discord/ResolvedData.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/com/deahtstroke/rivenbot/enums/MessageComponentId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.deahtstroke.rivenbot.enums; | ||
|
||
import java.util.NoSuchElementException; | ||
import java.util.Objects; | ||
import java.util.stream.Stream; | ||
import lombok.Getter; | ||
|
||
public enum MessageComponentId { | ||
RAID_STATS_COMPREHENSION("raid_stats_comprehension"), | ||
MESSAGE_COMPONENT_TEST("message_component_test"); | ||
|
||
@Getter | ||
private final String id; | ||
|
||
MessageComponentId(String componentId) { | ||
this.id = componentId; | ||
} | ||
|
||
public static MessageComponentId findById(String id) { | ||
return Stream.of(MessageComponentId.values()) | ||
.filter(mci -> Objects.equals(mci.id, id)) | ||
.findFirst() | ||
.orElseThrow(() -> new NoSuchElementException( | ||
"Was not able to find a message component ID for id [%s]".formatted(id))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/main/java/com/deahtstroke/rivenbot/exception/NoRaidDataFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.deahtstroke.rivenbot.exception; | ||
|
||
public class NoRaidDataFoundException extends BaseDiscordChatException { | ||
|
||
public NoRaidDataFoundException(String message, String chatErrorMessage) { | ||
super(message, chatErrorMessage); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/deahtstroke/rivenbot/exception/NoSuchHandlerException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.deahtstroke.rivenbot.exception; | ||
|
||
public class NoSuchHandlerException extends RuntimeException { | ||
|
||
public NoSuchHandlerException(String errorMessage) { | ||
super(errorMessage); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 13 additions & 6 deletions
19
src/main/java/com/deahtstroke/rivenbot/factory/MessageComponentFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,31 @@ | ||
package com.deahtstroke.rivenbot.factory; | ||
|
||
import com.deahtstroke.rivenbot.enums.MessageComponentId; | ||
import com.deahtstroke.rivenbot.exception.NoSuchHandlerException; | ||
import com.deahtstroke.rivenbot.handler.MessageComponentSource; | ||
import com.deahtstroke.rivenbot.handler.RaidStatsButtonHandler; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class MessageComponentFactory implements MessageComponentHandler<MessageComponentSource> { | ||
|
||
private static final String STATS_COMPREHENSION_ID = "raid_stats_comprehension"; | ||
|
||
private final Map<String, MessageComponentSource> componentFactory; | ||
private final Map<MessageComponentId, MessageComponentSource> componentFactory; | ||
|
||
public MessageComponentFactory( | ||
RaidStatsButtonHandler raidStatsButtonHandler) { | ||
componentFactory = Map.of(STATS_COMPREHENSION_ID, raidStatsButtonHandler); | ||
componentFactory = Map.of(MessageComponentId.RAID_STATS_COMPREHENSION, raidStatsButtonHandler); | ||
} | ||
|
||
@Override | ||
public MessageComponentSource getHandler(String componentId) { | ||
return componentFactory.get(componentId); | ||
public MessageComponentSource getHandler(MessageComponentId componentId) { | ||
MessageComponentSource handler = componentFactory.get(componentId); | ||
if (Objects.isNull(handler)) { | ||
throw new NoSuchHandlerException( | ||
"No handler found for component [%s] with ID [%s]".formatted(componentId, | ||
componentId.getId())); | ||
} | ||
return handler; | ||
} | ||
} |
8 changes: 5 additions & 3 deletions
8
src/main/java/com/deahtstroke/rivenbot/factory/MessageComponentHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
package com.deahtstroke.rivenbot.factory; | ||
|
||
import com.deahtstroke.rivenbot.enums.MessageComponentId; | ||
|
||
public interface MessageComponentHandler<T> { | ||
|
||
/** | ||
* Return a message component of type T based on a componentId | ||
* Return a message component of type T based on a Message Component ID | ||
* | ||
* @param componentId The componentId of the button | ||
* @param componentId The MessageComponentId of the button | ||
* @return Type of the button handler | ||
*/ | ||
T getHandler(String componentId); | ||
T getHandler(MessageComponentId componentId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.