1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-06-03 00:15:27 +00:00
tgbotapi/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/RawChat.kt

62 lines
2.0 KiB
Kotlin
Raw Normal View History

2018-12-26 08:07:24 +00:00
package com.github.insanusmokrassar.TelegramBotAPI.types.chat
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
2018-12-26 08:07:24 +00:00
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
2019-04-13 02:21:19 +00:00
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
2018-12-26 08:07:24 +00:00
@Serializable
data class RawChat(
override val id: ChatId,
private val type: String,
2019-04-13 02:16:40 +00:00
private val title: String? = null,
private val username: Username? = null,
private val first_name: String? = null,
private val last_name: String? = null,
private val description: String? = null,
private val invite_link: String? = null,
private val pinned_message: RawMessage? = null,
private val sticker_set_name: String? = null,
private val can_set_sticker_set: Boolean? = null,
2018-12-26 08:07:24 +00:00
@SerialName("photo")
2019-08-12 07:46:16 +00:00
override val chatPhoto: ChatPhoto? = null,
private val permissions: ChatPermissions? = null
2018-12-26 08:07:24 +00:00
) : Chat {
fun extractChat(): Chat {
return when (type) {
"private" -> PrivateChat(id, username, first_name, last_name, chatPhoto)
"group" -> GroupChatImpl(
id,
title,
invite_link,
2019-08-12 07:46:16 +00:00
chatPhoto,
pinned_message,
permissions
2018-12-26 08:07:24 +00:00
)
"supergroup" -> SupergroupChat(
id,
title,
username,
description,
invite_link,
chatPhoto,
pinned_message,
sticker_set_name,
2019-08-12 07:46:16 +00:00
can_set_sticker_set ?: false,
permissions
2018-12-26 08:07:24 +00:00
)
"channel" -> ChannelChat(
id,
title,
username,
description,
invite_link,
chatPhoto,
pinned_message
)
else -> throw IllegalArgumentException("Unknown type of chat")
}
}
}