diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventAction.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventAction.kt index 286e2f3c88..196dcbf149 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventAction.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventAction.kt @@ -214,3 +214,8 @@ suspend fun BehaviourContext.waitChatShared( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } ) = waitEvents(initRequest, errorFactory) + +suspend fun BehaviourContext.waitChatBoostAdded( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null } +) = waitEvents(initRequest, errorFactory) diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventActionMessages.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventActionMessages.kt index 55d89bbc75..61246132b7 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventActionMessages.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventActionMessages.kt @@ -208,3 +208,8 @@ suspend fun BehaviourContext.waitChatSharedEventsMessages( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null } ) = waitEventsMessages(initRequest, errorFactory) + +suspend fun BehaviourContext.waitChatBoostAddedEventsMessages( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null } +) = waitEventsMessages(initRequest, errorFactory) diff --git a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt index 6fe38413da..55ff317b64 100644 --- a/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt +++ b/tgbotapi.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt @@ -823,3 +823,24 @@ suspend fun BC.onChatShared( markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, scenarioReceiver: CustomBehaviourContextAndTypeReceiver> ) = onEventWithCustomChatEventMessage(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) + + + +/** + * @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call + * @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example, + * this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage]. + * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own. + * Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times] + * to combinate several filters + * @param markerFactory Will be used to identify different "stream". [scenarioReceiver] will be called synchronously + * in one "stream". Output of [markerFactory] will be used as a key for "stream" + * @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that + * data + */ +suspend fun BC.onChatBoostAdded( + initialFilter: SimpleFilter>? = null, + subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver, Update>? = MessageFilterByChat, + markerFactory: MarkerFactory, Any> = ByChatMessageMarkerFactory, + scenarioReceiver: CustomBehaviourContextAndTypeReceiver> +) = onEventWithCustomChatEventMessage(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) 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 44b0f6df67..9b1ef20df7 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 @@ -656,6 +656,7 @@ const val menuButtonField = "menu_button" const val boostIdField = "boost_id" const val boostField = "boost" +const val boostCountField = "boost_count" const val addDateField = "add_date" const val expirationDateField = "expiration_date" const val removeDateField = "remove_date" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/ChatBoostAdded.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/ChatBoostAdded.kt new file mode 100644 index 0000000000..2153239057 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/ChatBoostAdded.kt @@ -0,0 +1,12 @@ +package dev.inmo.tgbotapi.types.message.ChatEvents + +import dev.inmo.tgbotapi.types.boostCountField +import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.PublicChatEvent +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class ChatBoostAdded( + @SerialName(boostCountField) + val count: Int +) : PublicChatEvent 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 0a8735da19..2b97286d0c 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 @@ -117,6 +117,9 @@ internal data class RawMessage( private val general_forum_topic_unhidden: GeneralForumTopicUnhidden? = null, private val write_access_allowed: WriteAccessAllowed? = null, + // Boost added to groups + private val boost_added: ChatBoostAdded? = null, + // AutoDelete Message time changed private val message_auto_delete_timer_changed: MessageAutoDeleteTimerChanged? = null, @@ -247,6 +250,7 @@ internal data class RawMessage( giveaway_created != null -> giveaway_created giveaway_winners is GiveawayPrivateResults -> giveaway_winners giveaway_completed != null -> giveaway_completed + boost_added != null -> boost_added else -> null } } diff --git a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNew.kt b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNew.kt index e73520d8cd..428d4eb8d6 100644 --- a/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNew.kt +++ b/tgbotapi.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCastsNew.kt @@ -222,6 +222,7 @@ import dev.inmo.tgbotapi.types.media.TitledTelegramMedia import dev.inmo.tgbotapi.types.media.VisualMediaGroupMemberTelegramMedia import dev.inmo.tgbotapi.types.message.ChannelEventMessage import dev.inmo.tgbotapi.types.message.ChatEvents.ChannelChatCreated +import dev.inmo.tgbotapi.types.message.ChatEvents.ChatBoostAdded import dev.inmo.tgbotapi.types.message.ChatEvents.DeleteChatPhoto import dev.inmo.tgbotapi.types.message.ChatEvents.GroupChatCreated import dev.inmo.tgbotapi.types.message.ChatEvents.LeftChatMemberEvent @@ -2882,6 +2883,15 @@ public inline fun ChatEvent.channelChatCreatedOrThrow(): ChannelChatCreated = th public inline fun ChatEvent.ifChannelChatCreated(block: (ChannelChatCreated) -> T): T? = channelChatCreatedOrNull() ?.let(block) +public inline fun ChatEvent.chatBoostAddedOrNull(): ChatBoostAdded? = this as? + dev.inmo.tgbotapi.types.message.ChatEvents.ChatBoostAdded + +public inline fun ChatEvent.chatBoostAddedOrThrow(): ChatBoostAdded = this as + dev.inmo.tgbotapi.types.message.ChatEvents.ChatBoostAdded + +public inline fun ChatEvent.ifChatBoostAdded(block: (ChatBoostAdded) -> T): T? = + chatBoostAddedOrNull() ?.let(block) + public inline fun ChatEvent.deleteChatPhotoOrNull(): DeleteChatPhoto? = this as? dev.inmo.tgbotapi.types.message.ChatEvents.DeleteChatPhoto