diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d217da284..fd46ba7a2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,31 @@ # TelegramBotAPI changelog +## 0.30.4 + +* `Common`: + * `Version`: + * `MicroUtils`: `0.3.1` -> `0.3.3` +* `Core`: + * `MultilevelTextSource#textSources` has been safely renamed to `subsources` + * `TextContent#fullEntitiesList` has been deprecated + * Now `TextContent` implements `TextedInput` + * `TextContent#entities` has been deprecated + * `GroupEventMessage` now overrides `chatEvent` with type `GroupEvent` + * `SupergroupEventMessage` now overrides `chatEvent` with type `SupergroupEvent` + * Any `ChatEventMessage` now have generic type of its `chatEvent` (just like messages) +* `Utils`: + * Old extensions related to chat events are deprecated: + * `Flow>#divideBySource` + * `Flow>#onlyChannelEvents` + * `Flow>#onlyGroupEvents` + * `Flow>#onlySupergroupEvents` + * A lot of extensions for `Flow` has been added: + * `FlowsUpdatesFilter#events` + * `FlowsUpdatesFilter#channelEvents` + * `FlowsUpdatesFilter#groupEvents` + * `FlowsUpdatesFilter#supergroupEvents` + * And a lot of other filters with specific types + ## 0.30.3 * `Common`: diff --git a/gradle.properties b/gradle.properties index b78605ad23..59e7102e0a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,12 +12,12 @@ klock_version=1.12.1 uuid_version=0.2.2 ktor_version=1.4.2 -micro_utils_version=0.3.1 +micro_utils_version=0.3.3 javax_activation_version=1.1.1 library_group=dev.inmo -library_version=0.30.3 +library_version=0.30.4 gradle_bintray_plugin_version=1.8.5 github_release_plugin_version=2.2.12 diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/TextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/TextSource.kt index aac31893f5..6f067adeff 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/TextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/TextSource.kt @@ -36,7 +36,10 @@ interface MultilevelTextSource : TextSource { @Deprecated("Will be removed in near major release") val textParts: List get() = textParts(0) + val subsources: List + @Deprecated("Will be removed in near major release", ReplaceWith("subsources")) val textSources: List + get() = subsources } data class TextPart( @@ -46,7 +49,7 @@ data class TextPart( fun List.justTextSources() = map { it.source } fun List.makeString() = joinToString("") { it.source } -internal fun MultilevelTextSource.textParts(offset: Int): List = textSources.toTextParts(offset) +internal fun MultilevelTextSource.textParts(offset: Int): List = subsources.toTextParts(offset) fun List.separateForMessage(limit: IntRange, numberOfParts: Int? = null): List> { if (isEmpty()) { return emptyList() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BoldTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BoldTextSource.kt index 64c1d3dee4..d5098f72f0 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BoldTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BoldTextSource.kt @@ -11,7 +11,7 @@ import dev.inmo.tgbotapi.utils.internal.boldMarkdownV2 */ data class BoldTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, - override val textSources: List + override val subsources: List ) : MultilevelTextSource { override val asMarkdownSource: String by lazy { source.boldMarkdown() } override val asMarkdownV2Source: String by lazy { boldMarkdownV2() } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CashTagTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CashTagTextSource.kt index 221fd5712e..5b016c0fd1 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CashTagTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CashTagTextSource.kt @@ -11,7 +11,7 @@ import dev.inmo.tgbotapi.utils.internal.cashTagMarkdownV2 */ data class CashTagTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, - override val textSources: List + override val subsources: List ) : MultilevelTextSource { override val asMarkdownSource: String by lazy { source.cashTagMarkdown() } override val asMarkdownV2Source: String by lazy { cashTagMarkdownV2() } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/EMailTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/EMailTextSource.kt index 77704d1e69..850cbefcd9 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/EMailTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/EMailTextSource.kt @@ -11,7 +11,7 @@ import dev.inmo.tgbotapi.utils.internal.emailMarkdownV2 */ data class EMailTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, - override val textSources: List + override val subsources: List ) : MultilevelTextSource { override val asMarkdownSource: String by lazy { source.emailMarkdown() } override val asMarkdownV2Source: String by lazy { emailMarkdownV2(source) } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/HashTagTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/HashTagTextSource.kt index 37ecbe8861..04af45a2e3 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/HashTagTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/HashTagTextSource.kt @@ -11,7 +11,7 @@ import dev.inmo.tgbotapi.utils.internal.hashTagMarkdownV2 */ data class HashTagTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, - override val textSources: List + override val subsources: List ) : MultilevelTextSource { override val asMarkdownSource: String by lazy { source.hashTagMarkdown() } override val asMarkdownV2Source: String by lazy { hashTagMarkdownV2() } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/ItalicTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/ItalicTextSource.kt index 887238f2bb..870fc8c7fc 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/ItalicTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/ItalicTextSource.kt @@ -11,7 +11,7 @@ import dev.inmo.tgbotapi.utils.internal.italicMarkdownV2 */ data class ItalicTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, - override val textSources: List + override val subsources: List ) : MultilevelTextSource { override val asMarkdownSource: String by lazy { source.italicMarkdown() } override val asMarkdownV2Source: String by lazy { italicMarkdownV2() } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/MentionTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/MentionTextSource.kt index ef17ac5632..f56ca0a13e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/MentionTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/MentionTextSource.kt @@ -18,7 +18,7 @@ private val String.withoutCommercialAt */ data class MentionTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, - override val textSources: List + override val subsources: List ) : MultilevelTextSource { override val asMarkdownSource: String by lazy { source.mentionMarkdown() } override val asMarkdownV2Source: String by lazy { mentionMarkdownV2() } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PhoneNumberTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PhoneNumberTextSource.kt index 321fb3f6f5..c6950f0889 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PhoneNumberTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PhoneNumberTextSource.kt @@ -11,7 +11,7 @@ import dev.inmo.tgbotapi.utils.internal.phoneMarkdownV2 */ data class PhoneNumberTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, - override val textSources: List + override val subsources: List ) : MultilevelTextSource { override val asMarkdownSource: String by lazy { source.phoneMarkdown() } override val asMarkdownV2Source: String by lazy { phoneMarkdownV2() } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/StrikethroughTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/StrikethroughTextSource.kt index b273b012c0..58e8e18dbd 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/StrikethroughTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/StrikethroughTextSource.kt @@ -11,7 +11,7 @@ import dev.inmo.tgbotapi.utils.internal.strikethroughMarkdownV2 */ data class StrikethroughTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, - override val textSources: List + override val subsources: List ) : MultilevelTextSource { override val asHtmlSource: String by lazy { strikethroughHTML() } override val asMarkdownV2Source: String by lazy { strikethroughMarkdownV2() } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextMentionTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextMentionTextSource.kt index 4ef48dbee6..acf2902cfa 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextMentionTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextMentionTextSource.kt @@ -13,7 +13,7 @@ import dev.inmo.tgbotapi.utils.internal.textMentionMarkdownV2 data class TextMentionTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, val user: User, - override val textSources: List + override val subsources: List ) : MultilevelTextSource { override val asMarkdownSource: String by lazy { source.textMentionMarkdown(user.id) } override val asMarkdownV2Source: String by lazy { textMentionMarkdownV2(user.id) } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/UnderlineTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/UnderlineTextSource.kt index 3523f12496..db6dd52efa 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/UnderlineTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/UnderlineTextSource.kt @@ -11,7 +11,7 @@ import dev.inmo.tgbotapi.utils.internal.underlineMarkdownV2 */ data class UnderlineTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, - override val textSources: List + override val subsources: List ) : MultilevelTextSource { override val asMarkdownSource: String by lazy { source.underlineMarkdown() } override val asMarkdownV2Source: String by lazy { underlineMarkdownV2() } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelEventMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelEventMessage.kt index ce972e7d52..009dd19ef7 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelEventMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelEventMessage.kt @@ -4,11 +4,12 @@ import com.soywiz.klock.DateTime import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.chat.abstracts.ChannelChat import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.ChannelEvent +import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.GroupEvent import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage -data class ChannelEventMessage( +data class ChannelEventMessage( override val messageId: MessageIdentifier, override val chat: ChannelChat, - override val chatEvent: ChannelEvent, + override val chatEvent: T, override val date: DateTime -) : ChatEventMessage +) : ChatEventMessage diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/abstracts/SupergroupEvent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/abstracts/SupergroupEvent.kt index d57d4a969f..cd0bfe9b53 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/abstracts/SupergroupEvent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/abstracts/SupergroupEvent.kt @@ -1,3 +1,3 @@ package dev.inmo.tgbotapi.types.message.ChatEvents.abstracts -interface SupergroupEvent: ChatEvent \ No newline at end of file +interface SupergroupEvent: GroupEvent \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonGroupEventMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonGroupEventMessage.kt index d55134b6c5..d3c2edb7a4 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonGroupEventMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonGroupEventMessage.kt @@ -8,12 +8,12 @@ import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.GroupEvent import dev.inmo.tgbotapi.types.message.abstracts.GroupEventMessage @Deprecated("Renamed", ReplaceWith("CommonGroupEventMessage")) -typealias GroupEventMessage = CommonGroupEventMessage +typealias GroupEventMessage = CommonGroupEventMessage<*> -data class CommonGroupEventMessage( +data class CommonGroupEventMessage( override val messageId: MessageIdentifier, override val user: User, override val chat: GroupChat, - override val chatEvent: GroupEvent, + override val chatEvent: T, override val date: DateTime -) : GroupEventMessage +) : GroupEventMessage diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonSupergroupEventMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonSupergroupEventMessage.kt index f5a382888e..d79212f169 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonSupergroupEventMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonSupergroupEventMessage.kt @@ -4,16 +4,17 @@ import com.soywiz.klock.DateTime import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.User import dev.inmo.tgbotapi.types.chat.abstracts.SupergroupChat +import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.GroupEvent import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.SupergroupEvent import dev.inmo.tgbotapi.types.message.abstracts.SupergroupEventMessage @Deprecated("Renamed", ReplaceWith("CommonSupergroupEventMessage")) -typealias SupergroupEventMessage = CommonSupergroupEventMessage +typealias SupergroupEventMessage = CommonSupergroupEventMessage<*> -data class CommonSupergroupEventMessage( +data class CommonSupergroupEventMessage( override val messageId: MessageIdentifier, override val user: User, override val chat: SupergroupChat, - override val chatEvent: SupergroupEvent, + override val chatEvent: T, override val date: DateTime -) : SupergroupEventMessage +) : SupergroupEventMessage diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/GroupMessages.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/GroupMessages.kt index 8a72fc3393..bf919049d8 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/GroupMessages.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/GroupMessages.kt @@ -38,6 +38,7 @@ data class AnonymousGroupMessageImpl( data class CommonGroupMessageImpl( override val chat: GroupChat, override val messageId: MessageIdentifier, + override val user: User, override val date: DateTime, override val forwardInfo: ForwardInfo?, override val editDate: DateTime?, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt index cfccea7958..a51e011d8a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt @@ -296,6 +296,7 @@ internal data class RawMessage( null -> CommonGroupMessageImpl( chat, messageId, + from ?: error("It is expected that in messages from non anonymous users and channels user must be specified"), date.asDate, forwarded, edit_date ?.asDate, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/ChatEventMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/ChatEventMessage.kt index abef861c5d..c409d53a0e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/ChatEventMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/ChatEventMessage.kt @@ -2,6 +2,6 @@ package dev.inmo.tgbotapi.types.message.abstracts import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.ChatEvent -interface ChatEventMessage : Message { - val chatEvent: ChatEvent +interface ChatEventMessage : Message { + val chatEvent: T } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/GroupEventMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/GroupEventMessage.kt index 2cc84379d1..f8988d489d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/GroupEventMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/GroupEventMessage.kt @@ -1,3 +1,5 @@ package dev.inmo.tgbotapi.types.message.abstracts -interface GroupEventMessage : ChatEventMessage, FromUserMessage +import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.GroupEvent + +interface GroupEventMessage : ChatEventMessage, FromUserMessage diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/GroupMessages.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/GroupMessages.kt index 0338591bcb..5b0df8433a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/GroupMessages.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/GroupMessages.kt @@ -17,4 +17,4 @@ interface AnonymousGroupMessage : GroupMessage, SignedMes override val senderChat: GroupChat get() = chat } -interface CommonGroupMessage : GroupMessage +interface CommonGroupMessage : GroupMessage, FromUserMessage diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/SupergroupEventMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/SupergroupEventMessage.kt index b0fdfd456d..0e111cec2c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/SupergroupEventMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/SupergroupEventMessage.kt @@ -1,3 +1,5 @@ package dev.inmo.tgbotapi.types.message.abstracts -interface SupergroupEventMessage : GroupEventMessage +import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.SupergroupEvent + +interface SupergroupEventMessage : GroupEventMessage diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/TextContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/TextContent.kt index 08a2d23a34..304ace106a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/TextContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/TextContent.kt @@ -1,7 +1,6 @@ package dev.inmo.tgbotapi.types.message.content -import dev.inmo.tgbotapi.CommonAbstracts.TextSourcesList -import dev.inmo.tgbotapi.CommonAbstracts.TextPart +import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.requests.send.SendTextMessage import dev.inmo.tgbotapi.types.ChatIdentifier @@ -15,13 +14,13 @@ import dev.inmo.tgbotapi.utils.internal.fullListOfSubSource import dev.inmo.tgbotapi.utils.internal.toMarkdownTexts data class TextContent( - val text: String, - /** - * Not full list of entities. This list WILL NOT contain [TextPart]s with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource] - * @see [TextContent.fullEntitiesList] - */ - val entities: List = emptyList() -) : MessageContent { + override val text: String, + override val textEntities: List = emptyList() +) : MessageContent, TextedInput { + @Deprecated("Has been renamed", ReplaceWith("textEntities")) + val entities: List + get() = textEntities + override fun createResend( chatId: ChatIdentifier, disableNotification: Boolean, @@ -83,4 +82,5 @@ data class TextContent( * Convert its [TextContent.entities] to list of [dev.inmo.tgbotapi.CommonAbstracts.TextSource] * with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource] */ +@Deprecated("Useless due to the fact that currently every message contains full list of sources") fun TextContent.fullEntitiesList(): TextSourcesList = text.fullListOfSubSource(entities).map { it.source } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/MultilevelTextSourceFormatting.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/MultilevelTextSourceFormatting.kt index 69e44e5d6c..31ef7e5136 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/MultilevelTextSourceFormatting.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/MultilevelTextSourceFormatting.kt @@ -83,19 +83,19 @@ private fun List.joinSubSourcesHtml() = joinToString("") { internal fun MultilevelTextSource.markdownV2Default( openControlSymbol: String, closeControlSymbol: String = openControlSymbol -) = "$openControlSymbol${textSources.joinSubSourcesMarkdownV2()}$closeControlSymbol" +) = "$openControlSymbol${subsources.joinSubSourcesMarkdownV2()}$closeControlSymbol" internal fun MultilevelTextSource.htmlDefault( openControlSymbol: String, closeControlSymbol: String = openControlSymbol -) = "<$openControlSymbol>${textSources.joinSubSourcesHtml()}" +) = "<$openControlSymbol>${subsources.joinSubSourcesHtml()}" internal fun MultilevelTextSource.linkMarkdownV2( link: String -) = "[${textSources.joinSubSourcesMarkdownV2()}](${link.escapeMarkdownV2Link()})" +) = "[${subsources.joinSubSourcesMarkdownV2()}](${link.escapeMarkdownV2Link()})" internal fun MultilevelTextSource.linkHTML( link: String -) = "${textSources.joinSubSourcesHtml()}" +) = "${subsources.joinSubSourcesHtml()}" internal fun MultilevelTextSource.optionalPrefix( @@ -116,8 +116,8 @@ internal fun MultilevelTextSource.boldMarkdownV2(): String = markdownV2Default(m internal fun MultilevelTextSource.boldHTML(): String = htmlDefault(htmlBoldControl) -internal fun MultilevelTextSource.cashTagMarkdownV2(): String = textSources.joinSubSourcesMarkdownV2() -internal fun MultilevelTextSource.cashTagHTML(): String = textSources.joinSubSourcesHtml() +internal fun MultilevelTextSource.cashTagMarkdownV2(): String = subsources.joinSubSourcesMarkdownV2() +internal fun MultilevelTextSource.cashTagHTML(): String = subsources.joinSubSourcesHtml() internal fun MultilevelTextSource.italicMarkdownV2(): String = markdownV2Default(markdownItalicControl) @@ -135,21 +135,21 @@ internal fun MultilevelTextSource.underlineHTML(): String = htmlDefault(htmlUnde internal fun MultilevelTextSource.textMentionMarkdownV2(userId: UserId): String = linkMarkdownV2(userId.link) internal fun MultilevelTextSource.textMentionHTML(userId: UserId): String = linkHTML(userId.link) -internal fun MultilevelTextSource.mentionMarkdownV2(): String = optionalPrefix("@") + textSources.joinSubSourcesMarkdownV2() -internal fun MultilevelTextSource.mentionHTML(): String = optionalPrefix("@") + textSources.joinSubSourcesHtml() +internal fun MultilevelTextSource.mentionMarkdownV2(): String = optionalPrefix("@") + subsources.joinSubSourcesMarkdownV2() +internal fun MultilevelTextSource.mentionHTML(): String = optionalPrefix("@") + subsources.joinSubSourcesHtml() internal fun MultilevelTextSource.hashTagMarkdownV2(): String = when { source.startsWith("\\#") || source.startsWith("#") -> "" else -> "\\#" -} + textSources.joinSubSourcesMarkdownV2() -internal fun MultilevelTextSource.hashTagHTML(): String = optionalPrefix("#") + textSources.joinSubSourcesHtml() +} + subsources.joinSubSourcesMarkdownV2() +internal fun MultilevelTextSource.hashTagHTML(): String = optionalPrefix("#") + subsources.joinSubSourcesHtml() -internal fun MultilevelTextSource.phoneMarkdownV2(): String = textSources.joinSubSourcesMarkdownV2() -internal fun MultilevelTextSource.phoneHTML(): String = textSources.joinSubSourcesHtml() +internal fun MultilevelTextSource.phoneMarkdownV2(): String = subsources.joinSubSourcesMarkdownV2() +internal fun MultilevelTextSource.phoneHTML(): String = subsources.joinSubSourcesHtml() -internal fun MultilevelTextSource.commandMarkdownV2(): String = optionalPrefix("/") + textSources.joinSubSourcesMarkdownV2() -internal fun MultilevelTextSource.commandHTML(): String = optionalPrefix("/") + textSources.joinSubSourcesHtml() +internal fun MultilevelTextSource.commandMarkdownV2(): String = optionalPrefix("/") + subsources.joinSubSourcesMarkdownV2() +internal fun MultilevelTextSource.commandHTML(): String = optionalPrefix("/") + subsources.joinSubSourcesHtml() diff --git a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/EntitiesTestText.kt b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/EntitiesTestText.kt index e754be23b6..b75814dcf1 100644 --- a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/EntitiesTestText.kt +++ b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/MessageEntity/EntitiesTestText.kt @@ -49,8 +49,8 @@ fun List.testTextParts() { assertTrue (get(5).source is MentionTextSource) val boldSource = get(1).source as BoldTextSource - assertTrue (boldSource.textSources.first() is ItalicTextSource) - assertTrue (boldSource.textSources[1] is RegularTextSource) - assertTrue (boldSource.textSources[2] is StrikethroughTextSource) - assertTrue ((boldSource.textSources[2] as StrikethroughTextSource).textSources.first() is UnderlineTextSource) + assertTrue (boldSource.subsources.first() is ItalicTextSource) + assertTrue (boldSource.subsources[1] is RegularTextSource) + assertTrue (boldSource.subsources[2] is StrikethroughTextSource) + assertTrue ((boldSource.subsources[2] as StrikethroughTextSource).subsources.first() is UnderlineTextSource) } diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/chat_events/ChatEventsSourcesConversations.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/chat_events/ChatEventsSourcesConversations.kt index eabe98cddc..43504fef31 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/chat_events/ChatEventsSourcesConversations.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/chat_events/ChatEventsSourcesConversations.kt @@ -1,13 +1,13 @@ package dev.inmo.tgbotapi.extensions.utils.chat_events -import dev.inmo.tgbotapi.types.message.* +import dev.inmo.tgbotapi.extensions.utils.shortcuts.* import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.mapNotNull import kotlin.reflect.KClass - -fun Flow.divideBySource(contentType: KClass) = mapNotNull { +@Deprecated("Refactored, replaced and renamed", ReplaceWith("filterByChatEvent", "dev.inmo.tgbotapi.extensions.utils.shortcuts.filterByChatEvent")) +fun > Flow>.divideBySource(contentType: KClass) = mapNotNull { if (contentType.isInstance(it)) { @Suppress("UNCHECKED_CAST") it as T @@ -16,6 +16,9 @@ fun Flow.divideBySource(contentType: KC } } -fun Flow.onlyChannelEvents() = divideBySource(ChannelEventMessage::class) -fun Flow.onlyGroupEvents() = divideBySource(CommonGroupEventMessage::class) -fun Flow.onlySupergroupEvents() = divideBySource(CommonSupergroupEventMessage::class) +@Deprecated("Replaced and renamed", ReplaceWith("channelEvents", "dev.inmo.tgbotapi.extensions.utils.shortcuts.channelEvents")) +fun Flow>.onlyChannelEvents() = channelEvents() +@Deprecated("Replaced and renamed", ReplaceWith("groupEvents", "dev.inmo.tgbotapi.extensions.utils.shortcuts.groupEvents")) +fun Flow>.onlyGroupEvents() = groupEvents() +@Deprecated("Replaced and renamed", ReplaceWith("supergroupEvents", "dev.inmo.tgbotapi.extensions.utils.shortcuts.supergroupEvents")) +fun Flow>.onlySupergroupEvents() = supergroupEvents() diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/CommandsShortcuts.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/CommandsShortcuts.kt index 5a8181819e..f23f1aae33 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/CommandsShortcuts.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/CommandsShortcuts.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.extensions.utils.shortcuts import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.CommonAbstracts.textSources import dev.inmo.tgbotapi.extensions.utils.onlyTextContentMessages import dev.inmo.tgbotapi.extensions.utils.updates.asContentMessagesFlow import dev.inmo.tgbotapi.types.MessageEntity.textsources.BotCommandTextSource @@ -27,7 +28,7 @@ import kotlinx.coroutines.flow.* fun > Flow.filterExactCommands( commandRegex: Regex ) = filter { contentMessage -> - (contentMessage.content.fullEntitiesList().singleOrNull() as? BotCommandTextSource) ?.let { commandRegex.matches(it.command) } == true + (contentMessage.content.textSources.singleOrNull() as? BotCommandTextSource) ?.let { commandRegex.matches(it.command) } == true } /** @@ -46,7 +47,7 @@ fun > Flow.filterExactCommands( fun > Flow.filterCommandsInsideTextMessages( commandRegex: Regex ) = filter { contentMessage -> - contentMessage.content.fullEntitiesList().any { + contentMessage.content.textSources.any { (it as? BotCommandTextSource) ?.let { commandRegex.matches(it.command) } == true } } @@ -70,7 +71,7 @@ fun > Flow.filterCommandsInsideTextMessages( fun > Flow.filterCommandsWithArgs( commandRegex: Regex ) = mapNotNull { contentMessage -> - val allEntities = contentMessage.content.fullEntitiesList() + val allEntities = contentMessage.content.textSources (allEntities.firstOrNull() as? BotCommandTextSource) ?.let { if (commandRegex.matches(it.command)) { contentMessage to allEntities.flatMap { diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/EventsShortcuts.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/EventsShortcuts.kt new file mode 100644 index 0000000000..c9f0831301 --- /dev/null +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/EventsShortcuts.kt @@ -0,0 +1,98 @@ +@file:Suppress("NOTHING_TO_INLINE", "unused", "EXPERIMENTAL_API_USAGE") + +package dev.inmo.tgbotapi.extensions.utils.shortcuts + +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.abstracts.* +import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter +import dev.inmo.tgbotapi.utils.RiskFeature +import kotlinx.coroutines.flow.* + +@RiskFeature("Use with caution") +inline fun FlowsUpdatesFilter.events(): Flow> { + return channelPostFlow.mapNotNull { it.data as? ChatEventMessage<*> } + messageFlow.mapNotNull { it.data as? ChatEventMessage<*> } +} + +@RiskFeature("Use with caution") +inline fun FlowsUpdatesFilter.channelEvents(): Flow> = channelPostFlow.mapNotNull { + it.data as? ChannelEventMessage<*> +} + +@RiskFeature("Use with caution") +inline fun FlowsUpdatesFilter.groupEvents(): Flow> = messageFlow.mapNotNull { + it.data as? GroupEventMessage<*> +} + +@RiskFeature("Use with caution") +inline fun FlowsUpdatesFilter.supergroupEvents(): Flow> = messageFlow.mapNotNull { + it.data as? SupergroupEventMessage<*> +} + +@RiskFeature("Use with caution") +inline fun > Flow>.filterByChatEvent(): Flow = mapNotNull { + if (it.chatEvent is T) it as? O else null +} + +@RiskFeature("Use with caution") +inline fun Flow>.filterChannelEvents() = filterByChatEvent>() +@RiskFeature("Use with caution") +inline fun FlowsUpdatesFilter.filterChannelEvents() = channelEvents().filterChannelEvents() +inline fun Flow>.channelCreatedEvents() = filterChannelEvents() +inline fun FlowsUpdatesFilter.channelCreatedEvents() = filterChannelEvents() +inline fun Flow>.deletedChannelPhotoEvents() = filterChannelEvents() +inline fun FlowsUpdatesFilter.deletedChannelPhotoEvents() = filterChannelEvents() +inline fun Flow>.newChannelPhotoEvents() = filterChannelEvents() +inline fun FlowsUpdatesFilter.newChannelPhotoEvents() = filterChannelEvents() +inline fun Flow>.newChannelTitleEvents() = filterChannelEvents() +inline fun FlowsUpdatesFilter.newChannelTitleEvents() = filterChannelEvents() +inline fun Flow>.newChannelPinnedMessageEvents() = filterChannelEvents() +inline fun FlowsUpdatesFilter.newChannelPinnedMessageEvents() = filterChannelEvents() +inline fun Flow>.channelEvents() = filterChannelEvents() + +@RiskFeature("Use with caution") +inline fun Flow>.filterGroupEvents() = filterByChatEvent>() +@RiskFeature("Use with caution") +inline fun FlowsUpdatesFilter.filterGroupEvents() = groupEvents().filterByChatEvent>() +inline fun Flow>.groupCreatedEvents() = filterGroupEvents() +inline fun FlowsUpdatesFilter.groupCreatedEvents() = filterGroupEvents() +inline fun Flow>.deletedGroupPhotoEvents() = filterGroupEvents() +inline fun FlowsUpdatesFilter.deletedGroupPhotoEvents() = filterGroupEvents() +inline fun Flow>.newGroupMembersEvents() = filterGroupEvents() +inline fun FlowsUpdatesFilter.newGroupMembersEvents() = filterGroupEvents() +inline fun Flow>.leftGroupMemberEvents() = filterGroupEvents() +inline fun FlowsUpdatesFilter.leftGroupMemberEvents() = filterGroupEvents() +inline fun Flow>.newGroupPhotoEvents() = filterGroupEvents() +inline fun FlowsUpdatesFilter.newGroupPhotoEvents() = filterGroupEvents() +inline fun Flow>.newGroupTitleEvents() = filterGroupEvents() +inline fun FlowsUpdatesFilter.newGroupTitleEvents() = filterGroupEvents() +inline fun Flow>.newGroupPinnedMessageEvents() = filterGroupEvents() +inline fun FlowsUpdatesFilter.newGroupPinnedMessageEvents() = filterGroupEvents() +inline fun Flow>.proximityAlertTriggeredInGroupEvents() = filterGroupEvents() +inline fun FlowsUpdatesFilter.proximityAlertTriggeredInGroupEvents() = filterGroupEvents() +inline fun Flow>.groupEvents() = filterGroupEvents() + + +@RiskFeature("Use with caution") +inline fun Flow>.filterSupergroupEvents() = filterByChatEvent>() +@RiskFeature("Use with caution") +inline fun FlowsUpdatesFilter.filterSupergroupEvents() = supergroupEvents().filterByChatEvent>() +inline fun Flow>.supergroupCreatedEvents() = filterSupergroupEvents() +inline fun FlowsUpdatesFilter.supergroupCreatedEvents() = filterSupergroupEvents() +inline fun Flow>.deletedSupergroupPhotoEvents() = filterSupergroupEvents() +inline fun FlowsUpdatesFilter.deletedSupergroupPhotoEvents() = filterSupergroupEvents() +inline fun Flow>.newSupergroupMembersEvents() = filterSupergroupEvents() +inline fun FlowsUpdatesFilter.newSupergroupMembersEvents() = filterSupergroupEvents() +inline fun Flow>.leftSupergroupMemberEvents() = filterSupergroupEvents() +inline fun FlowsUpdatesFilter.leftSupergroupMemberEvents() = filterSupergroupEvents() +inline fun Flow>.newSupergroupPhotoEvents() = filterSupergroupEvents() +inline fun FlowsUpdatesFilter.newSupergroupPhotoEvents() = filterSupergroupEvents() +inline fun Flow>.newSupergroupTitleEvents() = filterSupergroupEvents() +inline fun FlowsUpdatesFilter.newSupergroupTitleEvents() = filterSupergroupEvents() +inline fun Flow>.newSupergroupPinnedMessageEvents() = filterSupergroupEvents() +inline fun FlowsUpdatesFilter.newSupergroupPinnedMessageEvents() = filterSupergroupEvents() +inline fun Flow>.proximityAlertTriggeredInSupergroupEvents() = filterSupergroupEvents() +inline fun FlowsUpdatesFilter.proximityAlertTriggeredInSupergroupEvents() = filterSupergroupEvents() +inline fun Flow>.supergroupEvents() = filterSupergroupEvents() diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/SentMessageUpdatesConversations.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/SentMessageUpdatesConversations.kt index 1e4549b09f..4ee4c8fc40 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/SentMessageUpdatesConversations.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/SentMessageUpdatesConversations.kt @@ -19,12 +19,15 @@ fun Flow.asCommonMessagesFlow() = mapNotNull { it.data as? CommonMessage<*> } +@Suppress("NOTHING_TO_INLINE") +inline fun Flow.chatEvents() = mapNotNull { + it.data as? ChatEventMessage<*> +} /** * Will map incoming [BaseSentMessageUpdate]s to [ChatEventMessage] from [BaseSentMessageUpdate.data] */ -fun Flow.asChatEventsFlow() = mapNotNull { - it.data as? ChatEventMessage -} +@Deprecated("Renamed", ReplaceWith("chatEvents", "dev.inmo.tgbotapi.extensions.utils.updates.chatEvents")) +fun Flow.asChatEventsFlow() = chatEvents() /** * Will map incoming [BaseSentMessageUpdate]s to [UnknownMessageType] from [BaseSentMessageUpdate.data]