Skip to content

Commit

Permalink
Fixes/0.7.x/string argument as snowflake (kordlib#222)
Browse files Browse the repository at this point in the history
* check if an argument is actually a snowflake

* Use value since it's already a string

* Return null if snowflake couldn't be parsed to long
  • Loading branch information
HopeBaron authored Mar 26, 2021
1 parent b4c4a0c commit 3162422
Showing 1 changed file with 2 additions and 2 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 -> Snowflake(this)
else -> runCatching { Snowflake(this) }.getOrNull()
}

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

internal fun String.toInstant() = DateTimeFormatter.ISO_OFFSET_DATE_TIME.parse(this, Instant::from)
Expand Down

0 comments on commit 3162422

Please sign in to comment.