From 7639b15dc6c01a2586a3a8d6952cb19282346948 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 9 Mar 2021 19:19:15 +0600 Subject: [PATCH] voice chats functionality included --- .../chat/members/PromoteChatMember.kt | 4 +++- .../ChatMember/AdministratorChatMemberImpl.kt | 2 ++ .../types/ChatMember/CreatorChatMember.kt | 2 ++ .../abstracts/AdministratorChatMember.kt | 1 + .../kotlin/dev/inmo/tgbotapi/types/Common.kt | 2 ++ .../ChatEvents/abstracts/VoiceChatEvent.kt | 3 +++ .../ChatEvents/voice/VoiceChatEnded.kt | 18 ++++++++++++++ .../voice/VoiceChatParticipantsInvited.kt | 13 ++++++++++ .../ChatEvents/voice/VoiceChatStarted.kt | 7 ++++++ .../inmo/tgbotapi/types/message/RawMessage.kt | 9 +++++++ .../api/chat/members/PromoteChatMember.kt | 24 ++++++++++++------- 11 files changed, 76 insertions(+), 9 deletions(-) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/abstracts/VoiceChatEvent.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/voice/VoiceChatEnded.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/voice/VoiceChatParticipantsInvited.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/voice/VoiceChatStarted.kt diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/members/PromoteChatMember.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/members/PromoteChatMember.kt index b878b0cd6a..74e17ee623 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/members/PromoteChatMember.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/members/PromoteChatMember.kt @@ -31,7 +31,9 @@ data class PromoteChatMember( @SerialName(canPinMessagesField) private val canPinMessages: Boolean? = null, @SerialName(canPromoteMembersField) - private val canPromoteMembers: Boolean? = null + private val canPromoteMembers: Boolean? = null, + @SerialName(canManageVoiceChatsField) + private val canManageVoiceChats: Boolean? = null ) : ChatMemberRequest, UntilDate { override fun method(): String = "promoteChatMember" override val resultDeserializer: DeserializationStrategy diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/AdministratorChatMemberImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/AdministratorChatMemberImpl.kt index dd16ba76de..109f9b27cc 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/AdministratorChatMemberImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/AdministratorChatMemberImpl.kt @@ -26,6 +26,8 @@ data class AdministratorChatMemberImpl( override val canPinMessages: Boolean = false, @SerialName(canPromoteMembersField) override val canPromoteMembers: Boolean = false, + @SerialName(canManageVoiceChatsField) + override val canManageVoiceChats: Boolean = false, @SerialName(isAnonymousField) override val isAnonymous: Boolean = false, @SerialName(customTitleField) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/CreatorChatMember.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/CreatorChatMember.kt index 014ac9c952..a47dafd111 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/CreatorChatMember.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/CreatorChatMember.kt @@ -30,6 +30,8 @@ data class CreatorChatMember( override val canPinMessages: Boolean = true @Transient override val canPromoteMembers: Boolean = true + @Transient + override val canManageVoiceChats: Boolean = true @SerialName(statusField) @Required private val type: String = "creator" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/abstracts/AdministratorChatMember.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/abstracts/AdministratorChatMember.kt index 7a7c9d0944..db02e9d67c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/abstracts/AdministratorChatMember.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatMember/abstracts/AdministratorChatMember.kt @@ -13,6 +13,7 @@ interface AdministratorChatMember : SpecialRightsChatMember { val canRemoveMessages: Boolean val canRestrictMembers: Boolean val canPromoteMembers: Boolean + val canManageVoiceChats: Boolean val isAnonymous: Boolean val customTitle: String? } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index 819fb35587..bb9f787337 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -239,6 +239,7 @@ const val canInviteUsersField = "can_invite_users" const val canRestrictMembersField = "can_restrict_members" const val canPinMessagesField = "can_pin_messages" const val canPromoteMembersField = "can_promote_members" +const val canManageVoiceChatsField = "can_manage_voice_chats" const val pngStickerField = "png_sticker" const val tgsStickerField = "tgs_sticker" @@ -331,6 +332,7 @@ const val telegramPaymentChargeIdField = "telegram_payment_charge_id" const val providerPaymentChargeIdField = "provider_payment_charge_id" const val providerTokenField = "provider_token" const val providerDataField = "provider_data" +const val usersField = "users" const val requireNameField = "need_name" const val requirePhoneNumberField = "need_phone_number" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/abstracts/VoiceChatEvent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/abstracts/VoiceChatEvent.kt new file mode 100644 index 0000000000..54bb629cde --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/abstracts/VoiceChatEvent.kt @@ -0,0 +1,3 @@ +package dev.inmo.tgbotapi.types.message.ChatEvents.abstracts + +interface VoiceChatEvent : SupergroupEvent diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/voice/VoiceChatEnded.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/voice/VoiceChatEnded.kt new file mode 100644 index 0000000000..3969e603fd --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/voice/VoiceChatEnded.kt @@ -0,0 +1,18 @@ +package dev.inmo.tgbotapi.types.message.ChatEvents.voice + +import com.soywiz.klock.TimeSpan +import com.soywiz.klock.seconds +import dev.inmo.tgbotapi.types.Seconds +import dev.inmo.tgbotapi.types.durationField +import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.VoiceChatEvent +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class VoiceChatEnded( + @SerialName(durationField) + val duration: Seconds +) : VoiceChatEvent { + val timeSpan: TimeSpan + get() = TimeSpan(duration.seconds.milliseconds) +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/voice/VoiceChatParticipantsInvited.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/voice/VoiceChatParticipantsInvited.kt new file mode 100644 index 0000000000..44bddaac29 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/voice/VoiceChatParticipantsInvited.kt @@ -0,0 +1,13 @@ +package dev.inmo.tgbotapi.types.message.ChatEvents.voice + +import dev.inmo.tgbotapi.types.User +import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.VoiceChatEvent +import dev.inmo.tgbotapi.types.usersField +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +class VoiceChatParticipantsInvited( + @SerialName(usersField) + val users: List = emptyList() +) : VoiceChatEvent diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/voice/VoiceChatStarted.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/voice/VoiceChatStarted.kt new file mode 100644 index 0000000000..9b72796ac1 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/voice/VoiceChatStarted.kt @@ -0,0 +1,7 @@ +package dev.inmo.tgbotapi.types.message.ChatEvents.voice + +import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.VoiceChatEvent +import kotlinx.serialization.Serializable + +@Serializable +object VoiceChatStarted : VoiceChatEvent diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt index e10f88de8b..d3b204c2ba 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt @@ -11,6 +11,7 @@ import dev.inmo.tgbotapi.types.games.RawGame import dev.inmo.tgbotapi.types.location.Location import dev.inmo.tgbotapi.types.message.ChatEvents.* import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.* +import dev.inmo.tgbotapi.types.message.ChatEvents.voice.* import dev.inmo.tgbotapi.types.message.abstracts.Message import dev.inmo.tgbotapi.types.message.abstracts.UnknownMessageType import dev.inmo.tgbotapi.types.message.content.* @@ -81,6 +82,11 @@ internal data class RawMessage( private val dice: Dice? = null, private val successful_payment: SuccessfulPayment? = null, + // Voice Chat Service Messages + private val voice_chat_started: VoiceChatStarted? = null, + private val voice_chat_ended: VoiceChatEnded? = null, + private val voice_chat_participants_invited: VoiceChatParticipantsInvited? = null, + // login property private val connected_website: String? = null, @@ -172,6 +178,9 @@ internal data class RawMessage( left_chat_member != null -> LeftChatMember(left_chat_member) new_chat_title != null -> NewChatTitle(new_chat_title) new_chat_photo != null -> NewChatPhoto(new_chat_photo.toList()) + voice_chat_started != null -> voice_chat_started + voice_chat_ended != null -> voice_chat_ended + voice_chat_participants_invited != null -> voice_chat_participants_invited delete_chat_photo -> DeleteChatPhoto() group_chat_created -> GroupChatCreated( migrate_to_chat_id diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/members/PromoteChatMember.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/members/PromoteChatMember.kt index e3f1dc9721..fe05c89a8d 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/members/PromoteChatMember.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/members/PromoteChatMember.kt @@ -17,7 +17,8 @@ suspend fun TelegramBot.promoteChatMember( canInviteUsers: Boolean? = null, canRestrictMembers: Boolean? = null, canPinMessages: Boolean? = null, - canPromoteMembers: Boolean? = null + canPromoteMembers: Boolean? = null, + canManageVoiceChats: Boolean? = null ) = execute( PromoteChatMember( chatId, @@ -31,7 +32,8 @@ suspend fun TelegramBot.promoteChatMember( canInviteUsers, canRestrictMembers, canPinMessages, - canPromoteMembers + canPromoteMembers, + canManageVoiceChats ) ) @@ -47,7 +49,8 @@ suspend fun TelegramBot.promoteChatMember( canInviteUsers: Boolean? = null, canRestrictMembers: Boolean? = null, canPinMessages: Boolean? = null, - canPromoteMembers: Boolean? = null + canPromoteMembers: Boolean? = null, + canManageVoiceChats: Boolean? ) = promoteChatMember( chat.id, userId, @@ -60,7 +63,8 @@ suspend fun TelegramBot.promoteChatMember( canInviteUsers, canRestrictMembers, canPinMessages, - canPromoteMembers + canPromoteMembers, + canManageVoiceChats ) suspend fun TelegramBot.promoteChatMember( @@ -75,7 +79,8 @@ suspend fun TelegramBot.promoteChatMember( canInviteUsers: Boolean? = null, canRestrictMembers: Boolean? = null, canPinMessages: Boolean? = null, - canPromoteMembers: Boolean? = null + canPromoteMembers: Boolean? = null, + canManageVoiceChats: Boolean? ) = promoteChatMember( chatId, user.id, @@ -88,7 +93,8 @@ suspend fun TelegramBot.promoteChatMember( canInviteUsers, canRestrictMembers, canPinMessages, - canPromoteMembers + canPromoteMembers, + canManageVoiceChats ) suspend fun TelegramBot.promoteChatMember( @@ -103,7 +109,8 @@ suspend fun TelegramBot.promoteChatMember( canInviteUsers: Boolean? = null, canRestrictMembers: Boolean? = null, canPinMessages: Boolean? = null, - canPromoteMembers: Boolean? = null + canPromoteMembers: Boolean? = null, + canManageVoiceChats: Boolean? ) = promoteChatMember( chat.id, user.id, @@ -116,5 +123,6 @@ suspend fun TelegramBot.promoteChatMember( canInviteUsers, canRestrictMembers, canPinMessages, - canPromoteMembers + canPromoteMembers, + canManageVoiceChats )