mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 08:13:47 +00:00
fix of #645
This commit is contained in:
parent
cb4c48d025
commit
ed2c447730
@ -7,6 +7,8 @@
|
|||||||
* `MicroUtils`: `0.18.1` -> `0.18.4`
|
* `MicroUtils`: `0.18.1` -> `0.18.4`
|
||||||
* `BehaviourBuilder`:
|
* `BehaviourBuilder`:
|
||||||
* Now it is possible to use `waitMediaContent`/`waitMediaContentMessage`/`onMediaContent`
|
* Now it is possible to use `waitMediaContent`/`waitMediaContentMessage`/`onMediaContent`
|
||||||
|
* Add `onMention`/`waitMention` functionality
|
||||||
|
* Add opportunity to map content with extensions to `Flow`
|
||||||
|
|
||||||
## 7.1.2
|
## 7.1.2
|
||||||
|
|
||||||
|
@ -10,121 +10,127 @@ import dev.inmo.tgbotapi.utils.RiskFeature
|
|||||||
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
|
import kotlinx.coroutines.flow.mapNotNull
|
||||||
|
|
||||||
typealias CommonMessageToContentMapper<T> = suspend CommonMessage<T>.() -> T?
|
typealias CommonMessageToContentMapper<T> = suspend CommonMessage<T>.() -> T?
|
||||||
|
|
||||||
@RiskFeature(lowLevelRiskFeatureMessage)
|
@RiskFeature(lowLevelRiskFeatureMessage)
|
||||||
suspend inline fun <reified O : MessageContent> BehaviourContext.waitContent(
|
suspend inline fun BehaviourContext.waitContent(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
): Flow<O> = waitContentMessage<O>(initRequest, errorFactory).map { it.content }
|
): Flow<MessageContent> = waitContentMessage(initRequest, errorFactory).map { it.content }
|
||||||
|
|
||||||
|
inline fun <reified T : MessageContent> Flow<MessageContent>.mapContent() = mapNotNull { it as? T }
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitAnyContent(
|
suspend fun BehaviourContext.waitAnyContent(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContent<MessageContent>(initRequest, errorFactory)
|
) = waitContent(initRequest, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitTextedContent(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitContent(initRequest, errorFactory).mapContent<TextedContent>()
|
||||||
suspend fun BehaviourContext.waitContact(
|
suspend fun BehaviourContext.waitContact(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContent<ContactContent>(initRequest, errorFactory)
|
) = waitContent(initRequest, errorFactory).mapContent<ContactContent>()
|
||||||
suspend fun BehaviourContext.waitDice(
|
suspend fun BehaviourContext.waitDice(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContent<DiceContent>(initRequest, errorFactory)
|
) = waitContent(initRequest, errorFactory).mapContent<DiceContent>()
|
||||||
suspend fun BehaviourContext.waitGame(
|
suspend fun BehaviourContext.waitGame(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContent<GameContent>(initRequest, errorFactory)
|
) = waitContent(initRequest, errorFactory).mapContent<GameContent>()
|
||||||
suspend fun BehaviourContext.waitLocation(
|
suspend fun BehaviourContext.waitLocation(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContent<LocationContent>(initRequest, errorFactory)
|
) = waitContent(initRequest, errorFactory).mapContent<LocationContent>()
|
||||||
suspend fun BehaviourContext.waitLiveLocation(
|
suspend fun BehaviourContext.waitLiveLocation(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContent<LiveLocationContent>(initRequest, errorFactory)
|
) = waitContent(initRequest, errorFactory).mapContent<LiveLocationContent>()
|
||||||
suspend fun BehaviourContext.waitStaticLocation(
|
suspend fun BehaviourContext.waitStaticLocation(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContent<StaticLocationContent>(initRequest, errorFactory)
|
) = waitContent(initRequest, errorFactory).mapContent<StaticLocationContent>()
|
||||||
suspend fun BehaviourContext.waitPoll(
|
suspend fun BehaviourContext.waitPoll(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContent<PollContent>(initRequest, errorFactory)
|
) = waitContent(initRequest, errorFactory).mapContent<PollContent>()
|
||||||
suspend fun BehaviourContext.waitText(
|
suspend fun BehaviourContext.waitText(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContent<TextContent>(initRequest, errorFactory)
|
) = waitContent(initRequest, errorFactory).mapContent<TextContent>()
|
||||||
suspend fun BehaviourContext.waitVenue(
|
suspend fun BehaviourContext.waitVenue(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContent<VenueContent>(initRequest, errorFactory)
|
) = waitContent(initRequest, errorFactory).mapContent<VenueContent>()
|
||||||
suspend fun BehaviourContext.waitAudioMediaGroupContent(
|
suspend fun BehaviourContext.waitAudioMediaGroupContent(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
) = waitContent<AudioMediaGroupPartContent>(initRequest, errorFactory)
|
) = waitContent(initRequest, errorFactory).mapContent<AudioMediaGroupPartContent>()
|
||||||
suspend fun BehaviourContext.waitDocumentMediaGroupContent(
|
suspend fun BehaviourContext.waitDocumentMediaGroupContent(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContent<DocumentMediaGroupPartContent>(initRequest, errorFactory)
|
) = waitContent(initRequest, errorFactory).mapContent<DocumentMediaGroupPartContent>()
|
||||||
suspend fun BehaviourContext.waitMedia(
|
suspend fun BehaviourContext.waitMedia(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContent<MediaContent>(initRequest, errorFactory)
|
) = waitContent(initRequest, errorFactory).mapContent<MediaContent>()
|
||||||
suspend fun BehaviourContext.waitAnyMediaGroupContent(
|
suspend fun BehaviourContext.waitAnyMediaGroupContent(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
) = waitContent<MediaGroupPartContent>(initRequest, errorFactory)
|
) = waitContent(initRequest, errorFactory).mapContent<MediaGroupPartContent>()
|
||||||
suspend fun BehaviourContext.waitVisualMediaGroupContent(
|
suspend fun BehaviourContext.waitVisualMediaGroupContent(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
) = waitContent<VisualMediaGroupPartContent>(initRequest, errorFactory)
|
) = waitContent(initRequest, errorFactory).mapContent<VisualMediaGroupPartContent>()
|
||||||
suspend fun BehaviourContext.waitTextedMediaContent(
|
suspend fun BehaviourContext.waitTextedMediaContent(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
) = waitContent<TextedMediaContent>(initRequest, errorFactory)
|
) = waitContent(initRequest, errorFactory).mapContent<TextedMediaContent>()
|
||||||
suspend fun BehaviourContext.waitAnimation(
|
suspend fun BehaviourContext.waitAnimation(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContent<AnimationContent>(initRequest, errorFactory)
|
) = waitContent(initRequest, errorFactory).mapContent<AnimationContent>()
|
||||||
suspend fun BehaviourContext.waitAudio(
|
suspend fun BehaviourContext.waitAudio(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
) = waitContent<AudioContent>(initRequest, errorFactory)
|
) = waitContent(initRequest, errorFactory).mapContent<AudioContent>()
|
||||||
suspend fun BehaviourContext.waitDocument(
|
suspend fun BehaviourContext.waitDocument(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
) = waitContent<DocumentContent>(initRequest, errorFactory)
|
) = waitContent(initRequest, errorFactory).mapContent<DocumentContent>()
|
||||||
suspend fun BehaviourContext.waitPhoto(
|
suspend fun BehaviourContext.waitPhoto(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
) = waitContent<PhotoContent>(initRequest, errorFactory)
|
) = waitContent(initRequest, errorFactory).mapContent<PhotoContent>()
|
||||||
suspend fun BehaviourContext.waitSticker(
|
suspend fun BehaviourContext.waitSticker(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContent<StickerContent>(initRequest, errorFactory)
|
) = waitContent(initRequest, errorFactory).mapContent<StickerContent>()
|
||||||
suspend fun BehaviourContext.waitVideo(
|
suspend fun BehaviourContext.waitVideo(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContent<VideoContent>(initRequest, errorFactory)
|
) = waitContent(initRequest, errorFactory).mapContent<VideoContent>()
|
||||||
suspend fun BehaviourContext.waitVideoNote(
|
suspend fun BehaviourContext.waitVideoNote(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContent<VideoNoteContent>(initRequest, errorFactory)
|
) = waitContent(initRequest, errorFactory).mapContent<VideoNoteContent>()
|
||||||
suspend fun BehaviourContext.waitVoice(
|
suspend fun BehaviourContext.waitVoice(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContent<VoiceContent>(initRequest, errorFactory)
|
) = waitContent(initRequest, errorFactory).mapContent<VoiceContent>()
|
||||||
suspend fun BehaviourContext.waitInvoice(
|
suspend fun BehaviourContext.waitInvoice(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContent<InvoiceContent>(initRequest, errorFactory)
|
) = waitContent(initRequest, errorFactory).mapContent<InvoiceContent>()
|
||||||
suspend fun BehaviourContext.waitVisualContent(
|
suspend fun BehaviourContext.waitVisualContent(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContent<VisualMediaGroupPartContent>(initRequest, errorFactory)
|
) = waitContent(initRequest, errorFactory).mapContent<VisualMediaGroupPartContent>()
|
||||||
suspend fun BehaviourContext.waitMediaContent(
|
suspend fun BehaviourContext.waitMediaContent(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContent<MediaContent>(initRequest, errorFactory)
|
) = waitContent(initRequest, errorFactory).mapContent<MediaContent>()
|
||||||
|
@ -5,6 +5,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
|||||||
import dev.inmo.micro_utils.coroutines.safelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.safelyWithoutExceptions
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||||
import dev.inmo.tgbotapi.extensions.utils.withContent
|
import dev.inmo.tgbotapi.extensions.utils.withContent
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.withContentOrNull
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
||||||
import dev.inmo.tgbotapi.types.message.content.*
|
import dev.inmo.tgbotapi.types.message.content.*
|
||||||
@ -12,147 +13,138 @@ import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate
|
|||||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
import dev.inmo.tgbotapi.utils.lowLevelRiskFeatureMessage
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.filter
|
||||||
|
import kotlinx.coroutines.flow.mapNotNull
|
||||||
|
|
||||||
typealias CommonMessageToCommonMessageMapper<T> = suspend CommonMessage<T>.() -> CommonMessage<T>?
|
typealias CommonMessageToCommonMessageMapper<T> = suspend CommonMessage<T>.() -> CommonMessage<T>?
|
||||||
|
|
||||||
@RiskFeature(lowLevelRiskFeatureMessage)
|
@RiskFeature(lowLevelRiskFeatureMessage)
|
||||||
suspend inline fun <reified O : MessageContent> BehaviourContext.waitContentMessage(
|
suspend inline fun BehaviourContext.waitContentMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
noinline errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
): Flow<CommonMessage<O>> = expectFlow(
|
): Flow<CommonMessage<MessageContent>> = expectFlow(
|
||||||
initRequest,
|
initRequest,
|
||||||
errorFactory
|
errorFactory
|
||||||
) {
|
) {
|
||||||
if (it !is BaseSentMessageUpdate) {
|
if (it !is BaseSentMessageUpdate) {
|
||||||
return@expectFlow emptyList()
|
return@expectFlow emptyList()
|
||||||
}
|
}
|
||||||
listOfNotNull((it.data as? CommonMessage<*>) ?.withContent<O>())
|
listOfNotNull((it.data as? CommonMessage<*>))
|
||||||
}
|
}
|
||||||
|
|
||||||
internal inline fun <reified T : MessageContent> contentMessageConverter(
|
inline fun <reified T : MessageContent> Flow<CommonMessage<MessageContent>>.mapWithContent() = mapNotNull { it.withContentOrNull<T>() }
|
||||||
noinline mapper: CommonMessageToCommonMessageMapper<T>? = null
|
|
||||||
): suspend CommonMessage<MessageContent>.() -> CommonMessage<T>? = mapper ?.let {
|
|
||||||
{
|
|
||||||
if (content is T) {
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
val message = (this as CommonMessage<T>)
|
|
||||||
safelyWithoutExceptions { mapper(message) }
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} ?: {
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
if (content is T) this as CommonMessage<T> else null
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitAnyContentMessage(
|
suspend fun BehaviourContext.waitAnyContentMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null },
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
) = waitContentMessage<MessageContent>(initRequest, errorFactory)
|
) = waitContentMessage(initRequest, errorFactory)
|
||||||
|
suspend fun BehaviourContext.waitTextedContentMessage(
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null },
|
||||||
|
) = waitContentMessage(initRequest, errorFactory).mapWithContent<TextedContent>()
|
||||||
suspend fun BehaviourContext.waitContactMessage(
|
suspend fun BehaviourContext.waitContactMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContentMessage<ContactContent>(initRequest, errorFactory)
|
) = waitContentMessage(initRequest, errorFactory).mapWithContent<ContactContent>()
|
||||||
suspend fun BehaviourContext.waitDiceMessage(
|
suspend fun BehaviourContext.waitDiceMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContentMessage<DiceContent>(initRequest, errorFactory)
|
) = waitContentMessage(initRequest, errorFactory).mapWithContent<DiceContent>()
|
||||||
suspend fun BehaviourContext.waitGameMessage(
|
suspend fun BehaviourContext.waitGameMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContentMessage<GameContent>(initRequest, errorFactory)
|
) = waitContentMessage(initRequest, errorFactory).mapWithContent<GameContent>()
|
||||||
suspend fun BehaviourContext.waitLocationMessage(
|
suspend fun BehaviourContext.waitLocationMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContentMessage<LocationContent>(initRequest, errorFactory)
|
) = waitContentMessage(initRequest, errorFactory).mapWithContent<LocationContent>()
|
||||||
suspend fun BehaviourContext.waitLiveLocationMessage(
|
suspend fun BehaviourContext.waitLiveLocationMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContentMessage<LiveLocationContent>(initRequest, errorFactory)
|
) = waitContentMessage(initRequest, errorFactory).mapWithContent<LiveLocationContent>()
|
||||||
suspend fun BehaviourContext.waitStaticLocationMessage(
|
suspend fun BehaviourContext.waitStaticLocationMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContentMessage<StaticLocationContent>(initRequest, errorFactory)
|
) = waitContentMessage(initRequest, errorFactory).mapWithContent<StaticLocationContent>()
|
||||||
suspend fun BehaviourContext.waitPollMessage(
|
suspend fun BehaviourContext.waitPollMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContentMessage<PollContent>(initRequest, errorFactory)
|
) = waitContentMessage(initRequest, errorFactory).mapWithContent<PollContent>()
|
||||||
suspend fun BehaviourContext.waitTextMessage(
|
suspend fun BehaviourContext.waitTextMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContentMessage<TextContent>(initRequest, errorFactory)
|
) = waitContentMessage(initRequest, errorFactory).mapWithContent<TextContent>()
|
||||||
suspend fun BehaviourContext.waitVenueMessage(
|
suspend fun BehaviourContext.waitVenueMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContentMessage<VenueContent>(initRequest, errorFactory)
|
) = waitContentMessage(initRequest, errorFactory).mapWithContent<VenueContent>()
|
||||||
suspend fun BehaviourContext.waitAudioMediaGroupContentMessage(
|
suspend fun BehaviourContext.waitAudioMediaGroupContentMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContentMessage<AudioMediaGroupPartContent>(initRequest, errorFactory)
|
) = waitContentMessage(initRequest, errorFactory).mapWithContent<AudioMediaGroupPartContent>()
|
||||||
suspend fun BehaviourContext.waitDocumentMediaGroupContentMessage(
|
suspend fun BehaviourContext.waitDocumentMediaGroupContentMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContentMessage<DocumentMediaGroupPartContent>(initRequest, errorFactory)
|
) = waitContentMessage(initRequest, errorFactory).mapWithContent<DocumentMediaGroupPartContent>()
|
||||||
suspend fun BehaviourContext.waitMediaMessage(
|
suspend fun BehaviourContext.waitMediaMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContentMessage<MediaContent>(initRequest, errorFactory)
|
) = waitContentMessage(initRequest, errorFactory).mapWithContent<MediaContent>()
|
||||||
suspend fun BehaviourContext.waitAnyMediaGroupContentMessage(
|
suspend fun BehaviourContext.waitAnyMediaGroupContentMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContentMessage<MediaGroupPartContent>(initRequest, errorFactory)
|
) = waitContentMessage(initRequest, errorFactory).mapWithContent<MediaGroupPartContent>()
|
||||||
suspend fun BehaviourContext.waitVisualMediaGroupContentMessage(
|
suspend fun BehaviourContext.waitVisualMediaGroupContentMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContentMessage<VisualMediaGroupPartContent>(initRequest, errorFactory)
|
) = waitContentMessage(initRequest, errorFactory).mapWithContent<VisualMediaGroupPartContent>()
|
||||||
suspend fun BehaviourContext.waitTextedMediaContentMessage(
|
suspend fun BehaviourContext.waitTextedMediaContentMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContentMessage<TextedMediaContent>(initRequest, errorFactory)
|
) = waitContentMessage(initRequest, errorFactory).mapWithContent<TextedMediaContent>()
|
||||||
suspend fun BehaviourContext.waitAnimationMessage(
|
suspend fun BehaviourContext.waitAnimationMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContentMessage<AnimationContent>(initRequest, errorFactory)
|
) = waitContentMessage(initRequest, errorFactory).mapWithContent<AnimationContent>()
|
||||||
suspend fun BehaviourContext.waitAudioMessage(
|
suspend fun BehaviourContext.waitAudioMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContentMessage<AudioContent>(initRequest, errorFactory)
|
) = waitContentMessage(initRequest, errorFactory).mapWithContent<AudioContent>()
|
||||||
suspend fun BehaviourContext.waitDocumentMessage(
|
suspend fun BehaviourContext.waitDocumentMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContentMessage<DocumentContent>(initRequest, errorFactory)
|
) = waitContentMessage(initRequest, errorFactory).mapWithContent<DocumentContent>()
|
||||||
suspend fun BehaviourContext.waitPhotoMessage(
|
suspend fun BehaviourContext.waitPhotoMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContentMessage<PhotoContent>(initRequest, errorFactory)
|
) = waitContentMessage(initRequest, errorFactory).mapWithContent<PhotoContent>()
|
||||||
suspend fun BehaviourContext.waitStickerMessage(
|
suspend fun BehaviourContext.waitStickerMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContentMessage<StickerContent>(initRequest, errorFactory)
|
) = waitContentMessage(initRequest, errorFactory).mapWithContent<StickerContent>()
|
||||||
suspend fun BehaviourContext.waitVideoMessage(
|
suspend fun BehaviourContext.waitVideoMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContentMessage<VideoContent>(initRequest, errorFactory)
|
) = waitContentMessage(initRequest, errorFactory).mapWithContent<VideoContent>()
|
||||||
suspend fun BehaviourContext.waitVideoNoteMessage(
|
suspend fun BehaviourContext.waitVideoNoteMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContentMessage<VideoNoteContent>(initRequest, errorFactory)
|
) = waitContentMessage(initRequest, errorFactory).mapWithContent<VideoNoteContent>()
|
||||||
suspend fun BehaviourContext.waitVoiceMessage(
|
suspend fun BehaviourContext.waitVoiceMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContentMessage<VoiceContent>(initRequest, errorFactory)
|
) = waitContentMessage(initRequest, errorFactory).mapWithContent<VoiceContent>()
|
||||||
suspend fun BehaviourContext.waitInvoiceMessage(
|
suspend fun BehaviourContext.waitInvoiceMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContentMessage<InvoiceContent>(initRequest, errorFactory)
|
) = waitContentMessage(initRequest, errorFactory).mapWithContent<InvoiceContent>()
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitVisualContentMessage(
|
suspend fun BehaviourContext.waitVisualContentMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContentMessage<VisualMediaGroupPartContent>(initRequest, errorFactory)
|
) = waitContentMessage(initRequest, errorFactory).mapWithContent<VisualMediaGroupPartContent>()
|
||||||
|
|
||||||
suspend fun BehaviourContext.waitMediaContentMessage(
|
suspend fun BehaviourContext.waitMediaContentMessage(
|
||||||
initRequest: Request<*>? = null,
|
initRequest: Request<*>? = null,
|
||||||
errorFactory: NullableRequestBuilder<*> = { null }
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
) = waitContentMessage<MediaContent>(initRequest, errorFactory)
|
) = waitContentMessage(initRequest, errorFactory).mapWithContent<MediaContent>()
|
||||||
|
@ -0,0 +1,107 @@
|
|||||||
|
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.whenMentionTextSource
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.whenTextMentionTextSource
|
||||||
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
|
import dev.inmo.tgbotapi.types.UserId
|
||||||
|
import dev.inmo.tgbotapi.types.Username
|
||||||
|
import dev.inmo.tgbotapi.types.chat.User
|
||||||
|
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.MessageContent
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.TextedContent
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.filter
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check, that [TextedContent.textSources] contains:
|
||||||
|
*
|
||||||
|
* * Any [dev.inmo.tgbotapi.types.message.textsources.MentionTextSource] with [dev.inmo.tgbotapi.types.message.textsources.MentionTextSource.username]
|
||||||
|
* equal to [username]
|
||||||
|
* * Any [dev.inmo.tgbotapi.types.message.textsources.TextMentionTextSource] with [dev.inmo.tgbotapi.types.message.textsources.TextMentionTextSource.user]
|
||||||
|
* with the same [username]
|
||||||
|
*/
|
||||||
|
fun TextedContent.isWithMention(username: Username) = textSources.any {
|
||||||
|
it.whenMentionTextSource {
|
||||||
|
it.username == username
|
||||||
|
} ?: it.whenTextMentionTextSource {
|
||||||
|
it.user.username == username
|
||||||
|
} ?: false
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check, that [TextedContent.textSources] contains:
|
||||||
|
*
|
||||||
|
* * Any [dev.inmo.tgbotapi.types.message.textsources.TextMentionTextSource] with [dev.inmo.tgbotapi.types.message.textsources.TextMentionTextSource.user]
|
||||||
|
* with the same [userId]
|
||||||
|
*/
|
||||||
|
fun TextedContent.isWithTextMention(userId: UserId) = textSources.any {
|
||||||
|
it.whenTextMentionTextSource {
|
||||||
|
it.user.id == userId
|
||||||
|
} ?: false
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses [isWithMention] with [user] [Username] (is presented) or [isWithTextMention] with [user] [UserId] to determine
|
||||||
|
* user mentioning in [this] [CommonMessage]
|
||||||
|
*/
|
||||||
|
fun TextedContent.isWithMention(user: User): Boolean = user.username ?.let { username -> isWithMention(username) } == true || isWithTextMention(user.id)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses [isWithMention] passing [username] as argument to take only messages with [username] mentions or text mentions
|
||||||
|
*/
|
||||||
|
fun Flow<TextedContent>.filterMentions(username: Username) = filter {
|
||||||
|
it.isWithMention(username)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses [isWithTextMention] passing [userId] as argument to take only messages with [userId] text mentions
|
||||||
|
*/
|
||||||
|
fun Flow<TextedContent>.filterTextMentions(userId: UserId) = filter {
|
||||||
|
it.isWithTextMention(userId)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses [isWithMention] passing [user] as argument to take only messages with [user] mentions or text mentions
|
||||||
|
*/
|
||||||
|
fun Flow<TextedContent>.filterMentions(user: User) = filter {
|
||||||
|
it.isWithMention(user)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates cold [Flow] with the messages with [TextedContent] where [username] has been mentioned
|
||||||
|
*
|
||||||
|
* @see filterMentions
|
||||||
|
* @see filterTextMentions
|
||||||
|
*/
|
||||||
|
suspend fun BehaviourContext.waitContentWithMentions (
|
||||||
|
username: Username,
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitContent(initRequest, errorFactory).mapContent<TextedContent>().filterMentions(username)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates cold [Flow] with the messages with [TextedContent] where [userId] has been mentioned with text
|
||||||
|
*
|
||||||
|
* @see filterTextMentions
|
||||||
|
* @see filterMentions
|
||||||
|
* @see dev.inmo.tgbotapi.types.message.textsources.TextMentionTextSource
|
||||||
|
*/
|
||||||
|
suspend fun BehaviourContext.waitContentWithTextMentions (
|
||||||
|
userId: UserId,
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitTextedContent(initRequest, errorFactory).filterTextMentions(userId)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates cold [Flow] with the messages with [TextedContent] where [user] has been mentioned as text or mentioned
|
||||||
|
* with text
|
||||||
|
*
|
||||||
|
* @see filterMentions
|
||||||
|
* @see filterTextMentions
|
||||||
|
*/
|
||||||
|
suspend fun BehaviourContext.waitContentWithMentions (
|
||||||
|
user: User,
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitTextedContent(initRequest, errorFactory).filterMentions(user)
|
@ -0,0 +1,82 @@
|
|||||||
|
package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.whenMentionTextSource
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.whenTextMentionTextSource
|
||||||
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
|
import dev.inmo.tgbotapi.types.UserId
|
||||||
|
import dev.inmo.tgbotapi.types.Username
|
||||||
|
import dev.inmo.tgbotapi.types.chat.User
|
||||||
|
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.TextedContent
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.filter
|
||||||
|
|
||||||
|
fun CommonMessage<TextedContent>.isWithMention(username: Username) = content.isWithMention(username)
|
||||||
|
|
||||||
|
fun CommonMessage<TextedContent>.isWithTextMention(userId: UserId) = content.isWithTextMention(userId)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses [isWithMention] with [user] [Username] (is presented) or [isWithTextMention] with [user] [UserId] to determine
|
||||||
|
* user mentioning in [this] [CommonMessage]
|
||||||
|
*/
|
||||||
|
fun CommonMessage<TextedContent>.isWithMention(user: User): Boolean = content.isWithMention(user)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses [isWithMention] passing [username] as argument to take only messages with [username] mentions or text mentions
|
||||||
|
*/
|
||||||
|
fun Flow<CommonMessage<TextedContent>>.filterMentionsMessages(username: Username) = filter {
|
||||||
|
it.isWithMention(username)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses [isWithTextMention] passing [userId] as argument to take only messages with [userId] text mentions
|
||||||
|
*/
|
||||||
|
fun Flow<CommonMessage<TextedContent>>.filterTextMentionsMessages(userId: UserId) = filter {
|
||||||
|
it.isWithTextMention(userId)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses [isWithMention] passing [user] as argument to take only messages with [user] mentions or text mentions
|
||||||
|
*/
|
||||||
|
fun Flow<CommonMessage<TextedContent>>.filterMentionsMessages(user: User) = filter {
|
||||||
|
it.isWithMention(user)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates cold [Flow] with the messages with [TextedContent] where [username] has been mentioned
|
||||||
|
*
|
||||||
|
* @see filterMentions
|
||||||
|
* @see filterTextMentions
|
||||||
|
*/
|
||||||
|
suspend fun BehaviourContext.waitContentMessageWithMentions (
|
||||||
|
username: Username,
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitContentMessage(initRequest, errorFactory).mapWithContent<TextedContent>().filterMentionsMessages(username)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates cold [Flow] with the messages with [TextedContent] where [userId] has been mentioned with text
|
||||||
|
*
|
||||||
|
* @see filterTextMentions
|
||||||
|
* @see filterMentions
|
||||||
|
* @see dev.inmo.tgbotapi.types.message.textsources.TextMentionTextSource
|
||||||
|
*/
|
||||||
|
suspend fun BehaviourContext.waitContentMessageWithTextMentions (
|
||||||
|
userId: UserId,
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitTextedContentMessage(initRequest, errorFactory).filterTextMentionsMessages(userId)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates cold [Flow] with the messages with [TextedContent] where [user] has been mentioned as text or mentioned
|
||||||
|
* with text
|
||||||
|
*
|
||||||
|
* @see filterMentions
|
||||||
|
* @see filterTextMentions
|
||||||
|
*/
|
||||||
|
suspend fun BehaviourContext.waitContentMessageWithMentions (
|
||||||
|
user: User,
|
||||||
|
initRequest: Request<*>? = null,
|
||||||
|
errorFactory: NullableRequestBuilder<*> = { null }
|
||||||
|
) = waitTextedContentMessage(initRequest, errorFactory).filterMentionsMessages(user)
|
@ -248,6 +248,30 @@ suspend fun <BC : BehaviourContext> BC.onText(
|
|||||||
scenarioReceiver
|
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.onTextedContent(
|
||||||
|
initialFilter: CommonMessageFilter<TextedContent>? = null,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, TextedMessage, Update> = MessageFilterByChat,
|
||||||
|
markerFactory: MarkerFactory<in TextedMessage, Any> = ByChatMessageMarkerFactory,
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, TextedMessage>
|
||||||
|
) = onContentMessageWithType(
|
||||||
|
initialFilter,
|
||||||
|
subcontextUpdatesFilter,
|
||||||
|
markerFactory,
|
||||||
|
scenarioReceiver
|
||||||
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
|
* @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,
|
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
|
||||||
|
@ -0,0 +1,357 @@
|
|||||||
|
package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.CustomBehaviourContextAndTwoTypesReceiver
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.CustomBehaviourContextAndTypeReceiver
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.isWithMention
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.isWithTextMention
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.AnyMarkerFactory
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
||||||
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times
|
||||||
|
import dev.inmo.tgbotapi.types.UserId
|
||||||
|
import dev.inmo.tgbotapi.types.Username
|
||||||
|
import dev.inmo.tgbotapi.types.chat.User
|
||||||
|
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.AnimationContent
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.AudioContent
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.DocumentContent
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.MediaGroupContent
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.MediaGroupPartContent
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.PhotoContent
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.TextContent
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.TextedContent
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.VideoContent
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.VisualMediaGroupPartContent
|
||||||
|
import dev.inmo.tgbotapi.types.message.content.VoiceContent
|
||||||
|
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||||
|
|
||||||
|
internal suspend inline fun <BC : BehaviourContext, reified T : TextedContent> BC.onMention(
|
||||||
|
username: Username,
|
||||||
|
initialFilter: CommonMessageFilter<T>? = null,
|
||||||
|
noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<T>, Update>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<T>, Any> = AnyMarkerFactory(),
|
||||||
|
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<T>>
|
||||||
|
) = onContentMessageWithType<BC, T>(
|
||||||
|
initialFilter * {
|
||||||
|
it.content.isWithMention(username)
|
||||||
|
},
|
||||||
|
subcontextUpdatesFilter,
|
||||||
|
markerFactory,
|
||||||
|
scenarioReceiver
|
||||||
|
)
|
||||||
|
|
||||||
|
internal suspend inline fun <BC : BehaviourContext, reified T : TextedContent> BC.onTextMention(
|
||||||
|
userId: UserId,
|
||||||
|
initialFilter: CommonMessageFilter<T>? = null,
|
||||||
|
noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<T>, Update>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<T>, Any> = AnyMarkerFactory(),
|
||||||
|
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<T>>
|
||||||
|
) = onContentMessageWithType<BC, T>(
|
||||||
|
initialFilter * {
|
||||||
|
it.content.isWithTextMention(userId)
|
||||||
|
},
|
||||||
|
subcontextUpdatesFilter,
|
||||||
|
markerFactory,
|
||||||
|
scenarioReceiver
|
||||||
|
)
|
||||||
|
|
||||||
|
internal suspend inline fun <BC : BehaviourContext, reified T : TextedContent> BC.onMention(
|
||||||
|
user: User,
|
||||||
|
initialFilter: CommonMessageFilter<T>? = null,
|
||||||
|
noinline subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<T>, Update>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<T>, Any> = AnyMarkerFactory(),
|
||||||
|
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<T>>
|
||||||
|
) = onContentMessageWithType<BC, T>(
|
||||||
|
initialFilter * {
|
||||||
|
it.content.isWithMention(user)
|
||||||
|
},
|
||||||
|
subcontextUpdatesFilter,
|
||||||
|
markerFactory,
|
||||||
|
scenarioReceiver
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onMentionWithAnyContent(
|
||||||
|
username: Username,
|
||||||
|
initialFilter: CommonMessageFilter<TextedContent>? = null,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<TextedContent>, Update>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<TextedContent>, Any> = AnyMarkerFactory(),
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<TextedContent>>
|
||||||
|
) = onMention(username, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onTextMentionWithAnyContent(
|
||||||
|
userId: UserId,
|
||||||
|
initialFilter: CommonMessageFilter<TextedContent>? = null,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<TextedContent>, Update>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<TextedContent>, Any> = AnyMarkerFactory(),
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<TextedContent>>
|
||||||
|
) = onTextMention(userId, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onMentionWithAnyContent(
|
||||||
|
user: User,
|
||||||
|
initialFilter: CommonMessageFilter<TextedContent>? = null,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<TextedContent>, Update>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<TextedContent>, Any> = AnyMarkerFactory(),
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<TextedContent>>
|
||||||
|
) = onMention(user, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onMentionWithVoiceContent(
|
||||||
|
username: Username,
|
||||||
|
initialFilter: CommonMessageFilter<VoiceContent>? = null,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<VoiceContent>, Update>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<VoiceContent>, Any> = AnyMarkerFactory(),
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<VoiceContent>>
|
||||||
|
) = onMention(username, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onTextMentionWithVoiceContent(
|
||||||
|
userId: UserId,
|
||||||
|
initialFilter: CommonMessageFilter<VoiceContent>? = null,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<VoiceContent>, Update>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<VoiceContent>, Any> = AnyMarkerFactory(),
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<VoiceContent>>
|
||||||
|
) = onTextMention(userId, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onMentionWithVoiceContent(
|
||||||
|
user: User,
|
||||||
|
initialFilter: CommonMessageFilter<VoiceContent>? = null,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<VoiceContent>, Update>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<VoiceContent>, Any> = AnyMarkerFactory(),
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<VoiceContent>>
|
||||||
|
) = onMention(user, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onMentionWithMediaGroupContent(
|
||||||
|
username: Username,
|
||||||
|
initialFilter: CommonMessageFilter<MediaGroupContent<MediaGroupPartContent>>? = null,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<MediaGroupContent<MediaGroupPartContent>>, Update>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<MediaGroupPartContent>, Any> = AnyMarkerFactory(),
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<MediaGroupContent<MediaGroupPartContent>>>
|
||||||
|
) = onMention(username, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onTextMentionWithMediaGroupContent(
|
||||||
|
userId: UserId,
|
||||||
|
initialFilter: CommonMessageFilter<MediaGroupContent<MediaGroupPartContent>>? = null,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<MediaGroupContent<MediaGroupPartContent>>, Update>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<MediaGroupContent<MediaGroupPartContent>>, Any> = AnyMarkerFactory(),
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<MediaGroupContent<MediaGroupPartContent>>>
|
||||||
|
) = onTextMention(userId, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onMentionWithMediaGroupContent(
|
||||||
|
user: User,
|
||||||
|
initialFilter: CommonMessageFilter<MediaGroupContent<MediaGroupPartContent>>? = null,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<MediaGroupContent<MediaGroupPartContent>>, Update>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<MediaGroupContent<MediaGroupPartContent>>, Any> = AnyMarkerFactory(),
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<MediaGroupContent<MediaGroupPartContent>>>
|
||||||
|
) = onMention(user, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onMentionWithMediaGroupPartContent(
|
||||||
|
username: Username,
|
||||||
|
initialFilter: CommonMessageFilter<MediaGroupPartContent>? = null,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<MediaGroupPartContent>, Update>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<MediaGroupPartContent>, Any> = AnyMarkerFactory(),
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<MediaGroupPartContent>>
|
||||||
|
) = onMention(username, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onTextMentionWithMediaGroupPartContent(
|
||||||
|
userId: UserId,
|
||||||
|
initialFilter: CommonMessageFilter<MediaGroupPartContent>? = null,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<MediaGroupPartContent>, Update>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<MediaGroupPartContent>, Any> = AnyMarkerFactory(),
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<MediaGroupPartContent>>
|
||||||
|
) = onTextMention(userId, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onMentionWithMediaGroupPartContent(
|
||||||
|
user: User,
|
||||||
|
initialFilter: CommonMessageFilter<MediaGroupPartContent>? = null,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<MediaGroupPartContent>, Update>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<MediaGroupPartContent>, Any> = AnyMarkerFactory(),
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<MediaGroupPartContent>>
|
||||||
|
) = onMention(user, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onMentionWithAudioContent(
|
||||||
|
username: Username,
|
||||||
|
initialFilter: CommonMessageFilter<AudioContent>? = null,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<AudioContent>, Update>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<AudioContent>, Any> = AnyMarkerFactory(),
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<AudioContent>>
|
||||||
|
) = onMention(username, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onTextMentionWithAudioContent(
|
||||||
|
userId: UserId,
|
||||||
|
initialFilter: CommonMessageFilter<AudioContent>? = null,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<AudioContent>, Update>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<AudioContent>, Any> = AnyMarkerFactory(),
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<AudioContent>>
|
||||||
|
) = onTextMention(userId, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onMentionWithAudioContent(
|
||||||
|
user: User,
|
||||||
|
initialFilter: CommonMessageFilter<AudioContent>? = null,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<AudioContent>, Update>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<AudioContent>, Any> = AnyMarkerFactory(),
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<AudioContent>>
|
||||||
|
) = onMention(user, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onMentionWithDocumentContent(
|
||||||
|
username: Username,
|
||||||
|
initialFilter: CommonMessageFilter<DocumentContent>? = null,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<DocumentContent>, Update>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<DocumentContent>, Any> = AnyMarkerFactory(),
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<DocumentContent>>
|
||||||
|
) = onMention(username, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onTextMentionWithDocumentContent(
|
||||||
|
userId: UserId,
|
||||||
|
initialFilter: CommonMessageFilter<DocumentContent>? = null,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<DocumentContent>, Update>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<DocumentContent>, Any> = AnyMarkerFactory(),
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<DocumentContent>>
|
||||||
|
) = onTextMention(userId, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onMentionWithDocumentContent(
|
||||||
|
user: User,
|
||||||
|
initialFilter: CommonMessageFilter<DocumentContent>? = null,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<DocumentContent>, Update>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<DocumentContent>, Any> = AnyMarkerFactory(),
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<DocumentContent>>
|
||||||
|
) = onMention(user, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onMentionWithVisualMediaGroupPartContent(
|
||||||
|
username: Username,
|
||||||
|
initialFilter: CommonMessageFilter<VisualMediaGroupPartContent>? = null,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<VisualMediaGroupPartContent>, Update>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<VisualMediaGroupPartContent>, Any> = AnyMarkerFactory(),
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<VisualMediaGroupPartContent>>
|
||||||
|
) = onMention(username, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onTextMentionWithVisualMediaGroupPartContent(
|
||||||
|
userId: UserId,
|
||||||
|
initialFilter: CommonMessageFilter<VisualMediaGroupPartContent>? = null,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<VisualMediaGroupPartContent>, Update>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<VisualMediaGroupPartContent>, Any> = AnyMarkerFactory(),
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<VisualMediaGroupPartContent>>
|
||||||
|
) = onTextMention(userId, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onMentionWithVisualMediaGroupPartContent(
|
||||||
|
user: User,
|
||||||
|
initialFilter: CommonMessageFilter<VisualMediaGroupPartContent>? = null,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<VisualMediaGroupPartContent>, Update>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<VisualMediaGroupPartContent>, Any> = AnyMarkerFactory(),
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<VisualMediaGroupPartContent>>
|
||||||
|
) = onMention(user, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onMentionWithVideoContent(
|
||||||
|
username: Username,
|
||||||
|
initialFilter: CommonMessageFilter<VideoContent>? = null,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<VideoContent>, Update>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<VideoContent>, Any> = AnyMarkerFactory(),
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<VideoContent>>
|
||||||
|
) = onMention(username, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onTextMentionWithVideoContent(
|
||||||
|
userId: UserId,
|
||||||
|
initialFilter: CommonMessageFilter<VideoContent>? = null,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<VideoContent>, Update>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<VideoContent>, Any> = AnyMarkerFactory(),
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<VideoContent>>
|
||||||
|
) = onTextMention(userId, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onMentionWithVideoContent(
|
||||||
|
user: User,
|
||||||
|
initialFilter: CommonMessageFilter<VideoContent>? = null,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<VideoContent>, Update>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<VideoContent>, Any> = AnyMarkerFactory(),
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<VideoContent>>
|
||||||
|
) = onMention(user, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onMentionWithPhotoContent(
|
||||||
|
username: Username,
|
||||||
|
initialFilter: CommonMessageFilter<PhotoContent>? = null,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<PhotoContent>, Update>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<PhotoContent>, Any> = AnyMarkerFactory(),
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<PhotoContent>>
|
||||||
|
) = onMention(username, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onTextMentionWithPhotoContent(
|
||||||
|
userId: UserId,
|
||||||
|
initialFilter: CommonMessageFilter<PhotoContent>? = null,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<PhotoContent>, Update>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<PhotoContent>, Any> = AnyMarkerFactory(),
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<PhotoContent>>
|
||||||
|
) = onTextMention(userId, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onMentionWithPhotoContent(
|
||||||
|
user: User,
|
||||||
|
initialFilter: CommonMessageFilter<PhotoContent>? = null,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<PhotoContent>, Update>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<PhotoContent>, Any> = AnyMarkerFactory(),
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<PhotoContent>>
|
||||||
|
) = onMention(user, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onMentionWithAnimationContent(
|
||||||
|
username: Username,
|
||||||
|
initialFilter: CommonMessageFilter<AnimationContent>? = null,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<AnimationContent>, Update>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<AnimationContent>, Any> = AnyMarkerFactory(),
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<AnimationContent>>
|
||||||
|
) = onMention(username, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onTextMentionWithAnimationContent(
|
||||||
|
userId: UserId,
|
||||||
|
initialFilter: CommonMessageFilter<AnimationContent>? = null,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<AnimationContent>, Update>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<AnimationContent>, Any> = AnyMarkerFactory(),
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<AnimationContent>>
|
||||||
|
) = onTextMention(userId, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onMentionWithAnimationContent(
|
||||||
|
user: User,
|
||||||
|
initialFilter: CommonMessageFilter<AnimationContent>? = null,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<AnimationContent>, Update>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<AnimationContent>, Any> = AnyMarkerFactory(),
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<AnimationContent>>
|
||||||
|
) = onMention(user, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onMentionWithTextContent(
|
||||||
|
username: Username,
|
||||||
|
initialFilter: CommonMessageFilter<TextContent>? = null,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<TextContent>, Update>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<TextContent>, Any> = AnyMarkerFactory(),
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<TextContent>>
|
||||||
|
) = onMention(username, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onTextMentionWithTextContent(
|
||||||
|
userId: UserId,
|
||||||
|
initialFilter: CommonMessageFilter<TextContent>? = null,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<TextContent>, Update>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<TextContent>, Any> = AnyMarkerFactory(),
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<TextContent>>
|
||||||
|
) = onTextMention(userId, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
||||||
|
suspend fun <BC : BehaviourContext> BC.onMentionWithTextContent(
|
||||||
|
user: User,
|
||||||
|
initialFilter: CommonMessageFilter<TextContent>? = null,
|
||||||
|
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, CommonMessage<TextContent>, Update>? = null,
|
||||||
|
markerFactory: MarkerFactory<in CommonMessage<TextContent>, Any> = AnyMarkerFactory(),
|
||||||
|
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, CommonMessage<TextContent>>
|
||||||
|
) = onMention(user, initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||||
|
|
@ -1,6 +1,7 @@
|
|||||||
package dev.inmo.tgbotapi.types.message.content
|
package dev.inmo.tgbotapi.types.message.content
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.abstracts.SpoilerableData
|
import dev.inmo.tgbotapi.abstracts.SpoilerableData
|
||||||
|
import dev.inmo.tgbotapi.abstracts.TextedInput
|
||||||
import dev.inmo.tgbotapi.utils.internal.ClassCastsIncluded
|
import dev.inmo.tgbotapi.utils.internal.ClassCastsIncluded
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.types.ChatIdentifier
|
import dev.inmo.tgbotapi.types.ChatIdentifier
|
||||||
@ -51,6 +52,18 @@ sealed interface MessageContent: ResendableContent {
|
|||||||
|
|
||||||
additionalBuilder()
|
additionalBuilder()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
polymorphic(TextedContent::class) {
|
||||||
|
subclass(TextContent::class)
|
||||||
|
subclass(VoiceContent::class)
|
||||||
|
subclass(MediaGroupContent::class)
|
||||||
|
subclass(AudioContent::class)
|
||||||
|
subclass(DocumentContent::class)
|
||||||
|
subclass(VideoContent::class)
|
||||||
|
subclass(PhotoContent::class)
|
||||||
|
subclass(AnimationContent::class)
|
||||||
|
}
|
||||||
|
|
||||||
polymorphic(MediaCollectionContent::class) {
|
polymorphic(MediaCollectionContent::class) {
|
||||||
subclass(PhotoContent::class)
|
subclass(PhotoContent::class)
|
||||||
|
|
||||||
@ -115,6 +128,11 @@ sealed interface MediaCollectionContent<T: TelegramMediaFile>: MessageContent, M
|
|||||||
val mediaCollection: List<T>
|
val mediaCollection: List<T>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All the subtypes of this content will have [text] and [textSources] fields
|
||||||
|
*/
|
||||||
|
sealed interface TextedContent : MessageContent, TextedInput
|
||||||
|
|
||||||
sealed interface MediaContent: MessageContent {
|
sealed interface MediaContent: MessageContent {
|
||||||
val media: TelegramMediaFile
|
val media: TelegramMediaFile
|
||||||
fun asTelegramMedia(): TelegramMedia
|
fun asTelegramMedia(): TelegramMedia
|
||||||
|
@ -22,7 +22,7 @@ sealed interface DocumentMediaGroupPartContent : MediaGroupPartContent {
|
|||||||
override fun toMediaGroupMemberTelegramMedia(): DocumentMediaGroupMemberTelegramMedia
|
override fun toMediaGroupMemberTelegramMedia(): DocumentMediaGroupMemberTelegramMedia
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed interface TextedMediaContent : MediaContent, TextedInput
|
sealed interface TextedMediaContent : TextedContent, MediaContent
|
||||||
|
|
||||||
sealed interface MediaGroupCollectionContent<T : MediaGroupPartContent> : TextedMediaContent {
|
sealed interface MediaGroupCollectionContent<T : MediaGroupPartContent> : TextedMediaContent {
|
||||||
@Serializable
|
@Serializable
|
||||||
|
@ -15,7 +15,7 @@ import kotlinx.serialization.Serializable
|
|||||||
data class TextContent(
|
data class TextContent(
|
||||||
override val text: String,
|
override val text: String,
|
||||||
override val textSources: TextSourcesList = emptyList(),
|
override val textSources: TextSourcesList = emptyList(),
|
||||||
) : MessageContent, TextedInput {
|
) : TextedContent {
|
||||||
override fun createResend(
|
override fun createResend(
|
||||||
chatId: ChatIdentifier,
|
chatId: ChatIdentifier,
|
||||||
messageThreadId: MessageThreadId?,
|
messageThreadId: MessageThreadId?,
|
||||||
|
@ -2,6 +2,8 @@ package dev.inmo.tgbotapi.types.message.content
|
|||||||
|
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.CommonMessage
|
||||||
|
|
||||||
|
typealias TextedMessage = CommonMessage<TextedContent>
|
||||||
|
|
||||||
typealias InvoiceMessage = CommonMessage<InvoiceContent>
|
typealias InvoiceMessage = CommonMessage<InvoiceContent>
|
||||||
typealias VenueMessage = CommonMessage<VenueContent>
|
typealias VenueMessage = CommonMessage<VenueContent>
|
||||||
typealias GameMessage = CommonMessage<GameContent>
|
typealias GameMessage = CommonMessage<GameContent>
|
||||||
|
Loading…
Reference in New Issue
Block a user