mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-22 16:47:13 +00:00
SuccessfulPaymentEvent
This commit is contained in:
parent
702c1bc1ff
commit
e51a4b7702
@ -13,6 +13,8 @@
|
||||
* `PayInlineKeyboardButton#pay` now is deprecated
|
||||
* `RowBuilder` and `MatrixBuilder` now are open and available for extending
|
||||
* `MatrixBuilder#matrix` will return read-only new list instead of original internal `mutMatrix`
|
||||
* Introduced new type of events `SuccessfulPaymentEvent` instead of putting of payment inside of message
|
||||
* New type of events union: `CommonGroupEvent`
|
||||
* `Utils`:
|
||||
* Two new dsl:
|
||||
* `inlineKeyboard` for creating `InlineKeyboardMarkup`
|
||||
|
@ -1,5 +1,5 @@
|
||||
package dev.inmo.tgbotapi.types.message.ChatEvents
|
||||
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.CommonEvent
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.CommonGroupEvent
|
||||
|
||||
class DeleteChatPhoto: CommonEvent
|
||||
class DeleteChatPhoto: CommonGroupEvent
|
||||
|
@ -1,8 +1,8 @@
|
||||
package dev.inmo.tgbotapi.types.message.ChatEvents
|
||||
|
||||
import dev.inmo.tgbotapi.types.User
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.CommonEvent
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.CommonGroupEvent
|
||||
|
||||
data class LeftChatMember(
|
||||
val user: User
|
||||
) : CommonEvent
|
||||
) : CommonGroupEvent
|
||||
|
@ -1,8 +1,8 @@
|
||||
package dev.inmo.tgbotapi.types.message.ChatEvents
|
||||
|
||||
import dev.inmo.tgbotapi.types.files.Photo
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.CommonEvent
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.CommonGroupEvent
|
||||
|
||||
data class NewChatPhoto(
|
||||
val photo: Photo
|
||||
): CommonEvent
|
||||
): CommonGroupEvent
|
||||
|
@ -1,7 +1,7 @@
|
||||
package dev.inmo.tgbotapi.types.message.ChatEvents
|
||||
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.CommonEvent
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.CommonGroupEvent
|
||||
|
||||
data class NewChatTitle(
|
||||
val title: String
|
||||
): CommonEvent
|
||||
): CommonGroupEvent
|
||||
|
@ -2,7 +2,7 @@ package dev.inmo.tgbotapi.types.message.ChatEvents
|
||||
|
||||
import dev.inmo.tgbotapi.types.Meters
|
||||
import dev.inmo.tgbotapi.types.User
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.CommonEvent
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.CommonGroupEvent
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
/**
|
||||
@ -14,4 +14,4 @@ data class ProximityAlertTriggered(
|
||||
val traveler: User,
|
||||
val watcher: User,
|
||||
val distance: Meters
|
||||
) : CommonEvent
|
||||
) : CommonGroupEvent
|
||||
|
@ -1,3 +1,3 @@
|
||||
package dev.inmo.tgbotapi.types.message.ChatEvents.abstracts
|
||||
|
||||
interface CommonEvent : ChannelEvent, GroupEvent, SupergroupEvent
|
||||
interface CommonEvent : CommonGroupEvent, PrivateEvent
|
||||
|
@ -0,0 +1,3 @@
|
||||
package dev.inmo.tgbotapi.types.message.ChatEvents.abstracts
|
||||
|
||||
interface CommonGroupEvent : ChannelEvent, GroupEvent, SupergroupEvent
|
@ -0,0 +1,3 @@
|
||||
package dev.inmo.tgbotapi.types.message.ChatEvents.abstracts
|
||||
|
||||
interface PrivateEvent : ChatEvent
|
@ -1,3 +1,3 @@
|
||||
package dev.inmo.tgbotapi.types.message.ChatEvents.abstracts
|
||||
|
||||
interface VoiceChatEvent : CommonEvent
|
||||
interface VoiceChatEvent : CommonGroupEvent
|
||||
|
@ -0,0 +1,15 @@
|
||||
package dev.inmo.tgbotapi.types.message
|
||||
|
||||
import com.soywiz.klock.DateTime
|
||||
import dev.inmo.tgbotapi.types.MessageIdentifier
|
||||
import dev.inmo.tgbotapi.types.chat.abstracts.ChannelChat
|
||||
import dev.inmo.tgbotapi.types.chat.abstracts.PrivateChat
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.PrivateEvent
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage
|
||||
|
||||
data class PrivateEventMessage<T : PrivateEvent>(
|
||||
override val messageId: MessageIdentifier,
|
||||
override val chat: PrivateChat,
|
||||
override val chatEvent: T,
|
||||
override val date: DateTime
|
||||
) : ChatEventMessage<T>
|
@ -7,7 +7,7 @@ import dev.inmo.tgbotapi.types.chat.abstracts.Chat
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.PrivateContentMessage
|
||||
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
||||
import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentInfo
|
||||
import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentEvent
|
||||
|
||||
data class PrivateContentMessageImpl<T: MessageContent>(
|
||||
override val messageId: MessageIdentifier,
|
||||
@ -20,5 +20,7 @@ data class PrivateContentMessageImpl<T: MessageContent>(
|
||||
override val replyTo: Message?,
|
||||
override val replyMarkup: InlineKeyboardMarkup?,
|
||||
override val senderBot: CommonBot?,
|
||||
val paymentInfo: SuccessfulPaymentInfo?
|
||||
) : PrivateContentMessage<T>
|
||||
) : PrivateContentMessage<T> {
|
||||
@Deprecated("This value will always be null. You may get SuccessfulPayment as one of ChatEvents")
|
||||
val paymentInfo: SuccessfulPaymentEvent? = null
|
||||
}
|
||||
|
@ -17,8 +17,7 @@ import dev.inmo.tgbotapi.types.message.abstracts.UnknownMessageType
|
||||
import dev.inmo.tgbotapi.types.message.content.*
|
||||
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
||||
import dev.inmo.tgbotapi.types.message.content.media.*
|
||||
import dev.inmo.tgbotapi.types.message.payments.InvoiceContent
|
||||
import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentInfo
|
||||
import dev.inmo.tgbotapi.types.message.payments.*
|
||||
import dev.inmo.tgbotapi.types.passport.PassportData
|
||||
import dev.inmo.tgbotapi.types.payments.Invoice
|
||||
import dev.inmo.tgbotapi.types.payments.SuccessfulPayment
|
||||
@ -197,18 +196,11 @@ internal data class RawMessage(
|
||||
channel_chat_created -> ChannelChatCreated()
|
||||
pinned_message != null -> PinnedMessage(pinned_message.asMessage)
|
||||
proximity_alert_triggered != null -> proximity_alert_triggered
|
||||
successful_payment != null -> SuccessfulPaymentEvent(successful_payment)
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
private val paymentInfo: SuccessfulPaymentInfo? by lazy {
|
||||
when {
|
||||
successful_payment != null -> SuccessfulPaymentInfo(successful_payment)
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
val asMessage: Message by lazy {
|
||||
try {
|
||||
chatEvent?.let { chatEvent ->
|
||||
@ -233,6 +225,12 @@ internal data class RawMessage(
|
||||
chatEvent as? ChannelEvent ?: throwWrongChatEvent(ChannelEvent::class, chatEvent),
|
||||
date.asDate
|
||||
)
|
||||
is PrivateChat -> PrivateEventMessage(
|
||||
messageId,
|
||||
chat,
|
||||
chatEvent as? PrivateEvent ?: throwWrongChatEvent(PrivateEvent::class, chatEvent),
|
||||
date.asDate
|
||||
)
|
||||
else -> error("Expected one of the public chats, but was $chat (in extracting of chat event message)")
|
||||
}
|
||||
} ?: content?.let { content ->
|
||||
@ -335,8 +333,7 @@ internal data class RawMessage(
|
||||
forwarded,
|
||||
reply_to_message?.asMessage,
|
||||
reply_markup,
|
||||
via_bot,
|
||||
paymentInfo
|
||||
via_bot
|
||||
)
|
||||
else -> error("Unknown type of chat: $chat")
|
||||
}
|
||||
@ -359,7 +356,7 @@ internal data class RawMessage(
|
||||
}
|
||||
}
|
||||
|
||||
private fun throwWrongChatEvent(expected: KClass<*>, but: ChatEvent): CommonEvent {
|
||||
private fun throwWrongChatEvent(expected: KClass<*>, but: ChatEvent): Nothing {
|
||||
error("Wrong type of chat event: expected $expected, but was $but")
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
package dev.inmo.tgbotapi.types.message.payments
|
||||
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.CommonEvent
|
||||
import dev.inmo.tgbotapi.types.message.payments.abstracts.PaymentInfo
|
||||
import dev.inmo.tgbotapi.types.payments.SuccessfulPayment
|
||||
|
||||
@Deprecated("Renamed", ReplaceWith("SuccessfulPaymentEvent", "dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentEvent"))
|
||||
typealias SuccessfulPaymentInfo = SuccessfulPaymentEvent
|
||||
data class SuccessfulPaymentEvent(
|
||||
val payment: SuccessfulPayment
|
||||
) : PaymentInfo, CommonEvent
|
@ -1,8 +0,0 @@
|
||||
package dev.inmo.tgbotapi.types.message.payments
|
||||
|
||||
import dev.inmo.tgbotapi.types.message.payments.abstracts.PaymentInfo
|
||||
import dev.inmo.tgbotapi.types.payments.SuccessfulPayment
|
||||
|
||||
data class SuccessfulPaymentInfo(
|
||||
val payment: SuccessfulPayment
|
||||
) : PaymentInfo
|
@ -11,6 +11,7 @@ import dev.inmo.tgbotapi.types.message.ChatEvents.*
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.*
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.voice.*
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage
|
||||
import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentEvent
|
||||
import kotlinx.coroutines.flow.toList
|
||||
|
||||
typealias EventMessageToEventMapper<T> = suspend ChatEventMessage<T>.() -> T?
|
||||
@ -72,6 +73,14 @@ suspend fun BehaviourContext.waitChannelEvents(
|
||||
mapper: EventMessageToEventMapper<ChannelEvent>? = null
|
||||
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
|
||||
|
||||
suspend fun BehaviourContext.waitPrivateEvents(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<ChatEventMessage<PrivateEvent>>? = null,
|
||||
mapper: EventMessageToEventMapper<PrivateEvent>? = null
|
||||
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
|
||||
|
||||
suspend fun BehaviourContext.waitChatEvents(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
@ -117,6 +126,14 @@ suspend fun BehaviourContext.waitMessageAutoDeleteTimerChangedEvents(
|
||||
mapper: EventMessageToEventMapper<MessageAutoDeleteTimerChanged>? = null
|
||||
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
|
||||
|
||||
|
||||
suspend fun BehaviourContext.waitCommonGroupEvents(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<ChatEventMessage<CommonGroupEvent>>? = null,
|
||||
mapper: EventMessageToEventMapper<CommonGroupEvent>? = null
|
||||
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitCommonEvents(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
@ -124,6 +141,7 @@ suspend fun BehaviourContext.waitCommonEvents(
|
||||
filter: SimpleFilter<ChatEventMessage<CommonEvent>>? = null,
|
||||
mapper: EventMessageToEventMapper<CommonEvent>? = null
|
||||
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
|
||||
|
||||
suspend fun BehaviourContext.waitGroupEvents(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
@ -209,3 +227,10 @@ suspend fun BehaviourContext.waitSupergroupChatCreatedEvents(
|
||||
filter: SimpleFilter<ChatEventMessage<SupergroupChatCreated>>? = null,
|
||||
mapper: EventMessageToEventMapper<SupergroupChatCreated>? = null
|
||||
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
|
||||
suspend fun BehaviourContext.waitSuccessfulPaymentEvents(
|
||||
initRequest: Request<*>? = null,
|
||||
errorFactory: NullableRequestBuilder<*> = { null },
|
||||
count: Int = 1,
|
||||
filter: SimpleFilter<ChatEventMessage<SuccessfulPaymentEvent>>? = null,
|
||||
mapper: EventMessageToEventMapper<SuccessfulPaymentEvent>? = null
|
||||
) = waitEvents(count, initRequest, errorFactory, filter, mapper)
|
||||
|
@ -13,6 +13,7 @@ import dev.inmo.tgbotapi.types.message.ChatEvents.*
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.*
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.voice.*
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage
|
||||
import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentEvent
|
||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||
|
||||
internal suspend inline fun <reified T : ChatEvent> BehaviourContext.onEvent(
|
||||
@ -43,6 +44,25 @@ suspend fun BehaviourContext.onChannelEvent(
|
||||
scenarioReceiver: BehaviourContextAndTypeReceiver<Unit, ChatEventMessage<ChannelEvent>>
|
||||
) = onEvent(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 BehaviourContext.onPrivateEvent(
|
||||
initialFilter: SimpleFilter<ChatEventMessage<PrivateEvent>>? = null,
|
||||
subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver<Boolean, ChatEventMessage<PrivateEvent>, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in ChatEventMessage<PrivateEvent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: BehaviourContextAndTypeReceiver<Unit, ChatEventMessage<PrivateEvent>>
|
||||
) = onEvent(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,
|
||||
@ -157,6 +177,25 @@ suspend fun BehaviourContext.onMessageAutoDeleteTimerChangedEvent(
|
||||
scenarioReceiver: BehaviourContextAndTypeReceiver<Unit, ChatEventMessage<MessageAutoDeleteTimerChanged>>
|
||||
) = onEvent(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 BehaviourContext.onCommonGroupEvent(
|
||||
initialFilter: SimpleFilter<ChatEventMessage<CommonGroupEvent>>? = null,
|
||||
subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver<Boolean, ChatEventMessage<CommonGroupEvent>, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in ChatEventMessage<CommonGroupEvent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: BehaviourContextAndTypeReceiver<Unit, ChatEventMessage<CommonGroupEvent>>
|
||||
) = onEvent(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,
|
||||
@ -403,3 +442,22 @@ suspend fun BehaviourContext.onSupergroupChatCreated(
|
||||
markerFactory: MarkerFactory<in ChatEventMessage<SupergroupChatCreated>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: BehaviourContextAndTypeReceiver<Unit, ChatEventMessage<SupergroupChatCreated>>
|
||||
) = onEvent(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 BehaviourContext.onSuccessfulPayment(
|
||||
initialFilter: SimpleFilter<ChatEventMessage<SuccessfulPaymentEvent>>? = null,
|
||||
subcontextUpdatesFilter: BehaviourContextAndTwoTypesReceiver<Boolean, ChatEventMessage<SuccessfulPaymentEvent>, Update>? = MessageFilterByChat,
|
||||
markerFactory: MarkerFactory<in ChatEventMessage<SuccessfulPaymentEvent>, Any> = ByChatMessageMarkerFactory,
|
||||
scenarioReceiver: BehaviourContextAndTypeReceiver<Unit, ChatEventMessage<SuccessfulPaymentEvent>>
|
||||
) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
|
||||
|
@ -1092,6 +1092,15 @@ inline fun Message.asGroupEventMessage(): GroupEventMessage<GroupEvent>? = this
|
||||
@PreviewFeature
|
||||
inline fun Message.requireGroupEventMessage(): GroupEventMessage<GroupEvent> = this as GroupEventMessage<GroupEvent>
|
||||
|
||||
@PreviewFeature
|
||||
inline fun <T> Message.whenPrivateEventMessage(block: (PrivateEventMessage<PrivateEvent>) -> T) = asPrivateEventMessage() ?.let(block)
|
||||
|
||||
@PreviewFeature
|
||||
inline fun Message.asPrivateEventMessage(): PrivateEventMessage<PrivateEvent>? = this as? PrivateEventMessage<PrivateEvent>
|
||||
|
||||
@PreviewFeature
|
||||
inline fun Message.requirePrivateEventMessage(): PrivateEventMessage<PrivateEvent> = this as PrivateEventMessage<PrivateEvent>
|
||||
|
||||
@PreviewFeature
|
||||
inline fun <T> Message.whenGroupContentMessage(block: (GroupContentMessage<MessageContent>) -> T) = asGroupContentMessage() ?.let(block)
|
||||
|
||||
@ -3034,13 +3043,13 @@ inline fun ChatEvent.asChannelEvent(): ChannelEvent? = this as? ChannelEvent
|
||||
inline fun ChatEvent.requireChannelEvent(): ChannelEvent = this as ChannelEvent
|
||||
|
||||
@PreviewFeature
|
||||
inline fun <T> ChatEvent.whenCommonEvent(block: (CommonEvent) -> T) = asCommonEvent() ?.let(block)
|
||||
inline fun <T> ChatEvent.whenCommonEvent(block: (CommonGroupEvent) -> T) = asCommonEvent() ?.let(block)
|
||||
|
||||
@PreviewFeature
|
||||
inline fun ChatEvent.asCommonEvent(): CommonEvent? = this as? CommonEvent
|
||||
inline fun ChatEvent.asCommonEvent(): CommonGroupEvent? = this as? CommonGroupEvent
|
||||
|
||||
@PreviewFeature
|
||||
inline fun ChatEvent.requireCommonEvent(): CommonEvent = this as CommonEvent
|
||||
inline fun ChatEvent.requireCommonEvent(): CommonGroupEvent = this as CommonGroupEvent
|
||||
|
||||
@PreviewFeature
|
||||
inline fun <T> ChatEvent.whenGroupEvent(block: (GroupEvent) -> T) = asGroupEvent() ?.let(block)
|
||||
|
@ -6,7 +6,10 @@ import dev.inmo.micro_utils.coroutines.plus
|
||||
import dev.inmo.tgbotapi.types.message.ChannelEventMessage
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.*
|
||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.*
|
||||
import dev.inmo.tgbotapi.types.message.PrivateEventMessage
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.*
|
||||
import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentEvent
|
||||
import dev.inmo.tgbotapi.types.payments.SuccessfulPayment
|
||||
import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter
|
||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
@ -32,6 +35,11 @@ inline fun FlowsUpdatesFilter.supergroupEvents(): Flow<SupergroupEventMessage<*>
|
||||
it.data as? SupergroupEventMessage<*>
|
||||
}
|
||||
|
||||
@RiskFeature("Use with caution")
|
||||
inline fun FlowsUpdatesFilter.privateEvents(): Flow<PrivateEventMessage<*>> = messagesFlow.mapNotNull {
|
||||
it.data as? PrivateEventMessage<*>
|
||||
}
|
||||
|
||||
@RiskFeature("Use with caution")
|
||||
inline fun <reified T: ChatEvent, reified O: ChatEventMessage<T>> Flow<ChatEventMessage<*>>.filterByChatEvent(): Flow<O> = mapNotNull {
|
||||
if (it.chatEvent is T) it as? O else null
|
||||
@ -51,6 +59,8 @@ inline fun Flow<ChatEventMessage<*>>.newChannelTitleEvents() = filterChannelEven
|
||||
inline fun FlowsUpdatesFilter.newChannelTitleEvents() = filterChannelEvents<NewChatTitle>()
|
||||
inline fun Flow<ChatEventMessage<*>>.newChannelPinnedMessageEvents() = filterChannelEvents<PinnedMessage>()
|
||||
inline fun FlowsUpdatesFilter.newChannelPinnedMessageEvents() = filterChannelEvents<PinnedMessage>()
|
||||
inline fun Flow<ChatEventMessage<*>>.successfulPaymentInChannelEvents() = filterChannelEvents<SuccessfulPaymentEvent>()
|
||||
inline fun FlowsUpdatesFilter.successfulPaymentInChannelEvents() = filterChannelEvents<SuccessfulPaymentEvent>()
|
||||
inline fun Flow<ChatEventMessage<*>>.channelEvents() = filterChannelEvents<ChannelEvent>()
|
||||
|
||||
@RiskFeature("Use with caution")
|
||||
@ -73,6 +83,8 @@ inline fun Flow<ChatEventMessage<*>>.newGroupPinnedMessageEvents() = filterGroup
|
||||
inline fun FlowsUpdatesFilter.newGroupPinnedMessageEvents() = filterGroupEvents<PinnedMessage>()
|
||||
inline fun Flow<ChatEventMessage<*>>.proximityAlertTriggeredInGroupEvents() = filterGroupEvents<ProximityAlertTriggered>()
|
||||
inline fun FlowsUpdatesFilter.proximityAlertTriggeredInGroupEvents() = filterGroupEvents<ProximityAlertTriggered>()
|
||||
inline fun Flow<ChatEventMessage<*>>.successfulPaymentInGroupEvents() = filterGroupEvents<SuccessfulPaymentEvent>()
|
||||
inline fun FlowsUpdatesFilter.successfulPaymentInGroupEvents() = filterGroupEvents<SuccessfulPaymentEvent>()
|
||||
inline fun Flow<ChatEventMessage<*>>.groupEvents() = filterGroupEvents<GroupEvent>()
|
||||
|
||||
|
||||
@ -96,4 +108,16 @@ inline fun Flow<ChatEventMessage<*>>.newSupergroupPinnedMessageEvents() = filter
|
||||
inline fun FlowsUpdatesFilter.newSupergroupPinnedMessageEvents() = filterSupergroupEvents<PinnedMessage>()
|
||||
inline fun Flow<ChatEventMessage<*>>.proximityAlertTriggeredInSupergroupEvents() = filterSupergroupEvents<ProximityAlertTriggered>()
|
||||
inline fun FlowsUpdatesFilter.proximityAlertTriggeredInSupergroupEvents() = filterSupergroupEvents<ProximityAlertTriggered>()
|
||||
inline fun Flow<ChatEventMessage<*>>.successfulPaymentInSupergroupEvents() = filterSupergroupEvents<SuccessfulPaymentEvent>()
|
||||
inline fun FlowsUpdatesFilter.successfulPaymentInSupergroupEvents() = filterSupergroupEvents<SuccessfulPaymentEvent>()
|
||||
inline fun Flow<ChatEventMessage<*>>.supergroupEvents() = filterSupergroupEvents<SupergroupEvent>()
|
||||
|
||||
@RiskFeature("Use with caution")
|
||||
inline fun <reified T : PrivateEvent> Flow<ChatEventMessage<*>>.filterPrivateEvents() = filterByChatEvent<T, PrivateEventMessage<T>>()
|
||||
@RiskFeature("Use with caution")
|
||||
inline fun <reified T : PrivateEvent> FlowsUpdatesFilter.filterPrivateEvents() = privateEvents().filterByChatEvent<T, PrivateEventMessage<T>>()
|
||||
inline fun Flow<ChatEventMessage<*>>.successfulPaymentInPrivateEvents() = filterPrivateEvents<SuccessfulPaymentEvent>()
|
||||
inline fun FlowsUpdatesFilter.successfulPaymentInPrivateEvents() = filterPrivateEvents<SuccessfulPaymentEvent>()
|
||||
inline fun Flow<ChatEventMessage<*>>.newPrivatePinnedMessageEvents() = filterPrivateEvents<PinnedMessage>()
|
||||
inline fun FlowsUpdatesFilter.newPrivatePinnedMessageEvents() = filterPrivateEvents<PinnedMessage>()
|
||||
inline fun Flow<ChatEventMessage<*>>.privateEvents() = filterPrivateEvents<PrivateEvent>()
|
||||
|
Loading…
Reference in New Issue
Block a user