1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-29 21:48:43 +00:00

UnknownCallbackQueryType

This commit is contained in:
InsanusMokrassar 2020-01-23 03:59:59 +06:00
parent cf814fcecb
commit f4fe680cac
4 changed files with 27 additions and 7 deletions

View File

@ -84,6 +84,7 @@ while they can work incorrectly
* `UnknownUpdateType` * `UnknownUpdateType`
* `UnknownMessageType` * `UnknownMessageType`
* `UnknownChatType` * `UnknownChatType`
* `UnknownCallbackQueryType`
## 0.21.0 TelegramBotAPI 4.5 ## 0.21.0 TelegramBotAPI 4.5

View File

@ -8,3 +8,10 @@ interface CallbackQuery {
val user: User val user: User
val chatInstance: String val chatInstance: String
} }
data class UnknownCallbackQueryType(
override val id: CallbackQueryIdentifier,
override val user: User,
override val chatInstance: String,
val raw: String
) : CallbackQuery

View File

@ -22,13 +22,21 @@ internal data class RawCallbackQuery(
@SerialName("game_short_name") @SerialName("game_short_name")
val gameShortName: String? = null val gameShortName: String? = null
) { ) {
val asCallbackQuery: CallbackQuery by lazy { private var inited: CallbackQuery? = null
when { fun asCallbackQuery(raw: String): CallbackQuery {
return inited ?: when {
message != null && data != null -> MessageDataCallbackQuery(id, from, chatInstance, message, data) message != null && data != null -> MessageDataCallbackQuery(id, from, chatInstance, message, data)
message != null && gameShortName != null -> MessageGameShortNameCallbackQuery(id, from, chatInstance, message, gameShortName) message != null && gameShortName != null -> MessageGameShortNameCallbackQuery(id, from, chatInstance, message, gameShortName)
inlineMessageId != null && data != null -> InlineMessageIdDataCallbackQuery(id, from, chatInstance, inlineMessageId, data) inlineMessageId != null && data != null -> InlineMessageIdDataCallbackQuery(id, from, chatInstance, inlineMessageId, data)
inlineMessageId != null && gameShortName != null -> InlineMessageIdGameShortNameCallbackQuery(id, from, chatInstance, inlineMessageId, gameShortName) inlineMessageId != null && gameShortName != null -> InlineMessageIdGameShortNameCallbackQuery(id, from, chatInstance, inlineMessageId, gameShortName)
else -> throw IllegalStateException("Strange answer from server, can't create callback query") else -> UnknownCallbackQueryType(
id,
from,
chatInstance,
raw
)
}.also {
inited = it
} }
} }
} }

View File

@ -14,6 +14,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update
import com.github.insanusmokrassar.TelegramBotAPI.types.updateIdField import com.github.insanusmokrassar.TelegramBotAPI.types.updateIdField
import kotlinx.serialization.SerialName import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import kotlinx.serialization.json.JsonElement
@Serializable @Serializable
internal data class RawUpdate constructor( internal data class RawUpdate constructor(
@ -38,7 +39,7 @@ internal data class RawUpdate constructor(
/** /**
* @return One of children of [Update] interface or null in case of unknown type of update * @return One of children of [Update] interface or null in case of unknown type of update
*/ */
fun asUpdate(raw: String): Update { fun asUpdate(raw: JsonElement): Update {
return initedUpdate ?: when { return initedUpdate ?: when {
edited_message != null -> EditMessageUpdate(updateId, edited_message) edited_message != null -> EditMessageUpdate(updateId, edited_message)
message != null -> MessageUpdate(updateId, message) message != null -> MessageUpdate(updateId, message)
@ -47,13 +48,16 @@ internal data class RawUpdate constructor(
chosen_inline_result != null -> ChosenInlineResultUpdate(updateId, chosen_inline_result.asChosenInlineResult) chosen_inline_result != null -> ChosenInlineResultUpdate(updateId, chosen_inline_result.asChosenInlineResult)
inline_query != null -> InlineQueryUpdate(updateId, inline_query.asInlineQuery) inline_query != null -> InlineQueryUpdate(updateId, inline_query.asInlineQuery)
callback_query != null -> CallbackQueryUpdate(updateId, callback_query.asCallbackQuery) callback_query != null -> CallbackQueryUpdate(
updateId,
callback_query.asCallbackQuery(raw.jsonObject["callback_query"].toString())
)
shipping_query != null -> ShippingQueryUpdate(updateId, shipping_query) shipping_query != null -> ShippingQueryUpdate(updateId, shipping_query)
pre_checkout_query != null -> PreCheckoutQueryUpdate(updateId, pre_checkout_query) pre_checkout_query != null -> PreCheckoutQueryUpdate(updateId, pre_checkout_query)
poll != null -> PollUpdate(updateId, poll) poll != null -> PollUpdate(updateId, poll)
else -> UnknownUpdateType( else -> UnknownUpdateType(
updateId, updateId,
raw raw.toString()
) )
}.also { }.also {
initedUpdate = it initedUpdate = it