From 955e9ca871f23c82deba880f6e6a8056effa5247 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 7 Jan 2024 20:05:05 +0600 Subject: [PATCH] fix of #816 --- .../kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt index 96881e086b..79537d5231 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt @@ -85,17 +85,24 @@ fun Int.toChatId(): IdChatIdentifier = toLong().toChatId() fun Byte.toChatId(): IdChatIdentifier = toLong().toChatId() @Serializable(ChatIdentifierSerializer::class) -data class Username( +@JvmInline +value class Username( val username: String ) : ChatIdentifier { val usernameWithoutAt get() = username.dropWhile { it == '@' } + val full: String + get() = username init { if (!username.startsWith("@")) { throw IllegalArgumentException("Username must starts with `@`") } } + + override fun toString(): String { + return full + } } fun String.toUsername(): Username = Username(this)