From f68d75fb27279a8c0db62b66e6983918bf2b4e7d Mon Sep 17 00:00:00 2001 From: Hope <34831095+HopeBaron@users.noreply.github.com> Date: Fri, 26 Mar 2021 20:25:08 +0200 Subject: [PATCH] Fix snowflakeOrNull behavior (#223) --- core/src/main/kotlin/Util.kt | 4 ++-- core/src/main/kotlin/entity/interaction/Interaction.kt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/kotlin/Util.kt b/core/src/main/kotlin/Util.kt index b79020ca6c7..5aca9b0bf3c 100644 --- a/core/src/main/kotlin/Util.kt +++ b/core/src/main/kotlin/Util.kt @@ -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) diff --git a/core/src/main/kotlin/entity/interaction/Interaction.kt b/core/src/main/kotlin/entity/interaction/Interaction.kt index a41e10b6b8a..1681f9c87d6 100644 --- a/core/src/main/kotlin/entity/interaction/Interaction.kt +++ b/core/src/main/kotlin/entity/interaction/Interaction.kt @@ -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 ->