1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-25 19:48:43 +00:00
This commit is contained in:
InsanusMokrassar 2024-01-07 20:05:05 +06:00
parent 8df72edd52
commit 955e9ca871

View File

@ -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)