mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-26 03:58:44 +00:00
fix of #816
This commit is contained in:
parent
8df72edd52
commit
955e9ca871
@ -85,17 +85,24 @@ fun Int.toChatId(): IdChatIdentifier = toLong().toChatId()
|
|||||||
fun Byte.toChatId(): IdChatIdentifier = toLong().toChatId()
|
fun Byte.toChatId(): IdChatIdentifier = toLong().toChatId()
|
||||||
|
|
||||||
@Serializable(ChatIdentifierSerializer::class)
|
@Serializable(ChatIdentifierSerializer::class)
|
||||||
data class Username(
|
@JvmInline
|
||||||
|
value class Username(
|
||||||
val username: String
|
val username: String
|
||||||
) : ChatIdentifier {
|
) : ChatIdentifier {
|
||||||
val usernameWithoutAt
|
val usernameWithoutAt
|
||||||
get() = username.dropWhile { it == '@' }
|
get() = username.dropWhile { it == '@' }
|
||||||
|
val full: String
|
||||||
|
get() = username
|
||||||
|
|
||||||
init {
|
init {
|
||||||
if (!username.startsWith("@")) {
|
if (!username.startsWith("@")) {
|
||||||
throw IllegalArgumentException("Username must starts with `@`")
|
throw IllegalArgumentException("Username must starts with `@`")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return full
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun String.toUsername(): Username = Username(this)
|
fun String.toUsername(): Username = Username(this)
|
||||||
|
Loading…
Reference in New Issue
Block a user