forked from TheCurle/Camelot
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve feedback when script throws or doesn't send a reply
- Loading branch information
1 parent
06a080d
commit f9d14d9
Showing
8 changed files
with
95 additions
and
15 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
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
45 changes: 45 additions & 0 deletions
45
src/main/java/net/neoforged/camelot/script/ScriptReplier.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,45 @@ | ||
package net.neoforged.camelot.script; | ||
|
||
import net.dv8tion.jda.api.requests.RestAction; | ||
import net.dv8tion.jda.api.utils.messages.MessageCreateData; | ||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import java.util.function.Consumer; | ||
|
||
public abstract class ScriptReplier implements Consumer<MessageCreateData> { | ||
private final AtomicBoolean wasReplied = new AtomicBoolean(); | ||
|
||
/** | ||
* Reply to the user and {@link RestAction#complete() immediately complete} | ||
* the action. | ||
*/ | ||
@Override | ||
public void accept(MessageCreateData createData) { | ||
send(createData).complete(); | ||
} | ||
|
||
/** | ||
* Reply to the user. | ||
*/ | ||
public RestAction<?> send(MessageCreateData createData) { | ||
wasReplied.set(true); | ||
return doSend(createData); | ||
} | ||
|
||
/** | ||
* {@return whether the script replied to the user} | ||
*/ | ||
public boolean wasReplied() { | ||
return wasReplied.get(); | ||
} | ||
|
||
/** | ||
* Reply to the user. | ||
* | ||
* @deprecated do not use this directly. This is only meant to be overridden. Use {@link #send(MessageCreateData)} instead. | ||
*/ | ||
@Deprecated | ||
@ApiStatus.OverrideOnly | ||
protected abstract RestAction<?> doSend(MessageCreateData createData); | ||
} |
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