Skip to content

Commit

Permalink
fix: clamp the int input field to 32 bit signed numbers by default
Browse files Browse the repository at this point in the history
  • Loading branch information
ToxicMushroom committed Sep 21, 2023
1 parent 2757617 commit eb2b3e5
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class IntConverter(
public val maxValue: Int? = Int.MAX_VALUE,
public val minValue: Int? = Int.MIN_VALUE,

override var validator: Validator<Int> = null
override var validator: Validator<Int> = null,
) : SingleConverter<Int>() {
override val signatureTypeString: String = "converters.number.signatureType"

Expand Down Expand Up @@ -86,7 +86,9 @@ public class IntConverter(
override suspend fun toSlashOption(arg: Argument<*>): OptionData =
OptionData(OptionType.INTEGER, arg.displayName, arg.description, required).apply {
this@IntConverter.maxValue?.toLong()?.let { this.setMaxValue(it) }
?: run { this.setMaxValue(Int.MAX_VALUE.toLong()) }
this@IntConverter.minValue?.toLong()?.let { this.setMinValue(it) }
?: run { this.setMaxValue(Int.MIN_VALUE.toLong()) }
}

override suspend fun parseOption(context: CommandContext, option: OptionMapping): Boolean {
Expand Down

0 comments on commit eb2b3e5

Please sign in to comment.