1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-22 08:37:12 +00:00

make bots username nullable

This commit is contained in:
InsanusMokrassar 2023-06-30 14:09:13 +06:00
parent 8247e7c69c
commit b3a657b7d6
3 changed files with 8 additions and 10 deletions

View File

@ -170,12 +170,12 @@ data class ExtendedForumChatImpl(
@Serializable
data class ExtendedBot(
override val id: UserId,
@SerialName(usernameField)
override val username: Username,
@SerialName(firstNameField)
override val firstName: String,
@SerialName(lastNameField)
override val lastName: String = "",
@SerialName(usernameField)
override val username: Username? = null,
@SerialName(canJoinGroupsField)
val canJoinGroups: Boolean = false,
@SerialName(canReadAllGroupMessagesField)

View File

@ -67,19 +67,17 @@ data class ChannelChatImpl(
sealed class User : PrivateChat
@Serializable(UserSerializer::class)
sealed class Bot : User() {
abstract override val username: Username
}
sealed class Bot : User()
@Serializable
data class CommonBot(
override val id: UserId,
@SerialName(usernameField)
override val username: Username,
@SerialName(firstNameField)
override val firstName: String,
@SerialName(lastNameField)
override val lastName: String = ""
override val lastName: String = "",
@SerialName(usernameField)
override val username: Username? = null,
) : Bot() {
@SerialName(isBotField)
private val isBot = true

View File

@ -28,9 +28,9 @@ val WebAppUser.isPremium
fun WebAppUser.asUser() = if (isBot == true) {
CommonBot(
UserId(id),
username ?.let(::Username) ?: error("Username is absent for bot, but must exists"),
firstName,
lastName ?: ""
lastName ?: "",
username ?.let(::Username) ?: error("Username is absent for bot, but must exists")
)
} else {
CommonUser(