mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 00:03:48 +00:00
add events waiters and triggers for topics
This commit is contained in:
parent
ee0c017a79
commit
0d37147a36
13
CHANGELOG.md
13
CHANGELOG.md
@ -2,6 +2,19 @@
|
||||
|
||||
## 4.0.0
|
||||
|
||||
**!!! THIS UPDATE CONTAINS FULL REWORK OF MEDIA GROUPS FUNCTIONALITY !!!**
|
||||
|
||||
**THIS UPDATE CONTAINS BREAKING CHANGES**
|
||||
|
||||
* `Common`:
|
||||
* All the media groups have been rewritten. Since this update, there are no separated messages types for media groups,
|
||||
but new type of content (`MediaGroupContent`) has been introduced
|
||||
* [Bot API 6.3](https://core.telegram.org/bots/api-changelog#november-5-2022) support
|
||||
* `Versions`:
|
||||
* `MicroUtils`: `0.13.2` -> `0.14.0`
|
||||
* `Core`:
|
||||
* New requests
|
||||
|
||||
## 3.3.1
|
||||
|
||||
* `Versions`:
|
||||
|
@ -7,6 +7,9 @@ import dev.inmo.tgbotapi.extensions.utils.*
|
||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.*
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.*
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicClosed
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicCreated
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicReopened
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.voice.*
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage
|
||||
import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentEvent
|
||||
@ -136,3 +139,15 @@ suspend fun BehaviourContext.waitWebAppDataEvents(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null }
|
||||
) = waitEvents<WebAppData>(initRequest, errorFactory)
|
||||
suspend fun BehaviourContext.waitForumTopicClosed(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null }
|
||||
) = waitEvents<ForumTopicClosed>(initRequest, errorFactory)
|
||||
suspend fun BehaviourContext.waitForumTopicCreated(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null }
|
||||
) = waitEvents<ForumTopicCreated>(initRequest, errorFactory)
|
||||
suspend fun BehaviourContext.waitForumTopicReopened(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null }
|
||||
) = waitEvents<ForumTopicReopened>(initRequest, errorFactory)
|
||||
|
@ -7,6 +7,9 @@ import dev.inmo.tgbotapi.extensions.utils.*
|
||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.*
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.*
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicClosed
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicCreated
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicReopened
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.voice.*
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage
|
||||
import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentEvent
|
||||
@ -133,3 +136,15 @@ suspend fun BehaviourContext.waitWebAppDataEventsMessages(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null }
|
||||
) = waitEventsMessages<WebAppData>(initRequest, errorFactory)
|
||||
suspend fun BehaviourContext.waitForumTopicClosedEventsMessages(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null }
|
||||
) = waitEventsMessages<ForumTopicClosed>(initRequest, errorFactory)
|
||||
suspend fun BehaviourContext.waitForumTopicCreatedEventsMessages(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null }
|
||||
) = waitEventsMessages<ForumTopicCreated>(initRequest, errorFactory)
|
||||
suspend fun BehaviourContext.waitForumTopicReopenedEventsMessages(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null }
|
||||
) = waitEventsMessages<ForumTopicReopened>(initRequest, errorFactory)
|
||||
|
@ -11,9 +11,13 @@ import dev.inmo.tgbotapi.extensions.utils.baseSentMessageUpdateOrNull
|
||||
import dev.inmo.tgbotapi.extensions.utils.chatEventMessageOrNull
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.*
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.*
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicClosed
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicCreated
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.forum.ForumTopicReopened
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.voice.*
|
||||
import dev.inmo.tgbotapi.types.message.PrivateEventMessage
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.SupergroupEventMessage
|
||||
import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentEvent
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||
|
||||
@ -27,6 +31,16 @@ internal suspend inline fun <BC : BehaviourContext, reified T : ChatEvent> BC.on
|
||||
(it.baseSentMessageUpdateOrNull() ?.data ?.chatEventMessageOrNull() ?.takeIf { it.chatEvent is T } as? ChatEventMessage<T>) ?.let(::listOfNotNull)
|
||||
}
|
||||
|
||||
internal suspend inline fun <BC : BehaviourContext, reified T : ChatEvent, reified CEM : ChatEventMessage<T>> BC.onEventWithCustomChatEventMessage(
|
||||
initialFilter: SimpleFilter<CEM>? = null,
|
||||
noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CEM, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in CEM, Any> = ByChatMessageMarkerFactory,
|
||||
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CEM>
|
||||
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
(it.baseSentMessageUpdateOrNull() ?.data ?.chatEventMessageOrNull() ?.takeIf { it.chatEvent is T } as? CEM) ?.let(::listOfNotNull)
|
||||
}
|
||||
|
||||
/**
|
||||
* @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,
|
||||
@ -503,12 +517,61 @@ suspend fun <BC : BehaviourContext> BC.onWebAppData(
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, PrivateEventMessage<WebAppData>, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in ChatEventMessage<WebAppData>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, PrivateEventMessage<WebAppData>>
|
||||
) = onEvent(
|
||||
initialFilter ?.let { { it is PrivateEventMessage<WebAppData> && initialFilter(it) } },
|
||||
subcontextUpdatesFilter ?.let { { message: ChatEventMessage<WebAppData>, update: Update -> message is PrivateEventMessage<WebAppData> && subcontextUpdatesFilter(message, update) } },
|
||||
markerFactory
|
||||
) {
|
||||
if (it is PrivateEventMessage<WebAppData>) {
|
||||
scenarioReceiver(it)
|
||||
}
|
||||
}
|
||||
) = 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 : BehaviourContext> BC.onForumTopicClosed(
|
||||
initialFilter: SimpleFilter<SupergroupEventMessage<ForumTopicClosed>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, SupergroupEventMessage<ForumTopicClosed>, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in ChatEventMessage<ForumTopicClosed>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, SupergroupEventMessage<ForumTopicClosed>>
|
||||
) = 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 : BehaviourContext> BC.onForumTopicCreated(
|
||||
initialFilter: SimpleFilter<SupergroupEventMessage<ForumTopicCreated>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, SupergroupEventMessage<ForumTopicCreated>, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in ChatEventMessage<ForumTopicCreated>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, SupergroupEventMessage<ForumTopicCreated>>
|
||||
) = 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 : BehaviourContext> BC.onForumTopicReopened(
|
||||
initialFilter: SimpleFilter<SupergroupEventMessage<ForumTopicReopened>>? = null,
|
||||
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, SupergroupEventMessage<ForumTopicReopened>, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in ChatEventMessage<ForumTopicReopened>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, SupergroupEventMessage<ForumTopicReopened>>
|
||||
) = onEventWithCustomChatEventMessage(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
Loading…
Reference in New Issue
Block a user