-
-
Notifications
You must be signed in to change notification settings - Fork 104
Feature/jshell #870
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Feature/jshell #870
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f0a93b5
Feature/jshell from fork (#869)
Alathreon 78828b8
Added startupt scripts for jshell
Alathreon 7fa5e1e
Formating jshell classes
Alathreon 900780c
JShell javadoc and many minor code improvements
Alathreon ff0288d
JShell more minor code improvements
Alathreon 01054fc
Other minor code changes
Alathreon 7edd53c
JShell now allows wrong uri and dead server, will give correct respon…
Alathreon 2e36e55
Forgot one exception javadoc for jshell feature
Alathreon 09a1b69
JShell refactored snippets send conditions
Alathreon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
39 changes: 39 additions & 0 deletions
39
application/src/main/java/org/togetherjava/tjbot/config/JShellConfig.java
This file contains hidden or 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,39 @@ | ||
| package org.togetherjava.tjbot.config; | ||
|
|
||
|
|
||
| import org.togetherjava.tjbot.features.utils.RateLimiter; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * JShell config. | ||
| * | ||
| * @param baseUrl the base url of the JShell REST API | ||
| * @param rateLimitWindowSeconds the number of seconds of the {@link RateLimiter rate limiter} for | ||
| * jshell commands and code actions | ||
| * @param rateLimitRequestsInWindow the number of requests of the {@link RateLimiter rate limiter} | ||
| * for jshell commands and code actions | ||
| */ | ||
| public record JShellConfig(String baseUrl, int rateLimitWindowSeconds, | ||
| int rateLimitRequestsInWindow) { | ||
| /** | ||
| * Creates a JShell config. | ||
| * | ||
| * @param baseUrl the base url of the JShell REST API, must be not null | ||
| * @param rateLimitWindowSeconds the number of seconds of the {@link RateLimiter rate limiter} | ||
| * for jshell commands and code actions, must be higher than 0 | ||
| * @param rateLimitRequestsInWindow the number of requests of the {@link RateLimiter rate | ||
| * limiter} for jshell commands and code actions, must be higher than 0 | ||
| */ | ||
| public JShellConfig { | ||
| Objects.requireNonNull(baseUrl); | ||
| if (rateLimitWindowSeconds < 0) { | ||
| throw new IllegalArgumentException( | ||
| "Illegal rateLimitWindowSeconds : " + rateLimitWindowSeconds); | ||
| } | ||
| if (rateLimitRequestsInWindow < 0) { | ||
| throw new IllegalArgumentException( | ||
| "Illegal rateLimitRequestsInWindow : " + rateLimitRequestsInWindow); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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
application/src/main/java/org/togetherjava/tjbot/features/code/EvalCodeCommand.java
This file contains hidden or 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 org.togetherjava.tjbot.features.code; | ||
|
|
||
| import net.dv8tion.jda.api.EmbedBuilder; | ||
| import net.dv8tion.jda.api.entities.MessageEmbed; | ||
|
|
||
| import org.togetherjava.tjbot.features.jshell.JShellEval; | ||
| import org.togetherjava.tjbot.features.utils.CodeFence; | ||
| import org.togetherjava.tjbot.features.utils.Colors; | ||
| import org.togetherjava.tjbot.features.utils.ConnectionFailedException; | ||
| import org.togetherjava.tjbot.features.utils.RequestFailedException; | ||
|
|
||
| /** | ||
| * Evaluates the given code with jshell. | ||
| * <p> | ||
| * It will not work of the code isn't valid java or jshell compatible code. | ||
| */ | ||
| final class EvalCodeCommand implements CodeAction { | ||
| private final JShellEval jshellEval; | ||
|
|
||
| EvalCodeCommand(JShellEval jshellEval) { | ||
| this.jshellEval = jshellEval; | ||
| } | ||
|
|
||
| @Override | ||
| public String getLabel() { | ||
| return "Run code"; | ||
| } | ||
|
|
||
| @Override | ||
| public MessageEmbed apply(CodeFence codeFence) { | ||
| if (codeFence.code().isEmpty()) { | ||
| return new EmbedBuilder().setColor(Colors.ERROR_COLOR) | ||
| .setDescription("There is nothing to evaluate") | ||
| .build(); | ||
| } | ||
| try { | ||
| return jshellEval.evaluateAndRespond(null, codeFence.code(), false, false); | ||
| } catch (RequestFailedException | ConnectionFailedException e) { | ||
| return new EmbedBuilder().setColor(Colors.ERROR_COLOR) | ||
| .setDescription("Request failed: " + e.getMessage()) | ||
| .build(); | ||
| } | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.