mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-09-08 17:49:35 +00:00
add different business entities
This commit is contained in:
@@ -265,6 +265,7 @@ import dev.inmo.tgbotapi.types.message.PrivateEventMessage
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.AnonymousForumContentMessage
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.AnonymousGroupContentMessage
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.BusinessContentMessage
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.ChannelContentMessage
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.CommonForumContentMessage
|
||||
@@ -441,6 +442,7 @@ import dev.inmo.tgbotapi.types.request.ChatSharedRequest
|
||||
import dev.inmo.tgbotapi.types.request.RequestResponse
|
||||
import dev.inmo.tgbotapi.types.request.UsersShared
|
||||
import dev.inmo.tgbotapi.types.update.BusinessConnectionUpdate
|
||||
import dev.inmo.tgbotapi.types.update.BusinessMessageUpdate
|
||||
import dev.inmo.tgbotapi.types.update.CallbackQueryUpdate
|
||||
import dev.inmo.tgbotapi.types.update.ChannelPostUpdate
|
||||
import dev.inmo.tgbotapi.types.update.ChatBoostRemovedUpdate
|
||||
@@ -450,6 +452,8 @@ import dev.inmo.tgbotapi.types.update.ChatMessageReactionUpdatedUpdate
|
||||
import dev.inmo.tgbotapi.types.update.ChatMessageReactionsCountUpdatedUpdate
|
||||
import dev.inmo.tgbotapi.types.update.ChosenInlineResultUpdate
|
||||
import dev.inmo.tgbotapi.types.update.CommonChatMemberUpdatedUpdate
|
||||
import dev.inmo.tgbotapi.types.update.DeletedBusinessMessageUpdate
|
||||
import dev.inmo.tgbotapi.types.update.EditBusinessMessageUpdate
|
||||
import dev.inmo.tgbotapi.types.update.EditChannelPostUpdate
|
||||
import dev.inmo.tgbotapi.types.update.EditMessageUpdate
|
||||
import dev.inmo.tgbotapi.types.update.InlineQueryUpdate
|
||||
@@ -760,6 +764,18 @@ public inline fun WithUser.passportMessageOrThrow(): PassportMessage = this as
|
||||
public inline fun <T> WithUser.ifPassportMessage(block: (PassportMessage) -> T): T? =
|
||||
passportMessageOrNull() ?.let(block)
|
||||
|
||||
public inline fun WithUser.businessContentMessageOrNull(): BusinessContentMessage<MessageContent>? =
|
||||
this as?
|
||||
dev.inmo.tgbotapi.types.message.abstracts.BusinessContentMessage<dev.inmo.tgbotapi.types.message.content.MessageContent>
|
||||
|
||||
public inline fun WithUser.businessContentMessageOrThrow(): BusinessContentMessage<MessageContent> =
|
||||
this as
|
||||
dev.inmo.tgbotapi.types.message.abstracts.BusinessContentMessage<dev.inmo.tgbotapi.types.message.content.MessageContent>
|
||||
|
||||
public inline fun <T>
|
||||
WithUser.ifBusinessContentMessage(block: (BusinessContentMessage<MessageContent>) -> T): T? =
|
||||
businessContentMessageOrNull() ?.let(block)
|
||||
|
||||
public inline fun WithUser.fromUserMessageOrNull(): FromUserMessage? = this as?
|
||||
dev.inmo.tgbotapi.types.message.abstracts.FromUserMessage
|
||||
|
||||
@@ -3358,6 +3374,18 @@ public inline fun <T>
|
||||
Message.ifPrivateEventMessage(block: (PrivateEventMessage<PrivateEvent>) -> T): T? =
|
||||
privateEventMessageOrNull() ?.let(block)
|
||||
|
||||
public inline fun Message.businessContentMessageOrNull(): BusinessContentMessage<MessageContent>? =
|
||||
this as?
|
||||
dev.inmo.tgbotapi.types.message.abstracts.BusinessContentMessage<dev.inmo.tgbotapi.types.message.content.MessageContent>
|
||||
|
||||
public inline fun Message.businessContentMessageOrThrow(): BusinessContentMessage<MessageContent> =
|
||||
this as
|
||||
dev.inmo.tgbotapi.types.message.abstracts.BusinessContentMessage<dev.inmo.tgbotapi.types.message.content.MessageContent>
|
||||
|
||||
public inline fun <T>
|
||||
Message.ifBusinessContentMessage(block: (BusinessContentMessage<MessageContent>) -> T): T? =
|
||||
businessContentMessageOrNull() ?.let(block)
|
||||
|
||||
public inline fun Message.channelContentMessageOrNull(): ChannelContentMessage<MessageContent>? =
|
||||
this as?
|
||||
dev.inmo.tgbotapi.types.message.abstracts.ChannelContentMessage<dev.inmo.tgbotapi.types.message.content.MessageContent>
|
||||
@@ -4910,6 +4938,15 @@ public inline fun Update.businessConnectionUpdateOrThrow(): BusinessConnectionUp
|
||||
public inline fun <T> Update.ifBusinessConnectionUpdate(block: (BusinessConnectionUpdate) -> T): T?
|
||||
= businessConnectionUpdateOrNull() ?.let(block)
|
||||
|
||||
public inline fun Update.businessMessageUpdateOrNull(): BusinessMessageUpdate? = this as?
|
||||
dev.inmo.tgbotapi.types.update.BusinessMessageUpdate
|
||||
|
||||
public inline fun Update.businessMessageUpdateOrThrow(): BusinessMessageUpdate = this as
|
||||
dev.inmo.tgbotapi.types.update.BusinessMessageUpdate
|
||||
|
||||
public inline fun <T> Update.ifBusinessMessageUpdate(block: (BusinessMessageUpdate) -> T): T? =
|
||||
businessMessageUpdateOrNull() ?.let(block)
|
||||
|
||||
public inline fun Update.callbackQueryUpdateOrNull(): CallbackQueryUpdate? = this as?
|
||||
dev.inmo.tgbotapi.types.update.CallbackQueryUpdate
|
||||
|
||||
@@ -4996,6 +5033,25 @@ public inline fun <T>
|
||||
Update.ifCommonChatMemberUpdatedUpdate(block: (CommonChatMemberUpdatedUpdate) -> T): T? =
|
||||
commonChatMemberUpdatedUpdateOrNull() ?.let(block)
|
||||
|
||||
public inline fun Update.deletedBusinessMessageUpdateOrNull(): DeletedBusinessMessageUpdate? = this
|
||||
as? dev.inmo.tgbotapi.types.update.DeletedBusinessMessageUpdate
|
||||
|
||||
public inline fun Update.deletedBusinessMessageUpdateOrThrow(): DeletedBusinessMessageUpdate = this
|
||||
as dev.inmo.tgbotapi.types.update.DeletedBusinessMessageUpdate
|
||||
|
||||
public inline fun <T>
|
||||
Update.ifDeletedBusinessMessageUpdate(block: (DeletedBusinessMessageUpdate) -> T): T? =
|
||||
deletedBusinessMessageUpdateOrNull() ?.let(block)
|
||||
|
||||
public inline fun Update.editBusinessMessageUpdateOrNull(): EditBusinessMessageUpdate? = this as?
|
||||
dev.inmo.tgbotapi.types.update.EditBusinessMessageUpdate
|
||||
|
||||
public inline fun Update.editBusinessMessageUpdateOrThrow(): EditBusinessMessageUpdate = this as
|
||||
dev.inmo.tgbotapi.types.update.EditBusinessMessageUpdate
|
||||
|
||||
public inline fun <T> Update.ifEditBusinessMessageUpdate(block: (EditBusinessMessageUpdate) -> T):
|
||||
T? = editBusinessMessageUpdateOrNull() ?.let(block)
|
||||
|
||||
public inline fun Update.editChannelPostUpdateOrNull(): EditChannelPostUpdate? = this as?
|
||||
dev.inmo.tgbotapi.types.update.EditChannelPostUpdate
|
||||
|
||||
|
@@ -23,6 +23,9 @@ inline fun <reified T : MessageContent> ChannelContentMessage<*>.requireWithCont
|
||||
inline fun <reified T : MessageContent> PrivateContentMessage<*>.withContent() = if (content is T) { this as PrivateContentMessage<T> } else { null }
|
||||
inline fun <reified T : MessageContent> PrivateContentMessage<*>.requireWithContent() = withContent<T>()!!
|
||||
|
||||
inline fun <reified T : MessageContent> BusinessContentMessage<*>.withContent() = if (content is T) { this as BusinessContentMessage<T> } else { null }
|
||||
inline fun <reified T : MessageContent> BusinessContentMessage<*>.requireWithContent() = withContent<T>()!!
|
||||
|
||||
inline fun <reified T : MessageContent> PublicContentMessage<*>.withContent() = if (content is T) { this as PublicContentMessage<T> } else { null }
|
||||
inline fun <reified T : MessageContent> PublicContentMessage<*>.requireWithContent() = withContent<T>()!!
|
||||
|
||||
|
@@ -1,2 +0,0 @@
|
||||
package dev.inmo.tgbotapi.extensions.utils.extensions
|
||||
|
@@ -1,12 +1,15 @@
|
||||
package dev.inmo.tgbotapi.extensions.utils.extensions
|
||||
|
||||
import dev.inmo.tgbotapi.abstracts.WithPreviewChat
|
||||
import dev.inmo.tgbotapi.abstracts.types.WithBusinessConnectionId
|
||||
import dev.inmo.tgbotapi.abstracts.types.WithOptionalBusinessConnectionId
|
||||
import dev.inmo.tgbotapi.extensions.utils.usernameChatOrNull
|
||||
import dev.inmo.tgbotapi.extensions.utils.whenUsernameChat
|
||||
import dev.inmo.tgbotapi.types.ChatIdentifier
|
||||
import dev.inmo.tgbotapi.types.MessageId
|
||||
import dev.inmo.tgbotapi.types.MessageThreadId
|
||||
import dev.inmo.tgbotapi.types.Username
|
||||
import dev.inmo.tgbotapi.types.business_connection.BusinessConnectionId
|
||||
import dev.inmo.tgbotapi.types.chat.Chat
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
||||
import dev.inmo.tgbotapi.types.threadId
|
||||
@@ -126,3 +129,17 @@ inline fun Message.sameTopic(other: Message) = sameTopic(other.chat, other.threa
|
||||
*/
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun Message.sameThread(other: Message) = sameTopic(other)
|
||||
|
||||
/**
|
||||
* @return true in case if [this] message is from the same business connection (with businessConnectionId == [id])
|
||||
*/
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun Message.sameBusinessConnection(
|
||||
id: BusinessConnectionId
|
||||
) = businessConnectionId == id
|
||||
|
||||
/**
|
||||
* @return true in case if [this] message is from the same business connection (with businessConnectionId == [other.businessConnectionId])
|
||||
*/
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun Message.sameBusinessConnection(other: WithBusinessConnectionId) = sameBusinessConnection(other.businessConnectionId)
|
||||
|
@@ -44,6 +44,9 @@ fun Update.sourceChatWithConverters(
|
||||
chatBoostUpdatedUpdateFlow: (ChatBoostUpdatedUpdate) -> Chat? = { it.data.chat },
|
||||
chatBoostRemovedUpdateFlow: (ChatBoostRemovedUpdate) -> Chat? = { it.data.chat },
|
||||
businessConnectionUpdateConverter: (BusinessConnectionUpdate) -> Chat? = { it.data.user },
|
||||
businessMessageUpdateConverter: (BusinessMessageUpdate) -> Chat? = { it.data.chat },
|
||||
editBusinessMessageUpdateConverter: (EditBusinessMessageUpdate) -> Chat? = { it.data.chat },
|
||||
deleteBusinessMessageUpdateConverter: (DeletedBusinessMessageUpdate) -> Chat? = { it.data.chat },
|
||||
commonChatMemberUpdatedUpdateConverter: (CommonChatMemberUpdatedUpdate) -> Chat? = { it.data.chat }
|
||||
): Chat? = when (this) {
|
||||
is BaseMessageUpdate -> baseMessageUpdateConverter(this)
|
||||
@@ -66,6 +69,9 @@ fun Update.sourceChatWithConverters(
|
||||
is ChatBoostUpdatedUpdate -> chatBoostUpdatedUpdateFlow(this)
|
||||
is ChatBoostRemovedUpdate -> chatBoostRemovedUpdateFlow(this)
|
||||
is BusinessConnectionUpdate -> businessConnectionUpdateConverter(this)
|
||||
is BusinessMessageUpdate -> businessMessageUpdateConverter(this)
|
||||
is EditBusinessMessageUpdate -> editBusinessMessageUpdateConverter(this)
|
||||
is DeletedBusinessMessageUpdate -> deleteBusinessMessageUpdateConverter(this)
|
||||
else -> {
|
||||
when (val data = data) {
|
||||
is FromUser -> data.from
|
||||
|
@@ -0,0 +1,12 @@
|
||||
package dev.inmo.tgbotapi.extensions.utils.shortcuts
|
||||
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.AccessibleMessage
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.BusinessContentMessage
|
||||
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
||||
import dev.inmo.tgbotapi.types.message.content.MessageContent
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.filterIsInstance
|
||||
|
||||
inline fun Flow<AccessibleMessage>.businessMessages() = filterIsInstance<BusinessContentMessage<*>>()
|
||||
inline fun <reified T : MessageContent> Flow<ContentMessage<T>>.businessMessagesWithType() = filterIsInstance<BusinessContentMessage<T>>()
|
||||
inline fun Flow<ContentMessage<*>>.allBusinessMessages() = businessMessagesWithType()
|
Reference in New Issue
Block a user