-
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.
Merge pull request #13 from Killjoyer/refactor
Refactor
Showing
26 changed files
with
479 additions
and
171 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
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
3 changes: 1 addition & 2 deletions
3
src/main/java/org/tbplusc/app/discordinteraction/ChatState.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,7 +1,6 @@ | ||
package org.tbplusc.app.discordinteraction; | ||
|
||
import discord4j.core.object.entity.Message; | ||
|
||
public interface ChatState { | ||
ChatState handleMessage(Message message); | ||
ChatState handleMessage(WrappedMessage message); | ||
} |
50 changes: 27 additions & 23 deletions
50
src/main/java/org/tbplusc/app/discordinteraction/DefaultChatState.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
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
29 changes: 12 additions & 17 deletions
29
src/main/java/org/tbplusc/app/discordinteraction/MessageHandler.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
36 changes: 36 additions & 0 deletions
36
src/main/java/org/tbplusc/app/discordinteraction/WrappedDiscordMessage.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,36 @@ | ||
package org.tbplusc.app.discordinteraction; | ||
|
||
import discord4j.core.object.entity.Message; | ||
import static org.tbplusc.app.discordinteraction.DiscordUtil.getChannelForMessage; | ||
|
||
public class WrappedDiscordMessage implements WrappedMessage { | ||
private final Message message; | ||
|
||
public WrappedDiscordMessage(Message message) { | ||
this.message = message; | ||
} | ||
|
||
@Override | ||
public String getContextKey() { | ||
final var authorOptional = message.getAuthor(); | ||
if (authorOptional.isEmpty()) { | ||
throw new NullPointerException("Message had no author"); | ||
} | ||
final var authorId = authorOptional.get().getId(); | ||
final var channel = message.getChannel().block(); | ||
if (channel == null) { | ||
throw new NullPointerException("No channel for the message"); | ||
} | ||
final var channelId = channel.getId(); | ||
return authorId.asString() + channelId.asString(); | ||
} | ||
|
||
@Override public String getContent() { | ||
return message.getContent(); | ||
} | ||
|
||
@Override public void respond(String text) { | ||
var channel = getChannelForMessage(message); | ||
channel.createMessage(text).block(); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/org/tbplusc/app/discordinteraction/WrappedMessage.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,9 @@ | ||
package org.tbplusc.app.discordinteraction; | ||
|
||
public interface WrappedMessage { | ||
String getContextKey(); | ||
|
||
String getContent(); | ||
|
||
void respond(String text); | ||
} |
Oops, something went wrong.