Skip to content

Commit

Permalink
Fix snowflakeOrNull behavior (kordlib#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
HopeBaron authored Mar 26, 2021
1 parent 3162422 commit f68d75f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions core/src/main/kotlin/Util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ import kotlin.reflect.KClass

internal fun String?.toSnowflakeOrNull(): Snowflake? = when {
this == null -> null
else -> runCatching { Snowflake(this) }.getOrNull()
else -> Snowflake(this)
}

internal fun Long?.toSnowflakeOrNull(): Snowflake? = when {
this == null -> null
else -> runCatching { Snowflake(this) }.getOrNull()
else -> Snowflake(this)
}

internal fun String.toInstant() = DateTimeFormatter.ISO_OFFSET_DATE_TIME.parse(this, Instant::from)
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/kotlin/entity/interaction/Interaction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ fun OptionValue(value: DiscordOptionValue<*>, resolvedObjects: ResolvedObjects?)
if (resolvedObjects == null) return OptionValue.StringOptionValue(value.value)

val string = value.value
val snowflake = string.toSnowflakeOrNull() ?: return OptionValue.StringOptionValue(string)
val snowflake = string.toLongOrNull().toSnowflakeOrNull() ?: return OptionValue.StringOptionValue(string)

when {
resolvedObjects.members?.get(snowflake) != null ->
Expand Down

0 comments on commit f68d75f

Please sign in to comment.