1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-27 20:48:44 +00:00

include ChatMemberUpdated functionality

This commit is contained in:
InsanusMokrassar 2021-03-11 20:17:08 +06:00
parent 2be342a769
commit c027244fbd
8 changed files with 68 additions and 14 deletions

View File

@ -17,7 +17,7 @@ private data class RawChatInviteLink(
@SerialName(isRevokedField)
val isRevoked: Boolean,
@SerialName(expireDateField)
val expirationDateTime: UnixTimeStamp? = null,
val expirationDateTime: TelegramDate? = null,
@SerialName(memberLimitField)
val membersLimit: MembersLimit ?= null
)
@ -27,7 +27,7 @@ private fun ChatInviteLink.toRawChatInviteLink() = RawChatInviteLink(
creator,
isPrimary,
isRevoked,
expirationDateTime ?.unixMillis ?.milliseconds ?.seconds ?.toLong(),
expirationDateTime ?.toTelegramDate(),
membersLimit
)
@ -50,16 +50,14 @@ data class PrimaryInviteLink(
@SerialName(isRevokedField)
override val isRevoked: Boolean = false,
@SerialName(expireDateField)
private val expireDate: UnixTimeStamp? = null,
private val expireDate: TelegramDate? = null,
@SerialName(memberLimitField)
override val membersLimit: MembersLimit? = null
) : ChatInviteLink() {
override val isPrimary: Boolean
get() = true
override val expirationDateTime: DateTime?
get() {
return DateTime(expireDate ?.seconds ?.milliseconds ?: return null)
}
get() = expireDate ?.asDate
}
@Serializable
@ -71,16 +69,14 @@ data class CommonInviteLink(
@SerialName(isRevokedField)
override val isRevoked: Boolean = false,
@SerialName(expireDateField)
private val expireDate: UnixTimeStamp? = null,
private val expireDate: TelegramDate? = null,
@SerialName(memberLimitField)
override val membersLimit: MembersLimit? = null
) : ChatInviteLink() {
override val isPrimary: Boolean
get() = false
override val expirationDateTime: DateTime?
get() {
return DateTime(expireDate ?.seconds ?.milliseconds ?: return null)
}
get() = expireDate ?.asDate
}
@Serializer(ChatInviteLink::class)

View File

@ -0,0 +1,22 @@
package dev.inmo.tgbotapi.types
import dev.inmo.tgbotapi.types.ChatMember.abstracts.ChatMember
import dev.inmo.tgbotapi.types.chat.abstracts.Chat
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class ChatMemberUpdated(
@SerialName(chatField)
val chat: Chat,
@SerialName(fromField)
val user: User,
@SerialName(dateField)
val date: TelegramDate,
@SerialName(oldChatMemberField)
val oldChatMemberState: ChatMember,
@SerialName(newChatMemberField)
val newChatMemberState: ChatMember,
@SerialName(inviteLinkField)
val inviteLink: ChatInviteLink? = null
)

View File

@ -253,6 +253,8 @@ const val canManageVoiceChatsField = "can_manage_voice_chats"
const val canManageChatField = "can_manage_chat"
const val pngStickerField = "png_sticker"
const val tgsStickerField = "tgs_sticker"
const val oldChatMemberField = "old_chat_member"
const val newChatMemberField = "new_chat_member"
const val okField = "ok"
const val captionField = "caption"

View File

@ -11,6 +11,8 @@ const val UPDATE_SHIPPING_QUERY = "shipping_query"
const val UPDATE_PRE_CHECKOUT_QUERY = "pre_checkout_query"
const val UPDATE_POLL = "poll"
const val UPDATE_POLL_ANSWER = "poll_answer"
const val MY_CHAT_MEMBER = "my_chat_member"
const val CHAT_MEMBER = "chat_member"
val ALL_UPDATES_LIST = listOf(
UPDATE_MESSAGE,
@ -23,5 +25,7 @@ val ALL_UPDATES_LIST = listOf(
UPDATE_SHIPPING_QUERY,
UPDATE_PRE_CHECKOUT_QUERY,
UPDATE_POLL,
UPDATE_POLL_ANSWER
UPDATE_POLL_ANSWER,
MY_CHAT_MEMBER,
CHAT_MEMBER
)

View File

@ -0,0 +1,10 @@
package dev.inmo.tgbotapi.types.update
import dev.inmo.tgbotapi.types.ChatMemberUpdated
import dev.inmo.tgbotapi.types.UpdateIdentifier
import dev.inmo.tgbotapi.types.update.abstracts.ChatMemberUpdatedUpdate
data class CommonChatMemberUpdatedUpdate(
override val updateId: UpdateIdentifier,
override val data: ChatMemberUpdated
) : ChatMemberUpdatedUpdate

View File

@ -0,0 +1,10 @@
package dev.inmo.tgbotapi.types.update
import dev.inmo.tgbotapi.types.ChatMemberUpdated
import dev.inmo.tgbotapi.types.UpdateIdentifier
import dev.inmo.tgbotapi.types.update.abstracts.ChatMemberUpdatedUpdate
data class MyChatMemberUpdatedUpdate(
override val updateId: UpdateIdentifier,
override val data: ChatMemberUpdated
) : ChatMemberUpdatedUpdate

View File

@ -1,9 +1,9 @@
package dev.inmo.tgbotapi.types.update
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.CallbackQuery.RawCallbackQuery
import dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult.RawChosenInlineResult
import dev.inmo.tgbotapi.types.InlineQueries.query.RawInlineQuery
import dev.inmo.tgbotapi.types.UpdateIdentifier
import dev.inmo.tgbotapi.types.message.abstracts.*
import dev.inmo.tgbotapi.types.payments.PreCheckoutQuery
import dev.inmo.tgbotapi.types.payments.ShippingQuery
@ -11,7 +11,6 @@ import dev.inmo.tgbotapi.types.polls.Poll
import dev.inmo.tgbotapi.types.polls.PollAnswer
import dev.inmo.tgbotapi.types.update.abstracts.UnknownUpdate
import dev.inmo.tgbotapi.types.update.abstracts.Update
import dev.inmo.tgbotapi.types.updateIdField
import kotlinx.serialization.*
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.jsonObject
@ -34,7 +33,9 @@ internal data class RawUpdate constructor(
private val shipping_query: ShippingQuery? = null,
private val pre_checkout_query: PreCheckoutQuery? = null,
private val poll: Poll? = null,
private val poll_answer: PollAnswer? = null
private val poll_answer: PollAnswer? = null,
private val my_chat_member: ChatMemberUpdated? = null,
private val chat_member: ChatMemberUpdated? = null
) {
private var initedUpdate: Update? = null
/**
@ -58,6 +59,8 @@ internal data class RawUpdate constructor(
pre_checkout_query != null -> PreCheckoutQueryUpdate(updateId, pre_checkout_query)
poll != null -> PollUpdate(updateId, poll)
poll_answer != null -> PollAnswerUpdate(updateId, poll_answer)
my_chat_member != null -> MyChatMemberUpdatedUpdate(updateId, my_chat_member)
chat_member != null -> CommonChatMemberUpdatedUpdate(updateId, chat_member)
else -> UnknownUpdate(
updateId,
raw.toString(),

View File

@ -0,0 +1,7 @@
package dev.inmo.tgbotapi.types.update.abstracts
import dev.inmo.tgbotapi.types.ChatMemberUpdated
interface ChatMemberUpdatedUpdate : Update {
override val data: ChatMemberUpdated
}