Skip to content

Commit

Permalink
Change field visibility and single-expression return syntax (#335)
Browse files Browse the repository at this point in the history
* changed the visibility for the name, descript.. and type field, changed the toRequest functions to single expression-styled returns

* remade .name and .description to public upon request, kept .type protected

* remade .type into read only (val)
  • Loading branch information
NoakPalander authored Jul 3, 2021
1 parent b0c1f34 commit 9258d3c
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions rest/src/main/kotlin/builder/interaction/OptionsBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import kotlin.contracts.contract
sealed class OptionsBuilder(
var name: String,
var description: String,
var type: ApplicationCommandOptionType,
val type: ApplicationCommandOptionType,
) :
RequestBuilder<ApplicationCommandOption> {
internal var _default: OptionalBoolean = OptionalBoolean.Missing
Expand All @@ -28,35 +28,36 @@ sealed class OptionsBuilder(
internal var _required: OptionalBoolean = OptionalBoolean.Missing
var required: Boolean? by ::_required.delegate()

override fun toRequest(): ApplicationCommandOption {
return ApplicationCommandOption(type, name, description, _default, _required)
}
override fun toRequest() = ApplicationCommandOption(
type,
name,
description,
_default,
_required
)
}

@KordDsl
@KordPreview
sealed class BaseChoiceBuilder<T>(
name: String,
description: String,
type: ApplicationCommandOptionType,
type: ApplicationCommandOptionType
) :
OptionsBuilder(name, description, type) {
private var _choices: Optional<MutableList<Choice<*>>> = Optional.Missing()
var choices: MutableList<Choice<*>>? by ::_choices.delegate()

abstract fun choice(name: String, value: T)

override fun toRequest(): ApplicationCommandOption {
return ApplicationCommandOption(
type,
name,
description,
choices = _choices,
required = _required,
default = _default
)
}

override fun toRequest() = ApplicationCommandOption(
type,
name,
description,
choices = _choices,
required = _required,
default = _default
)
}

@KordDsl
Expand Down Expand Up @@ -116,12 +117,12 @@ sealed class BaseCommandOptionBuilder(
private var _options: Optional<MutableList<OptionsBuilder>> = Optional.Missing()
var options by ::_options.delegate()

override fun toRequest(): ApplicationCommandOption {
return ApplicationCommandOption(type,
name,
description,
options = _options.mapList { it.toRequest() })
}
override fun toRequest() = ApplicationCommandOption(
type,
name,
description,
options = _options.mapList { it.toRequest() }
)
}

@KordDsl
Expand Down Expand Up @@ -181,7 +182,6 @@ class SubCommandBuilder(name: String, description: String) :
options!!.add(MentionableBuilder(name, description).apply(builder))

}

}

@KordDsl
Expand Down

0 comments on commit 9258d3c

Please sign in to comment.