1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 00:03:48 +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 @Serializable
data class ExtendedBot( data class ExtendedBot(
override val id: UserId, override val id: UserId,
@SerialName(usernameField)
override val username: Username,
@SerialName(firstNameField) @SerialName(firstNameField)
override val firstName: String, override val firstName: String,
@SerialName(lastNameField) @SerialName(lastNameField)
override val lastName: String = "", override val lastName: String = "",
@SerialName(usernameField)
override val username: Username? = null,
@SerialName(canJoinGroupsField) @SerialName(canJoinGroupsField)
val canJoinGroups: Boolean = false, val canJoinGroups: Boolean = false,
@SerialName(canReadAllGroupMessagesField) @SerialName(canReadAllGroupMessagesField)

View File

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

View File

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