Skip to content

Commit

Permalink
Merge pull request #15 from IntellectualSites/bugfix/setup-error-hand…
Browse files Browse the repository at this point in the history
…ling

Improve error handling of setup process
  • Loading branch information
TheMeinerLP authored Dec 11, 2023
2 parents cd7334e + 5fdd369 commit 511fae5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
1 change: 0 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ dependencies {
paperLibrary(libs.zstd)
paperLibrary(libs.redis)
implementation(libs.bstats)
paperLibrary(libs.kotlin.jackson)

compileOnly(libs.paper)
testImplementation(libs.kotlin.test)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,23 @@ import kotlin.time.Duration
*/
class DurationPrompt : StringPrompt() {
override fun getPromptText(context: ConversationContext): Component {
if (context.getSessionData("parse-error") != null) {
context.allSessionData.remove("parse-error")
return MiniMessage.miniMessage().deserialize("<red>Something went wrong while parsing the duration string, please follow the format!<br><green>How long do you want to keep the clipboards in the Redis memory? <gray>(example: <gold>6h = 6 hours, 2d = 2 days<gray>)")
}
return MiniMessage.miniMessage().deserialize("<green>How long do you want to keep the clipboards in the Redis memory? <gray>(example: <gold>6h = 6 hours<gray>)")
}

override fun acceptInput(context: ConversationContext, input: String?): Prompt? {
input?.let {
context.setSessionData(SetupKey.DURATION, Duration.parse(input))
override fun acceptInput(context: ConversationContext, input: String?): Prompt {
try {
input?.let {
context.setSessionData(SetupKey.DURATION, Duration.parse(input.lowercase()))
}
} catch (e: Exception) {
context.setSessionData("parse-error", null)
return this
}

return GenerateDockerComposePrompt()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class GenerateDockerComposePrompt : BooleanPrompt() {
return MiniMessage.miniMessage().deserialize("<green>Do you need a generated Docker Compose File or do you know your way around redis yourself? <gray>(Write: <gold>Yes for generate a file inside of plugin folder<gray>)")
}

override fun acceptValidatedInput(context: ConversationContext, input: Boolean): Prompt? {
override fun acceptValidatedInput(context: ConversationContext, input: Boolean): Prompt {
return if (input) {
context.setSessionData(SetupKey.DOCKER_COMPOSE, input)
context.setSessionData(SetupKey.DOCKER_COMPOSE, true)
FinishPrompt()
} else {
RedisAddressPrompt()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class RedisAddressPrompt : StringPrompt() {
return MiniMessage.miniMessage().deserialize("<green>What is the address of redis ? <gray>(<gold>Example format: \"redis://127.0.0.1:6379\"<gray>)")
}

override fun acceptInput(context: ConversationContext, input: String?): Prompt? {
override fun acceptInput(context: ConversationContext, input: String?): Prompt {
input?.let {
context.setSessionData(SetupKey.CONNECTION_ADDRESS, it)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ServerNamePrompt : StringPrompt() {
return MiniMessage.miniMessage().deserialize("<green>What is the name of the server instance in the network? <gray>(example: <gold>Lobby-1<gray>)")
}

override fun acceptInput(context: ConversationContext, input: String?): Prompt? {
override fun acceptInput(context: ConversationContext, input: String?): Prompt {
input?.let {
context.setSessionData(SetupKey.SERVER_NAME, it)
}
Expand Down

0 comments on commit 511fae5

Please sign in to comment.