From 36202133a1a4ff833094fbd166da8330059d8597 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 11 Mar 2021 21:06:25 +0600 Subject: [PATCH 01/49] update classcasts --- .../tgbotapi/extensions/utils/ClassCasts.kt | 135 ++++++++++++++++++ 1 file changed, 135 insertions(+) diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt index 5e27c2c544..708f85ae7d 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt @@ -48,6 +48,53 @@ import dev.inmo.tgbotapi.types.update.* import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.* import dev.inmo.tgbotapi.types.update.abstracts.* import dev.inmo.tgbotapi.utils.PreviewFeature +import dev.inmo.tgbotapi.types.dice.DiceAnimationType +import dev.inmo.tgbotapi.types.update.abstracts.Update +import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.ChatEvent +import dev.inmo.tgbotapi.types.update.CallbackQueryUpdate +import dev.inmo.tgbotapi.types.update.ChannelPostUpdate +import dev.inmo.tgbotapi.types.update.ChosenInlineResultUpdate +import dev.inmo.tgbotapi.types.update.CommonChatMemberUpdatedUpdate +import dev.inmo.tgbotapi.types.update.EditChannelPostUpdate +import dev.inmo.tgbotapi.types.update.EditMessageUpdate +import dev.inmo.tgbotapi.types.update.InlineQueryUpdate +import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.ChannelPostMediaGroupUpdate +import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.EditChannelPostMediaGroupUpdate +import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.EditMediaGroupUpdate +import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.EditMessageMediaGroupUpdate +import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.MediaGroupUpdate +import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.MessageMediaGroupUpdate +import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.SentMediaGroupUpdate +import dev.inmo.tgbotapi.types.update.MessageUpdate +import dev.inmo.tgbotapi.types.update.MyChatMemberUpdatedUpdate +import dev.inmo.tgbotapi.types.update.PollAnswerUpdate +import dev.inmo.tgbotapi.types.update.PollUpdate +import dev.inmo.tgbotapi.types.update.PreCheckoutQueryUpdate +import dev.inmo.tgbotapi.types.update.ShippingQueryUpdate +import dev.inmo.tgbotapi.types.update.abstracts.BaseEditMessageUpdate +import dev.inmo.tgbotapi.types.update.abstracts.BaseMessageUpdate +import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate +import dev.inmo.tgbotapi.types.update.abstracts.ChatMemberUpdatedUpdate +import dev.inmo.tgbotapi.types.update.abstracts.UnknownUpdate +import dev.inmo.tgbotapi.types.message.ChatEvents.ChannelChatCreated +import dev.inmo.tgbotapi.types.message.ChatEvents.DeleteChatPhoto +import dev.inmo.tgbotapi.types.message.ChatEvents.GroupChatCreated +import dev.inmo.tgbotapi.types.message.ChatEvents.LeftChatMember +import dev.inmo.tgbotapi.types.message.ChatEvents.MessageAutoDeleteTimerChanged +import dev.inmo.tgbotapi.types.message.ChatEvents.NewChatMembers +import dev.inmo.tgbotapi.types.message.ChatEvents.NewChatPhoto +import dev.inmo.tgbotapi.types.message.ChatEvents.NewChatTitle +import dev.inmo.tgbotapi.types.message.ChatEvents.PinnedMessage +import dev.inmo.tgbotapi.types.message.ChatEvents.ProximityAlertTriggered +import dev.inmo.tgbotapi.types.message.ChatEvents.SupergroupChatCreated +import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.ChannelEvent +import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.CommonEvent +import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.GroupEvent +import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.SupergroupEvent +import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.VoiceChatEvent +import dev.inmo.tgbotapi.types.message.ChatEvents.voice.VoiceChatEnded +import dev.inmo.tgbotapi.types.message.ChatEvents.voice.VoiceChatParticipantsInvited +import dev.inmo.tgbotapi.types.message.ChatEvents.voice.VoiceChatStarted @PreviewFeature inline fun Chat.asBot(): Bot? = this as? Bot @@ -938,6 +985,18 @@ inline fun Update.asUnknownUpdate(): UnknownUpdate? = this as? UnknownUpdate @PreviewFeature inline fun Update.requireUnknownUpdate(): UnknownUpdate = this as UnknownUpdate @PreviewFeature +inline fun Update.asCommonChatMemberUpdatedUpdate(): CommonChatMemberUpdatedUpdate? = this as? CommonChatMemberUpdatedUpdate +@PreviewFeature +inline fun Update.requireCommonChatMemberUpdatedUpdate(): CommonChatMemberUpdatedUpdate = this as CommonChatMemberUpdatedUpdate +@PreviewFeature +inline fun Update.asMyChatMemberUpdatedUpdate(): MyChatMemberUpdatedUpdate? = this as? MyChatMemberUpdatedUpdate +@PreviewFeature +inline fun Update.requireMyChatMemberUpdatedUpdate(): MyChatMemberUpdatedUpdate = this as MyChatMemberUpdatedUpdate +@PreviewFeature +inline fun Update.asChatMemberUpdatedUpdate(): ChatMemberUpdatedUpdate? = this as? ChatMemberUpdatedUpdate +@PreviewFeature +inline fun Update.requireChatMemberUpdatedUpdate(): ChatMemberUpdatedUpdate = this as ChatMemberUpdatedUpdate +@PreviewFeature inline fun TelegramMediaFile.asAnimationFile(): AnimationFile? = this as? AnimationFile @PreviewFeature inline fun TelegramMediaFile.requireAnimationFile(): AnimationFile = this as AnimationFile @@ -1245,3 +1304,79 @@ inline fun DiceAnimationType.requireFootballDiceAnimationType(): FootballDiceAni inline fun DiceAnimationType.asSlotMachineDiceAnimationType(): SlotMachineDiceAnimationType? = this as? SlotMachineDiceAnimationType @PreviewFeature inline fun DiceAnimationType.requireSlotMachineDiceAnimationType(): SlotMachineDiceAnimationType = this as SlotMachineDiceAnimationType +@PreviewFeature +inline fun ChatEvent.asChannelChatCreated(): ChannelChatCreated? = this as? ChannelChatCreated +@PreviewFeature +inline fun ChatEvent.requireChannelChatCreated(): ChannelChatCreated = this as ChannelChatCreated +@PreviewFeature +inline fun ChatEvent.asDeleteChatPhoto(): DeleteChatPhoto? = this as? DeleteChatPhoto +@PreviewFeature +inline fun ChatEvent.requireDeleteChatPhoto(): DeleteChatPhoto = this as DeleteChatPhoto +@PreviewFeature +inline fun ChatEvent.asGroupChatCreated(): GroupChatCreated? = this as? GroupChatCreated +@PreviewFeature +inline fun ChatEvent.requireGroupChatCreated(): GroupChatCreated = this as GroupChatCreated +@PreviewFeature +inline fun ChatEvent.asLeftChatMember(): LeftChatMember? = this as? LeftChatMember +@PreviewFeature +inline fun ChatEvent.requireLeftChatMember(): LeftChatMember = this as LeftChatMember +@PreviewFeature +inline fun ChatEvent.asMessageAutoDeleteTimerChanged(): MessageAutoDeleteTimerChanged? = this as? MessageAutoDeleteTimerChanged +@PreviewFeature +inline fun ChatEvent.requireMessageAutoDeleteTimerChanged(): MessageAutoDeleteTimerChanged = this as MessageAutoDeleteTimerChanged +@PreviewFeature +inline fun ChatEvent.asNewChatMembers(): NewChatMembers? = this as? NewChatMembers +@PreviewFeature +inline fun ChatEvent.requireNewChatMembers(): NewChatMembers = this as NewChatMembers +@PreviewFeature +inline fun ChatEvent.asNewChatPhoto(): NewChatPhoto? = this as? NewChatPhoto +@PreviewFeature +inline fun ChatEvent.requireNewChatPhoto(): NewChatPhoto = this as NewChatPhoto +@PreviewFeature +inline fun ChatEvent.asNewChatTitle(): NewChatTitle? = this as? NewChatTitle +@PreviewFeature +inline fun ChatEvent.requireNewChatTitle(): NewChatTitle = this as NewChatTitle +@PreviewFeature +inline fun ChatEvent.asPinnedMessage(): PinnedMessage? = this as? PinnedMessage +@PreviewFeature +inline fun ChatEvent.requirePinnedMessage(): PinnedMessage = this as PinnedMessage +@PreviewFeature +inline fun ChatEvent.asProximityAlertTriggered(): ProximityAlertTriggered? = this as? ProximityAlertTriggered +@PreviewFeature +inline fun ChatEvent.requireProximityAlertTriggered(): ProximityAlertTriggered = this as ProximityAlertTriggered +@PreviewFeature +inline fun ChatEvent.asSupergroupChatCreated(): SupergroupChatCreated? = this as? SupergroupChatCreated +@PreviewFeature +inline fun ChatEvent.requireSupergroupChatCreated(): SupergroupChatCreated = this as SupergroupChatCreated +@PreviewFeature +inline fun ChatEvent.asChannelEvent(): ChannelEvent? = this as? ChannelEvent +@PreviewFeature +inline fun ChatEvent.requireChannelEvent(): ChannelEvent = this as ChannelEvent +@PreviewFeature +inline fun ChatEvent.asCommonEvent(): CommonEvent? = this as? CommonEvent +@PreviewFeature +inline fun ChatEvent.requireCommonEvent(): CommonEvent = this as CommonEvent +@PreviewFeature +inline fun ChatEvent.asGroupEvent(): GroupEvent? = this as? GroupEvent +@PreviewFeature +inline fun ChatEvent.requireGroupEvent(): GroupEvent = this as GroupEvent +@PreviewFeature +inline fun ChatEvent.asSupergroupEvent(): SupergroupEvent? = this as? SupergroupEvent +@PreviewFeature +inline fun ChatEvent.requireSupergroupEvent(): SupergroupEvent = this as SupergroupEvent +@PreviewFeature +inline fun ChatEvent.asVoiceChatEvent(): VoiceChatEvent? = this as? VoiceChatEvent +@PreviewFeature +inline fun ChatEvent.requireVoiceChatEvent(): VoiceChatEvent = this as VoiceChatEvent +@PreviewFeature +inline fun ChatEvent.asVoiceChatEnded(): VoiceChatEnded? = this as? VoiceChatEnded +@PreviewFeature +inline fun ChatEvent.requireVoiceChatEnded(): VoiceChatEnded = this as VoiceChatEnded +@PreviewFeature +inline fun ChatEvent.asVoiceChatParticipantsInvited(): VoiceChatParticipantsInvited? = this as? VoiceChatParticipantsInvited +@PreviewFeature +inline fun ChatEvent.requireVoiceChatParticipantsInvited(): VoiceChatParticipantsInvited = this as VoiceChatParticipantsInvited +@PreviewFeature +inline fun ChatEvent.asVoiceChatStarted(): VoiceChatStarted? = this as? VoiceChatStarted +@PreviewFeature +inline fun ChatEvent.requireVoiceChatStarted(): VoiceChatStarted = this as VoiceChatStarted From 65cba0f014e52e19b32580a25fd918b0b2058958 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 11 Mar 2021 21:25:11 +0600 Subject: [PATCH 02/49] fill api of chat invite links --- .../chat/abstracts/ChatInviteLinkRequest.kt | 2 +- .../chat/invite_links/CreateChatInviteLink.kt | 8 +-- .../chat/invite_links/EditChatInviteLink.kt | 10 +-- .../chat/invite_links/RevokeChatInviteLink.kt | 2 +- .../chat/invite_links/CreateChatInviteLink.kt | 31 +++++++++ .../chat/invite_links/EditChatInviteLink.kt | 64 +++++++++++++++++++ .../chat/invite_links/RevokeChatInviteLink.kt | 27 ++++++++ 7 files changed, 133 insertions(+), 11 deletions(-) create mode 100644 tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/invite_links/CreateChatInviteLink.kt create mode 100644 tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/invite_links/EditChatInviteLink.kt create mode 100644 tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/invite_links/RevokeChatInviteLink.kt diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/abstracts/ChatInviteLinkRequest.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/abstracts/ChatInviteLinkRequest.kt index a56d8c5523..a45d428a8d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/abstracts/ChatInviteLinkRequest.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/abstracts/ChatInviteLinkRequest.kt @@ -6,7 +6,7 @@ import dev.inmo.tgbotapi.types.* import kotlinx.serialization.DeserializationStrategy interface ChatInviteLinkRequest : SimpleRequest { - val chatId: ChatId + val chatId: ChatIdentifier override val resultDeserializer: DeserializationStrategy get() = CommonInviteLink.serializer() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/invite_links/CreateChatInviteLink.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/invite_links/CreateChatInviteLink.kt index 32ff101b0e..a6212c4a44 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/invite_links/CreateChatInviteLink.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/invite_links/CreateChatInviteLink.kt @@ -8,14 +8,14 @@ import kotlinx.serialization.* @Serializable data class CreateChatInviteLink( @SerialName(chatIdField) - override val chatId: ChatId, + override val chatId: ChatIdentifier, @SerialName(expireDateField) - private val expirationUnixTimeStamp: UnixTimeStamp? = null, + private val expirationUnixTimeStamp: TelegramDate? = null, @SerialName(memberLimitField) override val membersLimit: MembersLimit? = null ) : EditChatInviteLinkRequest { override val expireDate: DateTime? - get() = expirationUnixTimeStamp ?.seconds ?.let { DateTime(it.milliseconds) } + get() = expirationUnixTimeStamp ?.asDate override val requestSerializer: SerializationStrategy<*> get() = serializer() @@ -27,5 +27,5 @@ fun CreateChatInviteLink( expireDate: DateTime, membersLimit: MembersLimit? = null ): CreateChatInviteLink = CreateChatInviteLink( - chatId, expireDate.unixMillisDouble.milliseconds.seconds.toLong(), membersLimit + chatId, expireDate.toTelegramDate(), membersLimit ) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/invite_links/EditChatInviteLink.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/invite_links/EditChatInviteLink.kt index 2e6c7e2bce..3ea6fc0eda 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/invite_links/EditChatInviteLink.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/invite_links/EditChatInviteLink.kt @@ -9,16 +9,16 @@ import kotlinx.serialization.* @Serializable data class EditChatInviteLink( @SerialName(chatIdField) - override val chatId: ChatId, + override val chatId: ChatIdentifier, @SerialName(inviteLinkField) override val inviteLink: String, @SerialName(expireDateField) - private val expirationUnixTimeStamp: UnixTimeStamp? = null, + private val expirationUnixTimeStamp: TelegramDate? = null, @SerialName(memberLimitField) override val membersLimit: MembersLimit? = null ) : EditChatInviteLinkRequest, KnownChatInviteLinkRequest { override val expireDate: DateTime? - get() = expirationUnixTimeStamp ?.seconds ?.let { DateTime(it.milliseconds) } + get() = expirationUnixTimeStamp ?.asDate override val requestSerializer: SerializationStrategy<*> get() = serializer() @@ -26,10 +26,10 @@ data class EditChatInviteLink( } fun EditChatInviteLink( - chatId: ChatId, + chatId: ChatIdentifier, inviteLink: String, expireDate: DateTime, membersLimit: MembersLimit? = null ): EditChatInviteLink = EditChatInviteLink( - chatId, inviteLink, expireDate.unixMillisDouble.milliseconds.seconds.toLong(), membersLimit + chatId, inviteLink, expireDate.toTelegramDate(), membersLimit ) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/invite_links/RevokeChatInviteLink.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/invite_links/RevokeChatInviteLink.kt index 9d14035c37..617f181e2a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/invite_links/RevokeChatInviteLink.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/invite_links/RevokeChatInviteLink.kt @@ -9,7 +9,7 @@ import kotlinx.serialization.* @Serializable data class RevokeChatInviteLink( @SerialName(chatIdField) - override val chatId: ChatId, + override val chatId: ChatIdentifier, @SerialName(inviteLinkField) override val inviteLink: String ) : KnownChatInviteLinkRequest { diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/invite_links/CreateChatInviteLink.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/invite_links/CreateChatInviteLink.kt new file mode 100644 index 0000000000..93ed35d244 --- /dev/null +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/invite_links/CreateChatInviteLink.kt @@ -0,0 +1,31 @@ +package dev.inmo.tgbotapi.extensions.api.chat.invite_links + +import com.soywiz.klock.DateTime +import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.requests.chat.invite_links.CreateChatInviteLink +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat + +suspend fun TelegramBot.createChatInviteLink( + chatId: ChatIdentifier, + expiration: TelegramDate? = null, + membersLimit: MembersLimit? = null +) = execute(CreateChatInviteLink(chatId, expiration, membersLimit)) + +suspend fun TelegramBot.createChatInviteLink( + chat: PublicChat, + expiration: TelegramDate? = null, + membersLimit: MembersLimit? = null +) = createChatInviteLink(chat.id, expiration, membersLimit) + +suspend fun TelegramBot.createChatInviteLink( + chatId: ChatIdentifier, + expiration: DateTime, + membersLimit: MembersLimit? = null +) = createChatInviteLink(chatId, expiration.toTelegramDate(), membersLimit) + +suspend fun TelegramBot.createChatInviteLink( + chat: PublicChat, + expiration: DateTime, + membersLimit: MembersLimit? = null +) = createChatInviteLink(chat.id, expiration.toTelegramDate(), membersLimit) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/invite_links/EditChatInviteLink.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/invite_links/EditChatInviteLink.kt new file mode 100644 index 0000000000..c5fdf01154 --- /dev/null +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/invite_links/EditChatInviteLink.kt @@ -0,0 +1,64 @@ +package dev.inmo.tgbotapi.extensions.api.chat.invite_links + +import com.soywiz.klock.DateTime +import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.requests.chat.invite_links.CreateChatInviteLink +import dev.inmo.tgbotapi.requests.chat.invite_links.EditChatInviteLink +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat + +suspend fun TelegramBot.editChatInviteLink( + chatId: ChatIdentifier, + previousLink: String, + expiration: TelegramDate? = null, + membersLimit: MembersLimit? = null +) = execute(EditChatInviteLink(chatId, previousLink, expiration, membersLimit)) + +suspend fun TelegramBot.editChatInviteLink( + chat: PublicChat, + previousLink: String, + expiration: TelegramDate? = null, + membersLimit: MembersLimit? = null +) = editChatInviteLink(chat.id, previousLink, expiration, membersLimit) + +suspend fun TelegramBot.editChatInviteLink( + chatId: ChatIdentifier, + previousLink: String, + expiration: DateTime, + membersLimit: MembersLimit? = null +) = editChatInviteLink(chatId, previousLink, expiration.toTelegramDate(), membersLimit) + +suspend fun TelegramBot.editChatInviteLink( + chat: PublicChat, + previousLink: String, + expiration: DateTime, + membersLimit: MembersLimit? = null +) = editChatInviteLink(chat.id, previousLink, expiration.toTelegramDate(), membersLimit) + +suspend fun TelegramBot.editChatInviteLink( + chat: ChatIdentifier, + previousLink: ChatInviteLink, + expiration: TelegramDate? = previousLink.expirationDateTime ?.toTelegramDate(), + membersLimit: MembersLimit? = previousLink.membersLimit +) = editChatInviteLink(chat, previousLink.inviteLink, expiration, membersLimit) + +suspend fun TelegramBot.editChatInviteLink( + chat: ChatIdentifier, + previousLink: ChatInviteLink, + expiration: DateTime, + membersLimit: MembersLimit? = previousLink.membersLimit +) = editChatInviteLink(chat, previousLink.inviteLink, expiration, membersLimit) + +suspend fun TelegramBot.editChatInviteLink( + chat: PublicChat, + previousLink: ChatInviteLink, + expiration: TelegramDate? = previousLink.expirationDateTime ?.toTelegramDate(), + membersLimit: MembersLimit? = previousLink.membersLimit +) = editChatInviteLink(chat, previousLink.inviteLink, expiration, membersLimit) + +suspend fun TelegramBot.editChatInviteLink( + chat: PublicChat, + previousLink: ChatInviteLink, + expiration: DateTime, + membersLimit: MembersLimit? = previousLink.membersLimit +) = editChatInviteLink(chat, previousLink.inviteLink, expiration, membersLimit) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/invite_links/RevokeChatInviteLink.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/invite_links/RevokeChatInviteLink.kt new file mode 100644 index 0000000000..4e2a4edeee --- /dev/null +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/invite_links/RevokeChatInviteLink.kt @@ -0,0 +1,27 @@ +package dev.inmo.tgbotapi.extensions.api.chat.invite_links + +import com.soywiz.klock.DateTime +import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.requests.chat.invite_links.* +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat + +suspend fun TelegramBot.revokeChatInviteLink( + chatId: ChatIdentifier, + previousLink: String +) = execute(RevokeChatInviteLink(chatId, previousLink)) + +suspend fun TelegramBot.revokeChatInviteLink( + chat: PublicChat, + previousLink: String +) = revokeChatInviteLink(chat.id, previousLink) + +suspend fun TelegramBot.revokeChatInviteLink( + chatId: ChatIdentifier, + previousLink: ChatInviteLink +) = revokeChatInviteLink(chatId, previousLink.inviteLink) + +suspend fun TelegramBot.revokeChatInviteLink( + chat: PublicChat, + previousLink: ChatInviteLink +) = revokeChatInviteLink(chat, previousLink.inviteLink) From e9b074a36c54e62f22fa896f50ae306a754373c2 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 11 Mar 2021 21:36:29 +0600 Subject: [PATCH 03/49] updates of FlowsUpdatesFilter --- .../dev/inmo/tgbotapi/updateshandlers/FlowsUpdatesFilter.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/updateshandlers/FlowsUpdatesFilter.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/updateshandlers/FlowsUpdatesFilter.kt index b07bc97cf6..9b86454801 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/updateshandlers/FlowsUpdatesFilter.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/updateshandlers/FlowsUpdatesFilter.kt @@ -28,6 +28,8 @@ interface FlowsUpdatesFilter : UpdatesFilter { val preCheckoutQueryFlow: Flow val pollFlow: Flow val pollAnswerFlow: Flow + val chatMemberUpdatedFlow: Flow + val myChatMemberUpdatedFlow: Flow val unknownUpdateTypeFlow: Flow } @@ -74,5 +76,7 @@ class DefaultFlowsUpdatesFilter( override val preCheckoutQueryFlow: Flow = allUpdatesFlow.filterIsInstance() override val pollFlow: Flow = allUpdatesFlow.filterIsInstance() override val pollAnswerFlow: Flow = allUpdatesFlow.filterIsInstance() + override val chatMemberUpdatedFlow: Flow = allUpdatesFlow.filterIsInstance() + override val myChatMemberUpdatedFlow: Flow = allUpdatesFlow.filterIsInstance() override val unknownUpdateTypeFlow: Flow = allUpdatesFlow.filterIsInstance() } \ No newline at end of file From d7d4adc8e4608b99040acefd895bfd0a5bb2e835 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 11 Mar 2021 21:39:34 +0600 Subject: [PATCH 04/49] optimize imports --- .../requests/SetPassportDataErrors.kt | 1 - .../chat/invite_links/CreateChatInviteLink.kt | 2 +- .../chat/invite_links/EditChatInviteLink.kt | 2 +- .../chat/invite_links/RevokeChatInviteLink.kt | 2 - .../tgbotapi/requests/send/polls/SendPoll.kt | 1 - .../dev/inmo/tgbotapi/types/ChatIdentifier.kt | 1 - .../dev/inmo/tgbotapi/types/ChatInviteLink.kt | 2 +- .../MessageAutoDeleteTimerChanged.kt | 1 - .../types/message/PrivateMessageImpl.kt | 3 +- .../types/message/content/TextContent.kt | 3 +- .../types/passport/encrypted/Email.kt | 2 +- .../passport/encrypted/EncryptedAddress.kt | 2 +- .../encrypted/EncryptedPersonalDetails.kt | 2 +- .../types/passport/encrypted/PhoneNumber.kt | 2 +- .../utils/passport/DecryptionContext.kt | 7 --- .../utils/passport/CredentialsDecrypting.kt | 5 +- .../chat/invite_links/EditChatInviteLink.kt | 1 - .../chat/invite_links/RevokeChatInviteLink.kt | 6 +-- .../api/send/media/SendMediaGroup.kt | 1 - .../expectations/WaitEventAction.kt | 3 +- .../expectations/WaitInlineQuery.kt | 2 - .../expectations/WaitPassportData.kt | 3 +- .../CallbackQueryTriggers.kt | 2 +- .../triggers_handling/EventTriggers.kt | 3 +- .../triggers_handling/InlineQueryTriggers.kt | 2 - .../triggers_handling/MediaGroupTriggers.kt | 5 +- .../triggers_handling/PassportTriggers.kt | 3 +- .../tgbotapi/extensions/utils/ClassCasts.kt | 50 ++----------------- .../utils/updates/retrieving/LongPolling.kt | 2 - .../updates/retrieving/MediaGroupsIncluder.kt | 1 - 30 files changed, 31 insertions(+), 91 deletions(-) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/SetPassportDataErrors.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/SetPassportDataErrors.kt index 80a039fd40..34a6deb85f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/SetPassportDataErrors.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/SetPassportDataErrors.kt @@ -1,6 +1,5 @@ package dev.inmo.tgbotapi.requests -import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.passport.PassportElementError diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/invite_links/CreateChatInviteLink.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/invite_links/CreateChatInviteLink.kt index a6212c4a44..4a87ef49c7 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/invite_links/CreateChatInviteLink.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/invite_links/CreateChatInviteLink.kt @@ -1,6 +1,6 @@ package dev.inmo.tgbotapi.requests.chat.invite_links -import com.soywiz.klock.* +import com.soywiz.klock.DateTime import dev.inmo.tgbotapi.requests.chat.abstracts.EditChatInviteLinkRequest import dev.inmo.tgbotapi.types.* import kotlinx.serialization.* diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/invite_links/EditChatInviteLink.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/invite_links/EditChatInviteLink.kt index 3ea6fc0eda..fdeb3b55e1 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/invite_links/EditChatInviteLink.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/invite_links/EditChatInviteLink.kt @@ -1,6 +1,6 @@ package dev.inmo.tgbotapi.requests.chat.invite_links -import com.soywiz.klock.* +import com.soywiz.klock.DateTime import dev.inmo.tgbotapi.requests.chat.abstracts.EditChatInviteLinkRequest import dev.inmo.tgbotapi.requests.chat.abstracts.KnownChatInviteLinkRequest import dev.inmo.tgbotapi.types.* diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/invite_links/RevokeChatInviteLink.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/invite_links/RevokeChatInviteLink.kt index 617f181e2a..31a8993666 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/invite_links/RevokeChatInviteLink.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/invite_links/RevokeChatInviteLink.kt @@ -1,7 +1,5 @@ package dev.inmo.tgbotapi.requests.chat.invite_links -import com.soywiz.klock.* -import dev.inmo.tgbotapi.requests.chat.abstracts.EditChatInviteLinkRequest import dev.inmo.tgbotapi.requests.chat.abstracts.KnownChatInviteLinkRequest import dev.inmo.tgbotapi.types.* import kotlinx.serialization.* diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendPoll.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendPoll.kt index d4bfd445cf..2af52017ef 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendPoll.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/polls/SendPoll.kt @@ -1,7 +1,6 @@ package dev.inmo.tgbotapi.requests.send.polls import com.soywiz.klock.DateTime -import com.soywiz.klock.TimeSpan import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.requests.send.abstracts.ReplyingMarkupSendMessageRequest import dev.inmo.tgbotapi.requests.send.abstracts.SendMessageRequest diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt index bdd251b7ed..3633593f94 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatIdentifier.kt @@ -1,7 +1,6 @@ package dev.inmo.tgbotapi.types import dev.inmo.micro_utils.common.Warning -import dev.inmo.tgbotapi.types.chat.abstracts.Chat import kotlinx.serialization.* import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatInviteLink.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatInviteLink.kt index fe6a0d094c..fe4bc031e7 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatInviteLink.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatInviteLink.kt @@ -1,6 +1,6 @@ package dev.inmo.tgbotapi.types -import com.soywiz.klock.* +import com.soywiz.klock.DateTime import kotlinx.serialization.* import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/MessageAutoDeleteTimerChanged.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/MessageAutoDeleteTimerChanged.kt index fdd7e264d1..3144e466cc 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/MessageAutoDeleteTimerChanged.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChatEvents/MessageAutoDeleteTimerChanged.kt @@ -1,6 +1,5 @@ package dev.inmo.tgbotapi.types.message.ChatEvents -import com.soywiz.klock.hours import dev.inmo.tgbotapi.types.Seconds import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.* import dev.inmo.tgbotapi.types.messageAutoDeleteTimeField diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateMessageImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateMessageImpl.kt index 94438537e2..94cd9fea81 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateMessageImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateMessageImpl.kt @@ -4,7 +4,8 @@ import com.soywiz.klock.DateTime import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.chat.abstracts.Chat -import dev.inmo.tgbotapi.types.message.abstracts.* +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 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 2d098ebc64..915c875a69 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 @@ -5,7 +5,8 @@ import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.requests.send.SendTextMessage import dev.inmo.tgbotapi.types.ChatIdentifier import dev.inmo.tgbotapi.types.MessageIdentifier -import dev.inmo.tgbotapi.types.ParseMode.* +import dev.inmo.tgbotapi.types.ParseMode.ParseMode +import dev.inmo.tgbotapi.types.ParseMode.defaultParseMode import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/Email.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/Email.kt index a8ed36220e..707a87f62f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/Email.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/Email.kt @@ -3,8 +3,8 @@ package dev.inmo.tgbotapi.types.passport.encrypted import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer import dev.inmo.tgbotapi.types.emailField import dev.inmo.tgbotapi.types.hashField -import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.PassportElementHash import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportElementWithEmail +import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.PassportElementHash import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/EncryptedAddress.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/EncryptedAddress.kt index 3e3f1d2010..5b2cec3eb1 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/EncryptedAddress.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/EncryptedAddress.kt @@ -3,8 +3,8 @@ package dev.inmo.tgbotapi.types.passport.encrypted import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer import dev.inmo.tgbotapi.types.dataField import dev.inmo.tgbotapi.types.passport.credentials.EncryptedData -import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.PassportElementHash import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportElementWithData +import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.PassportElementHash import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/EncryptedPersonalDetails.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/EncryptedPersonalDetails.kt index fe1142a7e4..1df8d90be5 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/EncryptedPersonalDetails.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/EncryptedPersonalDetails.kt @@ -3,8 +3,8 @@ package dev.inmo.tgbotapi.types.passport.encrypted import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer import dev.inmo.tgbotapi.types.dataField import dev.inmo.tgbotapi.types.passport.credentials.EncryptedData -import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.PassportElementHash import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportElementWithData +import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.PassportElementHash import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/PhoneNumber.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/PhoneNumber.kt index 88dc723765..d6cc0df603 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/PhoneNumber.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/PhoneNumber.kt @@ -2,8 +2,8 @@ package dev.inmo.tgbotapi.types.passport.encrypted import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer import dev.inmo.tgbotapi.types.hashField -import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.PassportElementHash import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportElementWithPhoneNumber +import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.PassportElementHash import dev.inmo.tgbotapi.types.phoneNumberField import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContext.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContext.kt index f179e3f627..57654fcfb7 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContext.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContext.kt @@ -1,14 +1,7 @@ package dev.inmo.tgbotapi.utils.passport import dev.inmo.micro_utils.crypto.SourceBytes -import dev.inmo.tgbotapi.bot.TelegramBot -import dev.inmo.tgbotapi.requests.DownloadFile -import dev.inmo.tgbotapi.requests.get.GetFile -import dev.inmo.tgbotapi.types.passport.credentials.EncryptedCredentials import dev.inmo.tgbotapi.types.passport.credentials.EncryptedData -import dev.inmo.tgbotapi.types.passport.encrypted.PassportFile -import dev.inmo.tgbotapi.utils.nonstrictJsonFormat -import kotlinx.serialization.json.JsonObject interface Decryptor { fun decrypt(data: EncryptedData): SourceBytes diff --git a/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/CredentialsDecrypting.kt b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/CredentialsDecrypting.kt index 7639ee5845..e150cc7f78 100644 --- a/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/CredentialsDecrypting.kt +++ b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/CredentialsDecrypting.kt @@ -4,11 +4,10 @@ import dev.inmo.micro_utils.crypto.decodeBase64 import dev.inmo.tgbotapi.types.passport.credentials.DecryptedCredentials import dev.inmo.tgbotapi.types.passport.credentials.EncryptedCredentials import dev.inmo.tgbotapi.utils.nonstrictJsonFormat -import java.security.* +import java.security.KeyFactory +import java.security.PrivateKey import java.security.spec.PKCS8EncodedKeySpec import javax.crypto.Cipher -import javax.crypto.spec.IvParameterSpec -import javax.crypto.spec.SecretKeySpec private val regexToRemoveFromKey = Regex("(-----(BEGIN|END) ((?:.*? KEY)|CERTIFICATE)-----|[\\s])") diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/invite_links/EditChatInviteLink.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/invite_links/EditChatInviteLink.kt index c5fdf01154..027a54360f 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/invite_links/EditChatInviteLink.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/invite_links/EditChatInviteLink.kt @@ -2,7 +2,6 @@ package dev.inmo.tgbotapi.extensions.api.chat.invite_links import com.soywiz.klock.DateTime import dev.inmo.tgbotapi.bot.TelegramBot -import dev.inmo.tgbotapi.requests.chat.invite_links.CreateChatInviteLink import dev.inmo.tgbotapi.requests.chat.invite_links.EditChatInviteLink import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/invite_links/RevokeChatInviteLink.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/invite_links/RevokeChatInviteLink.kt index 4e2a4edeee..320e29fa08 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/invite_links/RevokeChatInviteLink.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/chat/invite_links/RevokeChatInviteLink.kt @@ -1,9 +1,9 @@ package dev.inmo.tgbotapi.extensions.api.chat.invite_links -import com.soywiz.klock.DateTime import dev.inmo.tgbotapi.bot.TelegramBot -import dev.inmo.tgbotapi.requests.chat.invite_links.* -import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.requests.chat.invite_links.RevokeChatInviteLink +import dev.inmo.tgbotapi.types.ChatIdentifier +import dev.inmo.tgbotapi.types.ChatInviteLink import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat suspend fun TelegramBot.revokeChatInviteLink( diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendMediaGroup.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendMediaGroup.kt index e8cf10588f..01b8bb5077 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendMediaGroup.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendMediaGroup.kt @@ -8,7 +8,6 @@ import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.chat.abstracts.Chat import dev.inmo.tgbotapi.types.message.abstracts.Message import dev.inmo.tgbotapi.types.message.content.abstracts.MediaGroupContent -import dev.inmo.tgbotapi.types.message.content.abstracts.VisualMediaGroupContent import dev.inmo.tgbotapi.utils.RiskFeature /** diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventAction.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventAction.kt index 308c5dbd39..53fee66475 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventAction.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitEventAction.kt @@ -3,7 +3,8 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext -import dev.inmo.tgbotapi.extensions.utils.* +import dev.inmo.tgbotapi.extensions.utils.asBaseSentMessageUpdate +import dev.inmo.tgbotapi.extensions.utils.asChatEventMessage import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.types.message.ChatEvents.* import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.* diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitInlineQuery.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitInlineQuery.kt index 009af3d38a..1e34de13eb 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitInlineQuery.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitInlineQuery.kt @@ -1,10 +1,8 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext -import dev.inmo.tgbotapi.extensions.utils.asCallbackQueryUpdate import dev.inmo.tgbotapi.extensions.utils.asInlineQueryUpdate import dev.inmo.tgbotapi.requests.abstracts.Request -import dev.inmo.tgbotapi.types.CallbackQuery.* import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InlineQuery import dev.inmo.tgbotapi.types.InlineQueries.query.BaseInlineQuery import dev.inmo.tgbotapi.types.InlineQueries.query.LocationInlineQuery diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitPassportData.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitPassportData.kt index 309a4705d0..c77cd0381b 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitPassportData.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitPassportData.kt @@ -1,7 +1,8 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext -import dev.inmo.tgbotapi.extensions.utils.* +import dev.inmo.tgbotapi.extensions.utils.asMessageUpdate +import dev.inmo.tgbotapi.extensions.utils.asPassportMessage import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.types.message.PassportMessage import dev.inmo.tgbotapi.types.passport.PassportData diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggers.kt index d66c64eab8..8e0f9724f8 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggers.kt @@ -4,7 +4,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow -import dev.inmo.tgbotapi.extensions.utils.* +import dev.inmo.tgbotapi.extensions.utils.asCallbackQueryUpdate import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat import dev.inmo.tgbotapi.types.CallbackQuery.* diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt index fdea3f9a0a..6940426c78 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt @@ -4,7 +4,8 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow -import dev.inmo.tgbotapi.extensions.utils.* +import dev.inmo.tgbotapi.extensions.utils.asBaseSentMessageUpdate +import dev.inmo.tgbotapi.extensions.utils.asChatEventMessage import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat import dev.inmo.tgbotapi.types.message.ChatEvents.* import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.* diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/InlineQueryTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/InlineQueryTriggers.kt index e85f2cee37..317943df52 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/InlineQueryTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/InlineQueryTriggers.kt @@ -5,8 +5,6 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow import dev.inmo.tgbotapi.extensions.utils.asInlineQueryUpdate import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat -import dev.inmo.tgbotapi.types.CallbackQuery.DataCallbackQuery -import dev.inmo.tgbotapi.types.CallbackQuery.GameShortNameCallbackQuery import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InlineQuery import dev.inmo.tgbotapi.types.InlineQueries.query.BaseInlineQuery import dev.inmo.tgbotapi.types.InlineQueries.query.LocationInlineQuery diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/MediaGroupTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/MediaGroupTriggers.kt index 639f2cbeff..31a9b9d11c 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/MediaGroupTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/MediaGroupTriggers.kt @@ -5,12 +5,13 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow -import dev.inmo.tgbotapi.extensions.utils.* +import dev.inmo.tgbotapi.extensions.utils.asSentMediaGroupUpdate import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat import dev.inmo.tgbotapi.extensions.utils.shortcuts.chat import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage import dev.inmo.tgbotapi.types.message.content.abstracts.* -import dev.inmo.tgbotapi.types.message.content.media.* +import dev.inmo.tgbotapi.types.message.content.media.PhotoContent +import dev.inmo.tgbotapi.types.message.content.media.VideoContent import dev.inmo.tgbotapi.utils.PreviewFeature @PreviewFeature diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PassportTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PassportTriggers.kt index 971a55419f..e954526b0e 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PassportTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PassportTriggers.kt @@ -3,7 +3,8 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow -import dev.inmo.tgbotapi.extensions.utils.* +import dev.inmo.tgbotapi.extensions.utils.asMessageUpdate +import dev.inmo.tgbotapi.extensions.utils.asPassportMessage import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat import dev.inmo.tgbotapi.types.message.PassportMessage import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportElement diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt index 708f85ae7d..6eef25aed0 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt @@ -32,7 +32,10 @@ import dev.inmo.tgbotapi.types.dice.* import dev.inmo.tgbotapi.types.files.* import dev.inmo.tgbotapi.types.files.abstracts.* import dev.inmo.tgbotapi.types.message.* +import dev.inmo.tgbotapi.types.message.ChatEvents.* +import dev.inmo.tgbotapi.types.message.ChatEvents.LeftChatMember import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.* +import dev.inmo.tgbotapi.types.message.ChatEvents.voice.* import dev.inmo.tgbotapi.types.message.abstracts.* import dev.inmo.tgbotapi.types.message.content.* import dev.inmo.tgbotapi.types.message.content.abstracts.* @@ -48,53 +51,6 @@ import dev.inmo.tgbotapi.types.update.* import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.* import dev.inmo.tgbotapi.types.update.abstracts.* import dev.inmo.tgbotapi.utils.PreviewFeature -import dev.inmo.tgbotapi.types.dice.DiceAnimationType -import dev.inmo.tgbotapi.types.update.abstracts.Update -import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.ChatEvent -import dev.inmo.tgbotapi.types.update.CallbackQueryUpdate -import dev.inmo.tgbotapi.types.update.ChannelPostUpdate -import dev.inmo.tgbotapi.types.update.ChosenInlineResultUpdate -import dev.inmo.tgbotapi.types.update.CommonChatMemberUpdatedUpdate -import dev.inmo.tgbotapi.types.update.EditChannelPostUpdate -import dev.inmo.tgbotapi.types.update.EditMessageUpdate -import dev.inmo.tgbotapi.types.update.InlineQueryUpdate -import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.ChannelPostMediaGroupUpdate -import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.EditChannelPostMediaGroupUpdate -import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.EditMediaGroupUpdate -import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.EditMessageMediaGroupUpdate -import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.MediaGroupUpdate -import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.MessageMediaGroupUpdate -import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.SentMediaGroupUpdate -import dev.inmo.tgbotapi.types.update.MessageUpdate -import dev.inmo.tgbotapi.types.update.MyChatMemberUpdatedUpdate -import dev.inmo.tgbotapi.types.update.PollAnswerUpdate -import dev.inmo.tgbotapi.types.update.PollUpdate -import dev.inmo.tgbotapi.types.update.PreCheckoutQueryUpdate -import dev.inmo.tgbotapi.types.update.ShippingQueryUpdate -import dev.inmo.tgbotapi.types.update.abstracts.BaseEditMessageUpdate -import dev.inmo.tgbotapi.types.update.abstracts.BaseMessageUpdate -import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate -import dev.inmo.tgbotapi.types.update.abstracts.ChatMemberUpdatedUpdate -import dev.inmo.tgbotapi.types.update.abstracts.UnknownUpdate -import dev.inmo.tgbotapi.types.message.ChatEvents.ChannelChatCreated -import dev.inmo.tgbotapi.types.message.ChatEvents.DeleteChatPhoto -import dev.inmo.tgbotapi.types.message.ChatEvents.GroupChatCreated -import dev.inmo.tgbotapi.types.message.ChatEvents.LeftChatMember -import dev.inmo.tgbotapi.types.message.ChatEvents.MessageAutoDeleteTimerChanged -import dev.inmo.tgbotapi.types.message.ChatEvents.NewChatMembers -import dev.inmo.tgbotapi.types.message.ChatEvents.NewChatPhoto -import dev.inmo.tgbotapi.types.message.ChatEvents.NewChatTitle -import dev.inmo.tgbotapi.types.message.ChatEvents.PinnedMessage -import dev.inmo.tgbotapi.types.message.ChatEvents.ProximityAlertTriggered -import dev.inmo.tgbotapi.types.message.ChatEvents.SupergroupChatCreated -import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.ChannelEvent -import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.CommonEvent -import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.GroupEvent -import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.SupergroupEvent -import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.VoiceChatEvent -import dev.inmo.tgbotapi.types.message.ChatEvents.voice.VoiceChatEnded -import dev.inmo.tgbotapi.types.message.ChatEvents.voice.VoiceChatParticipantsInvited -import dev.inmo.tgbotapi.types.message.ChatEvents.voice.VoiceChatStarted @PreviewFeature inline fun Chat.asBot(): Bot? = this as? Bot diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/LongPolling.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/LongPolling.kt index 5e6057d576..b8496069e7 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/LongPolling.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/LongPolling.kt @@ -14,10 +14,8 @@ import dev.inmo.tgbotapi.types.update.abstracts.Update import dev.inmo.tgbotapi.updateshandlers.* import dev.inmo.tgbotapi.utils.* import io.ktor.client.features.HttpRequestTimeoutException -import io.ktor.utils.io.core.use import kotlinx.coroutines.* import kotlinx.coroutines.flow.* -import kotlin.coroutines.coroutineContext fun TelegramBot.startGettingOfUpdatesByLongPolling( timeoutSeconds: Seconds = 30, diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/MediaGroupsIncluder.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/MediaGroupsIncluder.kt index bae30b47ce..c369e14c16 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/MediaGroupsIncluder.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/MediaGroupsIncluder.kt @@ -2,7 +2,6 @@ package dev.inmo.tgbotapi.extensions.utils.updates.retrieving import dev.inmo.tgbotapi.extensions.utils.updates.convertWithMediaGroupUpdates import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage -import dev.inmo.tgbotapi.types.message.content.abstracts.MediaGroupContent import dev.inmo.tgbotapi.types.update.abstracts.BaseMessageUpdate import dev.inmo.tgbotapi.types.update.abstracts.Update import dev.inmo.tgbotapi.updateshandlers.UpdateReceiver From f9e3e57f24d3aa47c87e75da637d6f7f229134c8 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 11 Mar 2021 21:44:08 +0600 Subject: [PATCH 05/49] migrate 0.32.10 -> 0.33.0 --- CHANGELOG.md | 2 +- gradle.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 355c8a83e2..25c14ecb71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # TelegramBotAPI changelog -## 0.32.10 +## 0.33.0 * `Common`: * `Version`: diff --git a/gradle.properties b/gradle.properties index fa30cc70d3..d338fd8535 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,6 +17,6 @@ micro_utils_version=0.4.29 javax_activation_version=1.1.1 library_group=dev.inmo -library_version=0.32.10 +library_version=0.33.0 github_release_plugin_version=2.2.12 From 0adee13cba127caf385ecd9aea70a43fb33cd9e6 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 11 Mar 2021 22:28:56 +0600 Subject: [PATCH 06/49] remove deprecations --- .../types/message/ChannelMessageImpl.kt | 2 - .../tgbotapi/types/message/GroupMessages.kt | 6 - .../types/message/PrivateMessageImpl.kt | 2 - .../types/message/abstracts/ChannelMessage.kt | 2 - .../types/message/abstracts/GroupMessages.kt | 8 -- .../types/message/abstracts/PrivateMessage.kt | 2 - .../types/message/abstracts/PublicMessage.kt | 2 - .../types/message/content/TextContent.kt | 33 ------ .../content/abstracts/ResendableContent.kt | 8 -- .../dev/inmo/tgbotapi/utils/StorageFile.kt | 2 - .../tgbotapi/extensions/utils/ClassCasts.kt | 44 -------- .../utils/ContentMessageConversations.kt | 10 -- .../extensions/utils/SlotMachineUtils.kt | 2 - .../utils/updates/retrieving/LongPolling.kt | 105 ------------------ 14 files changed, 228 deletions(-) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMessageImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMessageImpl.kt index bf173782c8..6a0552ac1e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMessageImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMessageImpl.kt @@ -20,5 +20,3 @@ data class ChannelContentMessageImpl( override val senderBot: CommonBot?, override val authorSignature: AuthorSignature? ) : ChannelContentMessage -@Deprecated("Renamed due to ambiguity of naming", ReplaceWith("ChannelContentMessageImpl", "dev.inmo.tgbotapi.types.message.ChannelContentMessageImpl")) -typealias ChannelMessageImpl = ChannelContentMessageImpl 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 061eae0a99..e24405ba79 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 @@ -21,8 +21,6 @@ data class FromChannelGroupContentMessageImpl( override val senderBot: CommonBot?, override val authorSignature: AuthorSignature? ) : FromChannelGroupContentMessage -@Deprecated("Renamed due to ambiguity of naming", ReplaceWith("FromChannelGroupContentMessageImpl", "dev.inmo.tgbotapi.types.message.FromChannelGroupContentMessageImpl")) -typealias FromChannelGroupMessageImpl = FromChannelGroupContentMessageImpl data class AnonymousGroupContentMessageImpl( override val chat: GroupChat, @@ -36,8 +34,6 @@ data class AnonymousGroupContentMessageImpl( override val senderBot: CommonBot?, override val authorSignature: AuthorSignature? ) : AnonymousGroupContentMessage -@Deprecated("Renamed due to ambiguity of naming", ReplaceWith("AnonymousGroupContentMessageImpl", "dev.inmo.tgbotapi.types.message.AnonymousGroupContentMessageImpl")) -typealias AnonymousGroupMessageImpl = AnonymousGroupContentMessageImpl data class CommonGroupContentMessageImpl( override val chat: GroupChat, @@ -51,5 +47,3 @@ data class CommonGroupContentMessageImpl( override val content: T, override val senderBot: CommonBot? ) : CommonGroupContentMessage -@Deprecated("Renamed due to ambiguity of naming", ReplaceWith("CommonGroupContentMessageImpl", "dev.inmo.tgbotapi.types.message.CommonGroupContentMessageImpl")) -typealias CommonGroupMessageImpl = CommonGroupContentMessageImpl diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateMessageImpl.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateMessageImpl.kt index 94cd9fea81..75a928c049 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateMessageImpl.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PrivateMessageImpl.kt @@ -22,5 +22,3 @@ data class PrivateContentMessageImpl( override val senderBot: CommonBot?, val paymentInfo: SuccessfulPaymentInfo? ) : PrivateContentMessage -@Deprecated("Renamed due to ambiguity of naming", ReplaceWith("PrivateContentMessageImpl", "dev.inmo.tgbotapi.types.message.PrivateContentMessageImpl")) -typealias PrivateMessageImpl = PrivateContentMessageImpl diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/ChannelMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/ChannelMessage.kt index b9bbbec871..a7ddbc6e66 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/ChannelMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/ChannelMessage.kt @@ -9,5 +9,3 @@ interface ChannelContentMessage : PossiblySentViaBotCommonMes override val senderChat: ChannelChat get() = chat } -@Deprecated("Renamed due to ambiguity of naming", ReplaceWith("ChannelContentMessage", "dev.inmo.tgbotapi.types.message.abstracts.ChannelContentMessage")) -typealias ChannelMessage = ChannelContentMessage 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 6167a0ca1d..d5a91e20c1 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 @@ -7,8 +7,6 @@ import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent interface GroupContentMessage : PublicContentMessage { override val chat: GroupChat } -@Deprecated("Renamed due to ambiguity of naming", ReplaceWith("GroupContentMessage", "dev.inmo.tgbotapi.types.message.abstracts.GroupContentMessage")) -typealias GroupMessage = GroupContentMessage interface FromChannelGroupContentMessage : GroupContentMessage, SignedMessage, WithSenderChatMessage { @@ -16,16 +14,10 @@ interface FromChannelGroupContentMessage : GroupContentMessa override val senderChat: ChannelChat get() = channel } -@Deprecated("Renamed due to ambiguity of naming", ReplaceWith("FromChannelGroupContentMessage", "dev.inmo.tgbotapi.types.message.abstracts.FromChannelGroupContentMessage")) -typealias FromChannelGroupMessage = FromChannelGroupContentMessage interface AnonymousGroupContentMessage : GroupContentMessage, SignedMessage, WithSenderChatMessage { override val senderChat: GroupChat get() = chat } -@Deprecated("Renamed due to ambiguity of naming", ReplaceWith("AnonymousGroupContentMessage", "dev.inmo.tgbotapi.types.message.abstracts.AnonymousGroupContentMessage")) -typealias AnonymousGroupMessage = AnonymousGroupContentMessage interface CommonGroupContentMessage : GroupContentMessage, FromUserMessage -@Deprecated("Renamed due to ambiguity of naming", ReplaceWith("CommonGroupContentMessage", "dev.inmo.tgbotapi.types.message.abstracts.CommonGroupContentMessage")) -typealias CommonGroupMessage = CommonGroupContentMessage diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PrivateMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PrivateMessage.kt index 27a6c23614..767cef23ca 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PrivateMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PrivateMessage.kt @@ -4,5 +4,3 @@ import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage interface PrivateContentMessage : PossiblySentViaBotCommonMessage, FromUserMessage -@Deprecated("Renamed due to ambiguity of naming", ReplaceWith("PrivateContentMessage", "dev.inmo.tgbotapi.types.message.abstracts.PrivateContentMessage")) -typealias PrivateMessage = PrivateContentMessage diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PublicMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PublicMessage.kt index 4b409815c7..d965cc2db9 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PublicMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/PublicMessage.kt @@ -7,5 +7,3 @@ import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommo interface PublicContentMessage : PossiblySentViaBotCommonMessage { override val chat: PublicChat } -@Deprecated("Renamed due to ambiguity of naming", ReplaceWith("PublicContentMessage", "dev.inmo.tgbotapi.types.message.PublicContentMessage")) -typealias PublicMessage = PublicContentMessage 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 915c875a69..abc204e63e 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 @@ -30,37 +30,4 @@ data class TextContent( allowSendingWithoutReply, replyMarkup ) - - @Deprecated( - "Useless due to fact that createResend currently use textSource and that will guarantee correct sending of message", - ReplaceWith("createResend") - ) - override fun createResends( - chatId: ChatIdentifier, - disableNotification: Boolean, - replyToMessageId: MessageIdentifier?, - allowSendingWithoutReply: Boolean?, - replyMarkup: KeyboardMarkup? - ): List>> = listOf( - createResend( - chatId, - disableNotification, - replyToMessageId, - allowSendingWithoutReply, - replyMarkup - ) - ) - - @Deprecated( - "Useless due to fact that createResend currently use textSource and that will guarantee correct sending of message", - ReplaceWith("createResend") - ) - fun createResends( - chatId: ChatIdentifier, - disableNotification: Boolean, - replyToMessageId: MessageIdentifier?, - allowSendingWithoutReply: Boolean?, - replyMarkup: KeyboardMarkup?, - parseMode: ParseMode = defaultParseMode - ): List>> = createResends(chatId, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup) } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/abstracts/ResendableContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/abstracts/ResendableContent.kt index f0b1993573..895c312eb9 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/abstracts/ResendableContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/abstracts/ResendableContent.kt @@ -14,12 +14,4 @@ interface ResendableContent { allowSendingWithoutReply: Boolean? = null, replyMarkup: KeyboardMarkup? = null ): Request - - fun createResends( - chatId: ChatIdentifier, - disableNotification: Boolean = false, - replyToMessageId: MessageIdentifier? = null, - allowSendingWithoutReply: Boolean? = null, - replyMarkup: KeyboardMarkup? = null - ): List> = listOf(createResend(chatId, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup)) } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/StorageFile.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/StorageFile.kt index 167f6b80b8..6db07683ee 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/StorageFile.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/StorageFile.kt @@ -37,8 +37,6 @@ data class StorageFile( ) { val input: Input get() = inputSource() - @Deprecated("This method will be fully replaced with input property", ReplaceWith("input")) - fun asInput() = input } @Suppress("NOTHING_TO_INLINE") diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt index 6eef25aed0..999f165c15 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt @@ -398,40 +398,24 @@ inline fun SecureValue.asSecureValueWithTranslations(): SecureValueWithTranslati inline fun SecureValue.requireSecureValueWithTranslations(): SecureValueWithTranslations = this as SecureValueWithTranslations @PreviewFeature inline fun Message.asAnonymousGroupContentMessageImpl(): AnonymousGroupContentMessageImpl? = this as? AnonymousGroupContentMessageImpl -@Deprecated("Renamed", ReplaceWith("asAnonymousGroupContentMessageImpl", "dev.inmo.tgbotapi.extensions.utils.asAnonymousGroupContentMessageImpl")) -inline fun Message.asAnonymousGroupMessageImpl() = asAnonymousGroupContentMessageImpl() @PreviewFeature inline fun Message.requireAnonymousGroupContentMessageImpl(): AnonymousGroupContentMessageImpl = this as AnonymousGroupContentMessageImpl -@Deprecated("Renamed", ReplaceWith("requireAnonymousGroupContentMessageImpl", "dev.inmo.tgbotapi.extensions.utils.requireAnonymousGroupContentMessageImpl")) -inline fun Message.requireAnonymousGroupMessageImpl() = requireAnonymousGroupContentMessageImpl() @PreviewFeature inline fun Message.asChannelContentMessageImpl(): ChannelContentMessageImpl? = this as? ChannelContentMessageImpl -@Deprecated("Renamed", ReplaceWith("asChannelContentMessageImpl", "dev.inmo.tgbotapi.extensions.utils.asChannelContentMessageImpl")) -inline fun Message.asChannelMessageImpl() = asChannelContentMessageImpl() @PreviewFeature inline fun Message.requireChannelContentMessageImpl(): ChannelContentMessageImpl = this as ChannelContentMessageImpl -@Deprecated("Renamed", ReplaceWith("requireChannelContentMessageImpl", "dev.inmo.tgbotapi.extensions.utils.requireChannelContentMessageImpl")) -inline fun Message.requireChannelMessageImpl() = requireChannelContentMessageImpl() @PreviewFeature inline fun Message.asFromChannelGroupContentMessageImpl(): FromChannelGroupContentMessageImpl? = this as? FromChannelGroupContentMessageImpl -@Deprecated("Renamed", ReplaceWith("asFromChannelGroupContentMessageImpl", "dev.inmo.tgbotapi.extensions.utils.asFromChannelGroupContentMessageImpl")) -inline fun Message.asFromChannelGroupMessageImpl() = asFromChannelGroupContentMessageImpl() @PreviewFeature inline fun Message.requireFromChannelGroupContentMessageImpl(): FromChannelGroupContentMessageImpl = this as FromChannelGroupContentMessageImpl -@Deprecated("Renamed", ReplaceWith("requireFromChannelGroupContentMessageImpl", "dev.inmo.tgbotapi.extensions.utils.requireFromChannelGroupContentMessageImpl")) -inline fun Message.requireFromChannelGroupMessageImpl() = requireFromChannelGroupContentMessageImpl() @PreviewFeature inline fun Message.asPassportMessage(): PassportMessage? = this as? PassportMessage @PreviewFeature inline fun Message.requirePassportMessage(): PassportMessage = this as PassportMessage @PreviewFeature inline fun Message.asPrivateContentMessageImpl(): PrivateContentMessageImpl? = this as? PrivateContentMessageImpl -@Deprecated("Renamed", ReplaceWith("asPrivateContentMessageImpl", "dev.inmo.tgbotapi.extensions.utils.asPrivateContentMessageImpl")) -inline fun Message.asPrivateMessageImpl() = asPrivateContentMessageImpl() @PreviewFeature inline fun Message.requirePrivateContentMessageImpl(): PrivateContentMessageImpl = this as PrivateContentMessageImpl -@Deprecated("Renamed", ReplaceWith("requirePrivateContentMessageImpl", "dev.inmo.tgbotapi.extensions.utils.requirePrivateContentMessageImpl")) -inline fun Message.requirePrivateMessageImpl() = requirePrivateContentMessageImpl() @PreviewFeature inline fun Message.asChannelEventMessage(): ChannelEventMessage? = this as? ChannelEventMessage @PreviewFeature @@ -454,32 +438,20 @@ inline fun Message.asCommonSupergroupEventMessage(): CommonSupergroupEventMessag inline fun Message.requireCommonSupergroupEventMessage(): CommonSupergroupEventMessage = this as CommonSupergroupEventMessage @PreviewFeature inline fun Message.asAnonymousGroupContentMessage(): AnonymousGroupContentMessage? = this as? AnonymousGroupContentMessage -@Deprecated("Renamed", ReplaceWith("asAnonymousGroupContentMessage", "dev.inmo.tgbotapi.extensions.utils.asAnonymousGroupContentMessage")) -inline fun Message.asAnonymousGroupMessage() = asAnonymousGroupContentMessage() @PreviewFeature inline fun Message.requireAnonymousGroupContentMessage(): AnonymousGroupContentMessage = this as AnonymousGroupContentMessage -@Deprecated("Renamed", ReplaceWith("requireAnonymousGroupContentMessage", "dev.inmo.tgbotapi.extensions.utils.requireAnonymousGroupContentMessage")) -inline fun Message.requireAnonymousGroupMessage() = requireAnonymousGroupContentMessage() @PreviewFeature inline fun Message.asChannelContentMessage(): ChannelContentMessageImpl? = this as? ChannelContentMessageImpl -@Deprecated("Renamed", ReplaceWith("asChannelContentMessage", "dev.inmo.tgbotapi.extensions.utils.asChannelContentMessage")) -inline fun Message.asChannelMessage() = asChannelContentMessage() @PreviewFeature inline fun Message.requireChannelContentMessage(): ChannelContentMessageImpl = this as ChannelContentMessageImpl -@Deprecated("Renamed", ReplaceWith("requireChannelContentMessage", "dev.inmo.tgbotapi.extensions.utils.requireChannelContentMessage")) -inline fun Message.requireChannelMessage() = requireChannelContentMessage() @PreviewFeature inline fun Message.asChatEventMessage(): ChatEventMessage? = this as? ChatEventMessage @PreviewFeature inline fun Message.requireChatEventMessage(): ChatEventMessage = this as ChatEventMessage @PreviewFeature inline fun Message.asCommonGroupContentMessage(): CommonGroupContentMessage? = this as? CommonGroupContentMessage -@Deprecated("Renamed", ReplaceWith("asCommonGroupContentMessage", "dev.inmo.tgbotapi.extensions.utils.asCommonGroupContentMessage")) -inline fun Message.asCommonGroupMessage() = asCommonGroupContentMessage() @PreviewFeature inline fun Message.requireCommonGroupContentMessage(): CommonGroupContentMessage = this as CommonGroupContentMessage -@Deprecated("Renamed", ReplaceWith("requireCommonGroupContentMessage", "dev.inmo.tgbotapi.extensions.utils.requireCommonGroupContentMessage")) -inline fun Message.requireCommonGroupMessage() = requireCommonGroupContentMessage() @PreviewFeature inline fun Message.asCommonMessage(): CommonMessage? = this as? CommonMessage @PreviewFeature @@ -490,24 +462,16 @@ inline fun Message.asContentMessage(): ContentMessage? = this as inline fun Message.requireContentMessage(): ContentMessage = this as ContentMessage @PreviewFeature inline fun Message.asFromChannelGroupContentMessage(): FromChannelGroupContentMessage? = this as? FromChannelGroupContentMessage -@Deprecated("Renamed", ReplaceWith("asFromChannelGroupContentMessage", "dev.inmo.tgbotapi.extensions.utils.asFromChannelGroupContentMessage")) -inline fun Message.asFromChannelGroupMessage() = asFromChannelGroupContentMessage() @PreviewFeature inline fun Message.requireFromChannelGroupContentMessage(): FromChannelGroupContentMessage = this as FromChannelGroupContentMessage -@Deprecated("Renamed", ReplaceWith("requireFromChannelGroupContentMessage", "dev.inmo.tgbotapi.extensions.utils.requireFromChannelGroupContentMessage")) -inline fun Message.requireFromChannelGroupMessage() = requireFromChannelGroupContentMessage() @PreviewFeature inline fun Message.asGroupEventMessage(): GroupEventMessage? = this as? GroupEventMessage @PreviewFeature inline fun Message.requireGroupEventMessage(): GroupEventMessage = this as GroupEventMessage @PreviewFeature inline fun Message.asGroupContentMessage(): GroupContentMessage? = this as? GroupContentMessage -@Deprecated("Renamed", ReplaceWith("asGroupContentMessage", "dev.inmo.tgbotapi.extensions.utils.asGroupContentMessage")) -inline fun Message.asGroupMessage() = asGroupContentMessage() @PreviewFeature inline fun Message.requireGroupContentMessage(): GroupContentMessage = this as GroupContentMessage -@Deprecated("Renamed", ReplaceWith("requireGroupContentMessage", "dev.inmo.tgbotapi.extensions.utils.requireGroupContentMessage")) -inline fun Message.requireGroupMessage() = requireGroupContentMessage() @PreviewFeature inline fun Message.asMediaGroupMessage(): MediaGroupMessage? = this as? MediaGroupMessage @PreviewFeature @@ -526,20 +490,12 @@ inline fun Message.asPossiblyPaymentMessage(): PossiblyPaymentMessage? = this as inline fun Message.requirePossiblyPaymentMessage(): PossiblyPaymentMessage = this as PossiblyPaymentMessage @PreviewFeature inline fun Message.asPrivateContentMessage(): PrivateContentMessage? = this as? PrivateContentMessage -@Deprecated("Renamed", ReplaceWith("asPrivateContentMessage", "dev.inmo.tgbotapi.extensions.utils.asPrivateContentMessage")) -inline fun Message.asPrivateMessage() = asPrivateContentMessage() @PreviewFeature inline fun Message.requirePrivateContentMessage(): PrivateContentMessage = this as PrivateContentMessage -@Deprecated("Renamed", ReplaceWith("requirePrivateContentMessage", "dev.inmo.tgbotapi.extensions.utils.requirePrivateContentMessage")) -inline fun Message.requirePrivateMessage() = requirePrivateContentMessage() @PreviewFeature inline fun Message.asPublicContentMessage(): PublicContentMessage? = this as? PublicContentMessage -@Deprecated("Renamed", ReplaceWith("asPublicContentMessage", "dev.inmo.tgbotapi.extensions.utils.asPublicContentMessage")) -inline fun Message.asPublicMessage() = asPublicContentMessage() @PreviewFeature inline fun Message.requirePublicContentMessage(): PublicContentMessage = this as PublicContentMessage -@Deprecated("Renamed", ReplaceWith("requirePublicContentMessage", "dev.inmo.tgbotapi.extensions.utils.requirePublicContentMessage")) -inline fun Message.requirePublicMessage() = requirePublicContentMessage() @PreviewFeature inline fun Message.asSignedMessage(): SignedMessage? = this as? SignedMessage @PreviewFeature diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ContentMessageConversations.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ContentMessageConversations.kt index bcdff2ce59..37841333c7 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ContentMessageConversations.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ContentMessageConversations.kt @@ -13,16 +13,6 @@ private inline fun Flow>.withCont it.withContent() } -@Deprecated("This method will be removed in next major update") -fun Flow>.withContentType(contentType: KClass) = mapNotNull { - if (contentType.isInstance(it.content)) { - @Suppress("UNCHECKED_CAST") - it as ContentMessage - } else { - null - } -} - fun Flow>.onlyAnimationContentMessages() = withContentType() fun Flow>.onlyAudioContentMessages() = withContentType() fun Flow>.onlyContactContentMessages() = withContentType() diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/SlotMachineUtils.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/SlotMachineUtils.kt index 82fcdb7e77..9fae120809 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/SlotMachineUtils.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/SlotMachineUtils.kt @@ -16,8 +16,6 @@ enum class SlotMachineReelImage(val text: String, val number: Int) { LEMON("\uD83C\uDF4B", 2), SEVEN("7", 3) } -@Deprecated("Renamed", ReplaceWith("SlotMachineReelImage", "dev.inmo.tgbotapi.extensions.utils.SlotMachineReelImage")) -typealias SlotMachineReelImages = SlotMachineReelImage /** * @return First [SlotMachineReelImage] with [SlotMachineReelImage.number] equal to receiver OR [SlotMachineReelImage.SEVEN] diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/LongPolling.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/LongPolling.kt index b8496069e7..6cb849335e 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/LongPolling.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/LongPolling.kt @@ -158,26 +158,6 @@ fun TelegramBot.longPolling( flowUpdatesPreset: FlowsUpdatesFilter.() -> Unit ): Job = longPolling(FlowsUpdatesFilter(flowsUpdatesFilterUpdatesKeeperCount).apply(flowUpdatesPreset), timeoutSeconds, scope, exceptionsHandler) -/** - * This method will create a new one [FlowsUpdatesFilter]. This method could be unsafe due to the fact that it will start - * getting updates IMMEDIATELY. That means that your bot will be able to skip some of them until you will call - * [kotlinx.coroutines.flow.Flow.collect] on one of [FlowsUpdatesFilter] flows. To avoid it, you can pass - * [flowUpdatesPreset] lambda - it will be called BEFORE starting updates getting - */ -@FlowPreview -@Deprecated("Will be removed soon", ReplaceWith("longPolling", "dev.inmo.tgbotapi.extensions.utils.updates.retrieving.longPolling")) -@Suppress("unused") -fun RequestsExecutor.startGettingFlowsUpdatesByLongPolling( - timeoutSeconds: Seconds = 30, - scope: CoroutineScope = CoroutineScope(Dispatchers.Default), - exceptionsHandler: ExceptionHandler? = null, - flowsUpdatesFilterUpdatesKeeperCount: Int = 100, - flowUpdatesPreset: FlowsUpdatesFilter.() -> Unit = {} -): FlowsUpdatesFilter = FlowsUpdatesFilter(flowsUpdatesFilterUpdatesKeeperCount).apply { - flowUpdatesPreset() - startGettingOfUpdatesByLongPolling(timeoutSeconds, scope, exceptionsHandler, allowedUpdates, asUpdateReceiver) -} - fun RequestsExecutor.startGettingOfUpdatesByLongPolling( updatesFilter: UpdatesFilter, timeoutSeconds: Seconds = 30, @@ -190,88 +170,3 @@ fun RequestsExecutor.startGettingOfUpdatesByLongPolling( updatesFilter.allowedUpdates, updatesFilter.asUpdateReceiver ) - -@Deprecated("Will be removed soon", ReplaceWith("longPolling", "dev.inmo.tgbotapi.extensions.utils.updates.retrieving.longPolling")) -fun RequestsExecutor.startGettingOfUpdatesByLongPolling( - messageCallback: UpdateReceiver? = null, - messageMediaGroupCallback: UpdateReceiver? = null, - editedMessageCallback: UpdateReceiver? = null, - editedMessageMediaGroupCallback: UpdateReceiver? = null, - channelPostCallback: UpdateReceiver? = null, - channelPostMediaGroupCallback: UpdateReceiver? = null, - editedChannelPostCallback: UpdateReceiver? = null, - editedChannelPostMediaGroupCallback: UpdateReceiver? = null, - chosenInlineResultCallback: UpdateReceiver? = null, - inlineQueryCallback: UpdateReceiver? = null, - callbackQueryCallback: UpdateReceiver? = null, - shippingQueryCallback: UpdateReceiver? = null, - preCheckoutQueryCallback: UpdateReceiver? = null, - pollCallback: UpdateReceiver? = null, - pollAnswerCallback: UpdateReceiver? = null, - timeoutSeconds: Seconds = 30, - exceptionsHandler: ExceptionHandler? = null, - scope: CoroutineScope = CoroutineScope(Dispatchers.Default) -): Job { - return startGettingOfUpdatesByLongPolling( - SimpleUpdatesFilter( - messageCallback, - messageMediaGroupCallback, - editedMessageCallback, - editedMessageMediaGroupCallback, - channelPostCallback, - channelPostMediaGroupCallback, - editedChannelPostCallback, - editedChannelPostMediaGroupCallback, - chosenInlineResultCallback, - inlineQueryCallback, - callbackQueryCallback, - shippingQueryCallback, - preCheckoutQueryCallback, - pollCallback, - pollAnswerCallback - ), - timeoutSeconds, - exceptionsHandler, - scope - ) -} - -@Deprecated("Will be removed soon", ReplaceWith("longPolling", "dev.inmo.tgbotapi.extensions.utils.updates.retrieving.longPolling")) -@Suppress("unused") -fun RequestsExecutor.startGettingOfUpdatesByLongPolling( - messageCallback: UpdateReceiver? = null, - mediaGroupCallback: UpdateReceiver? = null, - editedMessageCallback: UpdateReceiver? = null, - channelPostCallback: UpdateReceiver? = null, - editedChannelPostCallback: UpdateReceiver? = null, - chosenInlineResultCallback: UpdateReceiver? = null, - inlineQueryCallback: UpdateReceiver? = null, - callbackQueryCallback: UpdateReceiver? = null, - shippingQueryCallback: UpdateReceiver? = null, - preCheckoutQueryCallback: UpdateReceiver? = null, - pollCallback: UpdateReceiver? = null, - pollAnswerCallback: UpdateReceiver? = null, - timeoutSeconds: Seconds = 30, - exceptionsHandler: ExceptionHandler? = null, - scope: CoroutineScope = CoroutineScope(Dispatchers.Default) -): Job = startGettingOfUpdatesByLongPolling( - messageCallback = messageCallback, - messageMediaGroupCallback = mediaGroupCallback, - editedMessageCallback = editedMessageCallback, - editedMessageMediaGroupCallback = mediaGroupCallback, - channelPostCallback = channelPostCallback, - channelPostMediaGroupCallback = mediaGroupCallback, - editedChannelPostCallback = editedChannelPostCallback, - editedChannelPostMediaGroupCallback = mediaGroupCallback, - chosenInlineResultCallback = chosenInlineResultCallback, - inlineQueryCallback = inlineQueryCallback, - callbackQueryCallback = callbackQueryCallback, - shippingQueryCallback = shippingQueryCallback, - preCheckoutQueryCallback = preCheckoutQueryCallback, - pollCallback = pollCallback, - pollAnswerCallback = pollAnswerCallback, - timeoutSeconds = timeoutSeconds, - exceptionsHandler = exceptionsHandler, - scope = scope -) - From 72cf38d3bb05ee3f1d78f911b527174ade65bbad Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 12 Mar 2021 14:36:10 +0600 Subject: [PATCH 07/49] fill Behaviour Builder for ChatMemberUpdated --- .../expectations/WaitChatMemberUpdated.kt | 65 +++++++++++++++++++ .../ChatMemberUpdatedTriggers.kt | 61 +++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitChatMemberUpdated.kt create mode 100644 tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatMemberUpdatedTriggers.kt diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitChatMemberUpdated.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitChatMemberUpdated.kt new file mode 100644 index 0000000000..27827be3e1 --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitChatMemberUpdated.kt @@ -0,0 +1,65 @@ +package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations + +import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext +import dev.inmo.tgbotapi.extensions.utils.asCallbackQueryUpdate +import dev.inmo.tgbotapi.requests.abstracts.Request +import dev.inmo.tgbotapi.types.CallbackQuery.CallbackQuery +import dev.inmo.tgbotapi.types.CallbackQuery.DataCallbackQuery +import dev.inmo.tgbotapi.types.ChatMemberUpdated +import dev.inmo.tgbotapi.types.update.CommonChatMemberUpdatedUpdate +import dev.inmo.tgbotapi.types.update.MyChatMemberUpdatedUpdate +import dev.inmo.tgbotapi.types.update.abstracts.ChatMemberUpdatedUpdate +import kotlinx.coroutines.flow.toList + +typealias ChatMemberUpdatedMapper = T.() -> T? + +private suspend inline fun BehaviourContext.waitChatMemberUpdated( + count: Int = 1, + initRequest: Request<*>? = null, + noinline errorFactory: NullableRequestBuilder<*> = { null }, + noinline mapper: ChatMemberUpdatedMapper +): List = expectFlow( + initRequest, + count, + errorFactory +) { + (it as? T) ?.data.let(::listOfNotNull) +}.toList().toList() + +private suspend inline fun BehaviourContext.waitChatMemberUpdated( + count: Int = 1, + initRequest: Request<*>? = null, + noinline errorFactory: NullableRequestBuilder<*> = { null }, + noinline filter: ChatMemberUpdatedMapper? = null +) : List = waitChatMemberUpdated( + count, + initRequest, + errorFactory +) { + if (filter == null) { + this + } else { + filter(this) + } +} + +suspend fun BehaviourContext.waitChatMemberUpdated( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null }, + count: Int = 1, + filter: ChatMemberUpdatedMapper? = null +) = waitChatMemberUpdated(count, initRequest, errorFactory, filter) + +suspend fun BehaviourContext.waitCommonChatMemberUpdated( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null }, + count: Int = 1, + filter: ChatMemberUpdatedMapper? = null +) = waitChatMemberUpdated(count, initRequest, errorFactory, filter) + +suspend fun BehaviourContext.waitMyChatMemberUpdated( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null }, + count: Int = 1, + filter: ChatMemberUpdatedMapper? = null +) = waitChatMemberUpdated(count, initRequest, errorFactory, filter) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatMemberUpdatedTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatMemberUpdatedTriggers.kt new file mode 100644 index 0000000000..180702731e --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatMemberUpdatedTriggers.kt @@ -0,0 +1,61 @@ +package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling + +import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions +import dev.inmo.tgbotapi.extensions.behaviour_builder.* +import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow +import dev.inmo.tgbotapi.extensions.utils.asChatMemberUpdatedUpdate +import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat +import dev.inmo.tgbotapi.types.ChatMemberUpdated +import dev.inmo.tgbotapi.types.update.CommonChatMemberUpdatedUpdate +import dev.inmo.tgbotapi.types.update.MyChatMemberUpdatedUpdate +import dev.inmo.tgbotapi.types.update.abstracts.ChatMemberUpdatedUpdate + +internal suspend inline fun BehaviourContext.onChatMemberUpdated( + includeFilterByChatInBehaviourSubContext: Boolean = true, + noinline additionalFilter: (suspend (ChatMemberUpdated) -> Boolean)? = null, + noinline scenarioReceiver: BehaviourContextAndTypeReceiver +) = flowsUpdatesFilter.expectFlow(bot) { + (it as? U) ?.data ?.let { chatMemberUpdated -> + if (additionalFilter == null || additionalFilter(chatMemberUpdated)) chatMemberUpdated else null + }.let(::listOfNotNull) +}.subscribeSafelyWithoutExceptions(scope) { triggerChatMemberUpdated -> + doInSubContextWithUpdatesFilter( + updatesFilter = if (includeFilterByChatInBehaviourSubContext) { + { it.sourceChat() ?.id ?.chatId == triggerChatMemberUpdated.chat.id.chatId } + } else { + null + } + ) { + scenarioReceiver(triggerChatMemberUpdated) + } +} + +suspend fun BehaviourContext.onChatMemberUpdated( + includeFilterByChatInBehaviourSubContext: Boolean = true, + additionalFilter: (suspend (ChatMemberUpdated) -> Boolean)? = null, + scenarioReceiver: BehaviourContextAndTypeReceiver +) = onChatMemberUpdated( + includeFilterByChatInBehaviourSubContext, + additionalFilter, + scenarioReceiver +) + +suspend fun BehaviourContext.onCommonChatMemberUpdated( + includeFilterByChatInBehaviourSubContext: Boolean = true, + additionalFilter: (suspend (ChatMemberUpdated) -> Boolean)? = null, + scenarioReceiver: BehaviourContextAndTypeReceiver +) = onChatMemberUpdated( + includeFilterByChatInBehaviourSubContext, + additionalFilter, + scenarioReceiver +) + +suspend fun BehaviourContext.onMyChatMemberUpdated( + includeFilterByChatInBehaviourSubContext: Boolean = true, + additionalFilter: (suspend (ChatMemberUpdated) -> Boolean)? = null, + scenarioReceiver: BehaviourContextAndTypeReceiver +) = onChatMemberUpdated( + includeFilterByChatInBehaviourSubContext, + additionalFilter, + scenarioReceiver +) From 7bb272f2fa35f7a157355f3f60bd159021a346f9 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 12 Mar 2021 14:39:27 +0600 Subject: [PATCH 08/49] update compatibility note --- tgbotapi.core/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tgbotapi.core/README.md b/tgbotapi.core/README.md index 0b8ed3f0d4..344aeace98 100644 --- a/tgbotapi.core/README.md +++ b/tgbotapi.core/README.md @@ -10,7 +10,7 @@ moments are describing by official [Telegram Bot API](https://core.telegram.org/ ## Compatibility -This version compatible with [4th of November 2020 update of TelegramBotAPI (version 5.0)](https://core.telegram.org/bots/api#november-4-2020). +This version compatible with [9th of March 2021 update of TelegramBotAPI (version 5.1)](https://core.telegram.org/bots/api#march-9-2021). ## How to implement library? From a4bae5133a9cb8a8f07a103e26f192b1bad332a6 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 12 Mar 2021 14:58:13 +0600 Subject: [PATCH 09/49] fill changelog --- CHANGELOG.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25c14ecb71..4d5a5d1710 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,13 +2,37 @@ ## 0.33.0 +**UPDATE UP TO Telegram Bot API 5.1** +_**ALL DEPRECATIONS WERE REMOVED**_ + * `Common`: * `Version`: * `MicroUtils`: `0.4.28` -> `0.4.29` * `Core`: * `AdministratorChatMemberSerializer` and `ChatMemberSerializer` has changed their visibility: they are public for now + * Add `ChatInviteLinkRequest` with subrequests like `KnownChatInviteLinkRequest` + * Add `CreateChatInviteLink`/`EditChatInviteLink`/`RevokeChatInviteLink` requests + * Update `KickChatMember` to include `revokeMessages` flag + * Update `PromoteChatMember` to include `canManageVoiceChats` and `canManageChat` flags + * Add `ChatInviteLink` object + * Add `PrimaryInviteLink` for `ChatInviteLink` with `isPrimary == true` + * Add `CommonInviteLink` for `ChatInviteLink` with `isPrimary == false` + * `AdministratorChatMemberSerializer` has been set as public for several versions + * `ChatMemberSerializer` has been set as public for several versions + * Add `ChatMemberUpdated` + * Add `MessageAutoDeleteTimerChanged` + * Add `VoiceChatEvent` + * Add `VoiceChatEnded` + * Add `VoiceChatParticipantsInvited` + * Add `VoiceChatStarted` + * Add `ChatMemberUpdatedUpdate` + * Add `CommonChatMemberUpdatedUpdate` + * Add `MyChatMemberUpdatedUpdate` +* `API`: + * All API extensions has been updated * `Behaviour Builder`: * Now content triggers and expectators will wait for channel posts too + * New waiters and triggers for `ChatMemberUpdated` and its variations ## 0.32.9 From 9fc07f2ff30149ecbbd5d1a1763693469afa8af8 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 12 Mar 2021 15:03:11 +0600 Subject: [PATCH 10/49] fix build --- .../expectations/WaitChatMemberUpdated.kt | 8 ++++---- .../triggers_handling/ChatMemberUpdatedTriggers.kt | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitChatMemberUpdated.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitChatMemberUpdated.kt index 27827be3e1..8e69298190 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitChatMemberUpdated.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitChatMemberUpdated.kt @@ -26,7 +26,7 @@ private suspend inline fun BehaviourContex (it as? T) ?.data.let(::listOfNotNull) }.toList().toList() -private suspend inline fun BehaviourContext.waitChatMemberUpdated( +private suspend inline fun BehaviourContext.waitChatMemberUpdatedWithFilter( count: Int = 1, initRequest: Request<*>? = null, noinline errorFactory: NullableRequestBuilder<*> = { null }, @@ -48,18 +48,18 @@ suspend fun BehaviourContext.waitChatMemberUpdated( errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, filter: ChatMemberUpdatedMapper? = null -) = waitChatMemberUpdated(count, initRequest, errorFactory, filter) +) = waitChatMemberUpdatedWithFilter(count, initRequest, errorFactory, filter) suspend fun BehaviourContext.waitCommonChatMemberUpdated( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, filter: ChatMemberUpdatedMapper? = null -) = waitChatMemberUpdated(count, initRequest, errorFactory, filter) +) = waitChatMemberUpdatedWithFilter(count, initRequest, errorFactory, filter) suspend fun BehaviourContext.waitMyChatMemberUpdated( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, filter: ChatMemberUpdatedMapper? = null -) = waitChatMemberUpdated(count, initRequest, errorFactory, filter) +) = waitChatMemberUpdatedWithFilter(count, initRequest, errorFactory, filter) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatMemberUpdatedTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatMemberUpdatedTriggers.kt index 180702731e..1156af2648 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatMemberUpdatedTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatMemberUpdatedTriggers.kt @@ -10,7 +10,7 @@ import dev.inmo.tgbotapi.types.update.CommonChatMemberUpdatedUpdate import dev.inmo.tgbotapi.types.update.MyChatMemberUpdatedUpdate import dev.inmo.tgbotapi.types.update.abstracts.ChatMemberUpdatedUpdate -internal suspend inline fun BehaviourContext.onChatMemberUpdated( +internal suspend inline fun BehaviourContext.onChatMemberUpdatedInternal( includeFilterByChatInBehaviourSubContext: Boolean = true, noinline additionalFilter: (suspend (ChatMemberUpdated) -> Boolean)? = null, noinline scenarioReceiver: BehaviourContextAndTypeReceiver @@ -34,7 +34,7 @@ suspend fun BehaviourContext.onChatMemberUpdated( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatMemberUpdated) -> Boolean)? = null, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onChatMemberUpdated( +) = onChatMemberUpdatedInternal( includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver @@ -44,7 +44,7 @@ suspend fun BehaviourContext.onCommonChatMemberUpdated( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatMemberUpdated) -> Boolean)? = null, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onChatMemberUpdated( +) = onChatMemberUpdatedInternal( includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver @@ -54,7 +54,7 @@ suspend fun BehaviourContext.onMyChatMemberUpdated( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (ChatMemberUpdated) -> Boolean)? = null, scenarioReceiver: BehaviourContextAndTypeReceiver -) = onChatMemberUpdated( +) = onChatMemberUpdatedInternal( includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver From 4e019eb8bbcf61977230411bd3be2794d77bd2aa Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 12 Mar 2021 20:11:26 +0600 Subject: [PATCH 11/49] Update packages_publishing.yml --- .github/workflows/packages_publishing.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/packages_publishing.yml b/.github/workflows/packages_publishing.yml index df0458887c..5165fc78a9 100644 --- a/.github/workflows/packages_publishing.yml +++ b/.github/workflows/packages_publishing.yml @@ -15,8 +15,10 @@ jobs: cat gradle.properties | sed -e "s/^library_version=\([0-9\.]*\)/library_version=\1-branch_$branch-build${{ github.run_number }}/" > gradle.properties.tmp rm gradle.properties mv gradle.properties.tmp gradle.properties - - name: Build and publish - run: ./gradlew clean build publishAllPublicationsToGithubPackagesRepository -x signJsPublication -x signJvmPublication -x signKotlinMultiplatformPublication -x signMetadataPublication + - name: Build + run: ./gradlew build + - name: Publish + run: ./gradlew publishAllPublicationsToGithubPackagesRepository --no-parallel -x signJsPublication -x signJvmPublication -x signKotlinMultiplatformPublication -x signMetadataPublication env: GITHUBPACKAGES_USER: ${{ github.actor }} GITHUBPACKAGES_PASSWORD: ${{ secrets.GITHUB_TOKEN }} From 8d777e1c0ee031459524948ed638d19644887eea Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 16 Mar 2021 16:30:13 +0600 Subject: [PATCH 12/49] Update dokka version --- docs/gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/gradle.properties b/docs/gradle.properties index b5322eae27..21241f2d08 100644 --- a/docs/gradle.properties +++ b/docs/gradle.properties @@ -1,3 +1,3 @@ -dokka_version=1.4.20 +dokka_version=1.4.30 org.gradle.jvmargs=-Xmx1024m From 60c3a0d7af0fc385cecc565ac2b201cb594d6fab Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 16 Mar 2021 22:21:15 +0600 Subject: [PATCH 13/49] update core info about current version --- tgbotapi.core/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tgbotapi.core/README.md b/tgbotapi.core/README.md index 344aeace98..4728898a5b 100644 --- a/tgbotapi.core/README.md +++ b/tgbotapi.core/README.md @@ -10,7 +10,7 @@ moments are describing by official [Telegram Bot API](https://core.telegram.org/ ## Compatibility -This version compatible with [9th of March 2021 update of TelegramBotAPI (version 5.1)](https://core.telegram.org/bots/api#march-9-2021). +This version compatible with [9th of March 2021 update of TelegramBotAPI (version 5.1)](https://core.telegram.org/bots/api-changelog#march-9-2021). ## How to implement library? From 5c11b60ea6bc4b82ed534b8625da20ff18213679 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 16 Mar 2021 22:33:42 +0600 Subject: [PATCH 14/49] fix dokka config --- docs/build.gradle | 6 +++--- settings.gradle | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/docs/build.gradle b/docs/build.gradle index 24cfebd52a..4e89f2c27e 100644 --- a/docs/build.gradle +++ b/docs/build.gradle @@ -36,7 +36,7 @@ kotlin { dependencies { implementation kotlin('stdlib') - project.parent.subprojects.forEach { + rootProject.subprojects.forEach { if (it != project) { api it } @@ -82,11 +82,11 @@ tasks.dokkaHtml { } named("jsMain") { - sourceRoots.setFrom(findSourcesWithName("jsMain", "commonMain")) + sourceRoots.setFrom(findSourcesWithName("jsMain")) } named("jvmMain") { - sourceRoots.setFrom(findSourcesWithName("jvmMain", "commonMain")) + sourceRoots.setFrom(findSourcesWithName("jvmMain")) } } } diff --git a/settings.gradle b/settings.gradle index 5ac47a3651..33e593255e 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,4 +1,11 @@ pluginManagement { + resolutionStrategy { + eachPlugin { + if (requested.id.id == "org.jetbrains.dokka") { + useModule("org.jetbrains.dokka:dokka-gradle-plugin:${requested.version}") + } + } + } repositories { gradlePluginPortal() jcenter() From 210a52485b8355f76e7e2e2460839424eeea93df Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 16 Mar 2021 22:39:54 +0600 Subject: [PATCH 15/49] add kdocs yml config --- .github/workflows/kdocs.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/kdocs.yml diff --git a/.github/workflows/kdocs.yml b/.github/workflows/kdocs.yml new file mode 100644 index 0000000000..7f85e41be1 --- /dev/null +++ b/.github/workflows/kdocs.yml @@ -0,0 +1,22 @@ + +name: Publish package to GitHub Packages +on: + push: + branches: + - master +jobs: + publishing: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Build + run: ./gradlew dokkaHtml + - name: Publish KDocs + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./docs/build/dokka/html + publish_branch: kdocs From 6dd27cb0bf18fe19cd79157ae26c17b755e22b0b Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 16 Mar 2021 22:41:45 +0600 Subject: [PATCH 16/49] fixes in names of workflows --- .github/workflows/kdocs.yml | 3 +-- .github/workflows/packages_publishing.yml | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/kdocs.yml b/.github/workflows/kdocs.yml index 7f85e41be1..a167050ff8 100644 --- a/.github/workflows/kdocs.yml +++ b/.github/workflows/kdocs.yml @@ -1,5 +1,4 @@ - -name: Publish package to GitHub Packages +name: Publish KDocs on: push: branches: diff --git a/.github/workflows/packages_publishing.yml b/.github/workflows/packages_publishing.yml index 5165fc78a9..21dd2a8cc8 100644 --- a/.github/workflows/packages_publishing.yml +++ b/.github/workflows/packages_publishing.yml @@ -1,4 +1,3 @@ - name: Publish package to GitHub Packages on: [push] jobs: From dbdd9b5ad2a7a817bf9ef27d9dac72eda645a5a0 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 16 Mar 2021 23:01:26 +0600 Subject: [PATCH 17/49] update dokka --- docs/build.gradle | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/build.gradle b/docs/build.gradle index 4e89f2c27e..d543950490 100644 --- a/docs/build.gradle +++ b/docs/build.gradle @@ -56,7 +56,7 @@ private List findSourcesWithName(String... approximateNames) }.collect { it.kotlin } } -tasks.dokkaHtml { +Object callback = { switch (true) { case project.hasProperty("DOKKA_PATH"): outputDirectory = project.property("DOKKA_PATH").toString() @@ -90,3 +90,6 @@ tasks.dokkaHtml { } } } + +tasks.dokkaGfm(callback) +tasks.dokkaHtml(callback) From d14ca7bbdc6f80258fc1969b8adeeb7d1b45c497 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 17 Mar 2021 21:13:52 +0600 Subject: [PATCH 18/49] Update kdocs.yml --- .github/workflows/kdocs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/kdocs.yml b/.github/workflows/kdocs.yml index a167050ff8..d51a68e8a5 100644 --- a/.github/workflows/kdocs.yml +++ b/.github/workflows/kdocs.yml @@ -12,7 +12,7 @@ jobs: with: java-version: 1.8 - name: Build - run: ./gradlew dokkaHtml + run: ./gradlew dokkaGfm - name: Publish KDocs uses: peaceiris/actions-gh-pages@v3 with: From 308fb9274b58cd69ba46f1d2ffb194351b8834f8 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 17 Mar 2021 21:14:05 +0600 Subject: [PATCH 19/49] Update kdocs.yml --- .github/workflows/kdocs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/kdocs.yml b/.github/workflows/kdocs.yml index d51a68e8a5..b4aa4fe8ed 100644 --- a/.github/workflows/kdocs.yml +++ b/.github/workflows/kdocs.yml @@ -17,5 +17,5 @@ jobs: uses: peaceiris/actions-gh-pages@v3 with: github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./docs/build/dokka/html + publish_dir: ./docs/build/dokka/gfm publish_branch: kdocs From 3de3bb61337a6e0a4dab163a9ea2fa8f5e13eb85 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 19 Mar 2021 20:18:32 +0600 Subject: [PATCH 20/49] start 0.33.1 --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d5a5d1710..cad4cd21f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # TelegramBotAPI changelog +## 0.33.1 + ## 0.33.0 **UPDATE UP TO Telegram Bot API 5.1** diff --git a/gradle.properties b/gradle.properties index d338fd8535..1ca36552a2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,6 +17,6 @@ micro_utils_version=0.4.29 javax_activation_version=1.1.1 library_group=dev.inmo -library_version=0.33.0 +library_version=0.33.1 github_release_plugin_version=2.2.12 From 9f8e8ee21ba63594e93c452422d995b3c88e7f7d Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 19 Mar 2021 20:20:07 +0600 Subject: [PATCH 21/49] update dependencies --- CHANGELOG.md | 5 +++++ gradle.properties | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cad4cd21f7..26f27a8e69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## 0.33.1 +* `Common`: + * `Version`: + * `MicroUtils`: `0.4.29` -> `0.4.30` + * `Klocks`: `2.0.6` -> `2.0.7` + ## 0.33.0 **UPDATE UP TO Telegram Bot API 5.1** diff --git a/gradle.properties b/gradle.properties index 1ca36552a2..386d5dc86d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,11 +8,11 @@ kotlin.incremental.js=true kotlin_version=1.4.31 kotlin_coroutines_version=1.4.3 kotlin_serialisation_runtime_version=1.1.0 -klock_version=2.0.6 +klock_version=2.0.7 uuid_version=0.2.3 ktor_version=1.5.2 -micro_utils_version=0.4.29 +micro_utils_version=0.4.30 javax_activation_version=1.1.1 From 80093cb5a9d35e36988ce9614d235a4670670e86 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 21 Mar 2021 23:22:16 +0600 Subject: [PATCH 22/49] Update kdocs.yml --- .github/workflows/kdocs.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/kdocs.yml b/.github/workflows/kdocs.yml index b4aa4fe8ed..a167050ff8 100644 --- a/.github/workflows/kdocs.yml +++ b/.github/workflows/kdocs.yml @@ -12,10 +12,10 @@ jobs: with: java-version: 1.8 - name: Build - run: ./gradlew dokkaGfm + run: ./gradlew dokkaHtml - name: Publish KDocs uses: peaceiris/actions-gh-pages@v3 with: github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./docs/build/dokka/gfm + publish_dir: ./docs/build/dokka/html publish_branch: kdocs From 5b620014cb1a822b145467144a07798ce0af8105 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 24 Mar 2021 13:14:09 +0600 Subject: [PATCH 23/49] update kotlin version --- CHANGELOG.md | 1 + gradle.properties | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 26f27a8e69..93c4a23e0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * `Common`: * `Version`: + * `Kotlin`: `1.4.31` -> `1.4.32` * `MicroUtils`: `0.4.29` -> `0.4.30` * `Klocks`: `2.0.6` -> `2.0.7` diff --git a/gradle.properties b/gradle.properties index 386d5dc86d..3163a8b867 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ kotlin.js.generate.externals=true kotlin.incremental=true kotlin.incremental.js=true -kotlin_version=1.4.31 +kotlin_version=1.4.32 kotlin_coroutines_version=1.4.3 kotlin_serialisation_runtime_version=1.1.0 klock_version=2.0.7 From 1a5d1cde78f3da792db30b84a6626b4ffec0d257 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 24 Mar 2021 13:41:37 +0600 Subject: [PATCH 24/49] add parseCommandsWithParams for text inputs --- CHANGELOG.md | 2 + .../tgbotapi/CommonAbstracts/Captioned.kt | 1 + .../TextCaptionBotCommandsParser.kt | 63 +++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/TextCaptionBotCommandsParser.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 93c4a23e0e..2bf5ab0e0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ * `Kotlin`: `1.4.31` -> `1.4.32` * `MicroUtils`: `0.4.29` -> `0.4.30` * `Klocks`: `2.0.6` -> `2.0.7` +* `Utils Extensions`: + * Add extensions `parseCommandsWithParams` ## 0.33.0 diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Captioned.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Captioned.kt index 7cee50ae0b..0b5ed05d2c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Captioned.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/Captioned.kt @@ -6,6 +6,7 @@ interface Captioned { val caption: String? } +@Deprecated("This interface is not used in library and will be removed soon") interface CaptionedOutput : Captioned { val parseMode: ParseMode? } diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/TextCaptionBotCommandsParser.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/TextCaptionBotCommandsParser.kt new file mode 100644 index 0000000000..4ad76dddac --- /dev/null +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/TextCaptionBotCommandsParser.kt @@ -0,0 +1,63 @@ +package dev.inmo.tgbotapi.extensions.utils.extensions + +import dev.inmo.tgbotapi.CommonAbstracts.* +import dev.inmo.tgbotapi.types.MessageEntity.textsources.BotCommandTextSource +import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage +import dev.inmo.tgbotapi.types.message.content.TextContent +import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent + + +val defaultArgsSeparator = Regex(" ") +/** + * Parse commands and their args. Logic will find command, get all subsequent data as args until new command + */ +fun List.parseCommandsWithParams( + argsSeparator: Regex = defaultArgsSeparator +): MutableMap> { + val result = mutableMapOf>() + var currentBotCommandSource: BotCommandTextSource? = null + var currentArgs = "" + fun includeCurrent() = currentBotCommandSource ?.let { + result[it.command] = currentArgs.split(argsSeparator).toTypedArray() + currentArgs = "" + } + for (textSource in this) { + if (textSource is BotCommandTextSource) { + includeCurrent() + currentBotCommandSource = textSource + } else { + currentArgs += textSource.source + } + } + includeCurrent() + return result +} + +/** + * Parse commands and their args. Logic will find command, get all subsequent data as args until new command + */ +fun TextedInput.parseCommandsWithParams( + argsSeparator: Regex = defaultArgsSeparator +) = textSources.parseCommandsWithParams(argsSeparator) + +/** + * Parse commands and their args. Logic will find command, get all subsequent data as args until new command + */ +fun TextedOutput.parseCommandsWithParams( + argsSeparator: Regex = defaultArgsSeparator +) = entities ?.parseCommandsWithParams(argsSeparator) ?: emptyMap() + +/** + * Parse commands and their args. Logic will find command, get all subsequent data as args until new command + */ +fun CaptionedInput.parseCommandsWithParams( + argsSeparator: Regex = defaultArgsSeparator +) = textSources.parseCommandsWithParams(argsSeparator) + +fun ContentMessage.parseCommandsWithParams( + argsSeparator: Regex = defaultArgsSeparator +) = content.parseCommandsWithParams(argsSeparator) + +fun ContentMessage.parseCommandsWithParams( + argsSeparator: Regex = defaultArgsSeparator +) where T : CaptionedInput, T : MessageContent = content.parseCommandsWithParams(argsSeparator) From 1ddd138ff7eb4d731d4c1fa6e603c2c5b307df14 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 24 Mar 2021 13:44:27 +0600 Subject: [PATCH 25/49] update kdocs for new function --- .../utils/extensions/TextCaptionBotCommandsParser.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/TextCaptionBotCommandsParser.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/TextCaptionBotCommandsParser.kt index 4ad76dddac..1eba49b1f4 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/TextCaptionBotCommandsParser.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/TextCaptionBotCommandsParser.kt @@ -54,10 +54,16 @@ fun CaptionedInput.parseCommandsWithParams( argsSeparator: Regex = defaultArgsSeparator ) = textSources.parseCommandsWithParams(argsSeparator) +/** + * Parse commands and their args. Logic will find command, get all subsequent data as args until new command + */ fun ContentMessage.parseCommandsWithParams( argsSeparator: Regex = defaultArgsSeparator ) = content.parseCommandsWithParams(argsSeparator) +/** + * Parse commands and their args. Logic will find command, get all subsequent data as args until new command + */ fun ContentMessage.parseCommandsWithParams( argsSeparator: Regex = defaultArgsSeparator ) where T : CaptionedInput, T : MessageContent = content.parseCommandsWithParams(argsSeparator) From 112c86c9da0e4d162541b03183cfdf14c01d8939 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 24 Mar 2021 13:56:51 +0600 Subject: [PATCH 26/49] remove caption based messages extension for parsing of commands --- .../utils/extensions/TextCaptionBotCommandsParser.kt | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/TextCaptionBotCommandsParser.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/TextCaptionBotCommandsParser.kt index 1eba49b1f4..86a63efb23 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/TextCaptionBotCommandsParser.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/TextCaptionBotCommandsParser.kt @@ -60,10 +60,3 @@ fun CaptionedInput.parseCommandsWithParams( fun ContentMessage.parseCommandsWithParams( argsSeparator: Regex = defaultArgsSeparator ) = content.parseCommandsWithParams(argsSeparator) - -/** - * Parse commands and their args. Logic will find command, get all subsequent data as args until new command - */ -fun ContentMessage.parseCommandsWithParams( - argsSeparator: Regex = defaultArgsSeparator -) where T : CaptionedInput, T : MessageContent = content.parseCommandsWithParams(argsSeparator) From 0b2f7a38992c6f0d11c79ccd3cb133b1d46474fc Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 26 Mar 2021 07:03:33 +0600 Subject: [PATCH 27/49] update condition for ReplyMessageNotFoundException --- .../kotlin/dev/inmo/tgbotapi/bot/exceptions/RequestException.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/exceptions/RequestException.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/exceptions/RequestException.kt index 687392c696..a9c6ec5f56 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/exceptions/RequestException.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/exceptions/RequestException.kt @@ -12,7 +12,7 @@ fun newRequestException( cause: Throwable? = null ) = response.description ?.let { description -> when { - description == "Bad Request: reply message not found" -> ReplyMessageNotFoundException(response, plainAnswer, message, cause) + description == "Bad Request: reply message not found" || description == "Bad Request: replied message not found" -> ReplyMessageNotFoundException(response, plainAnswer, message, cause) description == "Bad Request: message to edit not found" -> MessageToEditNotFoundException(response, plainAnswer, message, cause) description.contains("Bad Request: message is not modified") -> MessageIsNotModifiedException(response, plainAnswer, message, cause) description == "Unauthorized" -> UnauthorizedException(response, plainAnswer, message, cause) From 8ced95bc2fc794ef027845f7ce3d4205081d0e7f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 3 Apr 2021 14:24:24 +0600 Subject: [PATCH 28/49] start 0.33.2 --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bf5ab0e0e..33578c2c72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # TelegramBotAPI changelog +## 0.33.2 + ## 0.33.1 * `Common`: diff --git a/gradle.properties b/gradle.properties index 3163a8b867..5232c342b4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,6 +17,6 @@ micro_utils_version=0.4.30 javax_activation_version=1.1.1 library_group=dev.inmo -library_version=0.33.1 +library_version=0.33.2 github_release_plugin_version=2.2.12 From e2e235bd6c2f383c0c68a637dc91c5d8905083f2 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 3 Apr 2021 14:51:21 +0600 Subject: [PATCH 29/49] behaviour builder updates --- CHANGELOG.md | 8 ++++++++ .../expectations/WaitCallbackQuery.kt | 2 +- .../expectations/WaitChatMemberUpdated.kt | 2 +- .../expectations/WaitInlineQuery.kt | 2 +- .../expectations/WaitMediaGroup.kt | 16 +++++++++------- .../triggers_handling/CommandHandling.kt | 14 ++++++++++---- 6 files changed, 30 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33578c2c72..d321c74513 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ ## 0.33.2 +* `Behaviour Builder`: + * New typealias `MediaGroupFilter` has been added for `MediaGroup` expectators + * Several typealiases became `suspend`: + * `CallbackQueryMapper` + * `ChatMemberUpdatedMapper` + * `InlineQueryMapper` + * Commands got an additional parameter - `additionalFilter`. It will be called when all command filters were passed + ## 0.33.1 * `Common`: diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitCallbackQuery.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitCallbackQuery.kt index dc0e8645c9..c279181bb9 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitCallbackQuery.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitCallbackQuery.kt @@ -8,7 +8,7 @@ import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.types.CallbackQuery.* import kotlinx.coroutines.flow.toList -typealias CallbackQueryMapper = T.() -> T? +typealias CallbackQueryMapper = suspend T.() -> T? private suspend fun BehaviourContext.waitCallbackQueries( count: Int = 1, diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitChatMemberUpdated.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitChatMemberUpdated.kt index 8e69298190..ccdbd3051b 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitChatMemberUpdated.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitChatMemberUpdated.kt @@ -11,7 +11,7 @@ import dev.inmo.tgbotapi.types.update.MyChatMemberUpdatedUpdate import dev.inmo.tgbotapi.types.update.abstracts.ChatMemberUpdatedUpdate import kotlinx.coroutines.flow.toList -typealias ChatMemberUpdatedMapper = T.() -> T? +typealias ChatMemberUpdatedMapper = suspend T.() -> T? private suspend inline fun BehaviourContext.waitChatMemberUpdated( count: Int = 1, diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitInlineQuery.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitInlineQuery.kt index 1e34de13eb..c3de533c8e 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitInlineQuery.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitInlineQuery.kt @@ -8,7 +8,7 @@ import dev.inmo.tgbotapi.types.InlineQueries.query.BaseInlineQuery import dev.inmo.tgbotapi.types.InlineQueries.query.LocationInlineQuery import kotlinx.coroutines.flow.toList -typealias InlineQueryMapper = T.() -> T? +typealias InlineQueryMapper = suspend T.() -> T? private suspend fun BehaviourContext.waitInlineQueries( count: Int = 1, diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitMediaGroup.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitMediaGroup.kt index 5aa0bc8e90..d4602bc334 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitMediaGroup.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitMediaGroup.kt @@ -11,12 +11,14 @@ import dev.inmo.tgbotapi.utils.PreviewFeature import kotlinx.coroutines.flow.take import kotlinx.coroutines.flow.toList +typealias MediaGroupFilter = suspend List>.() -> Boolean + @PreviewFeature internal suspend inline fun BehaviourContext.buildMediaGroupWaiter( count: Int = 1, initRequest: Request<*>? = null, noinline errorFactory: NullableRequestBuilder<*> = { null }, - noinline filter: (suspend (List>) -> Boolean)? = null + noinline filter: MediaGroupFilter? = null ) = flowsUpdatesFilter.expectFlow(bot, initRequest, count, errorFactory) { update -> update.asSentMediaGroupUpdate() ?.data ?.let { mediaGroup -> if (mediaGroup.all { message -> message.content is T } && (filter == null || filter(mediaGroup as List>))) { @@ -33,35 +35,35 @@ suspend fun BehaviourContext.waitMediaGroup( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: (suspend (List>) -> Boolean)? = null + filter: MediaGroupFilter? = null ) = buildMediaGroupWaiter(count, initRequest, errorFactory, filter) suspend fun BehaviourContext.waitPlaylist( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: (suspend (List>) -> Boolean)? = null + filter: MediaGroupFilter? = null ) = buildMediaGroupWaiter(count, initRequest, errorFactory, filter) suspend fun BehaviourContext.waitDocumentsGroup( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: (suspend (List>) -> Boolean)? = null + filter: MediaGroupFilter? = null ) = buildMediaGroupWaiter(count, initRequest, errorFactory, filter) suspend fun BehaviourContext.waitVisualGallery( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: (suspend (List>) -> Boolean)? = null + filter: MediaGroupFilter? = null ) = buildMediaGroupWaiter(count, initRequest, errorFactory, filter) suspend fun BehaviourContext.waitPhotoGallery( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: (suspend (List>) -> Boolean)? = null + filter: MediaGroupFilter? = null ) = buildMediaGroupWaiter(count, initRequest, errorFactory, filter) suspend fun BehaviourContext.waitVideoGallery( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: (suspend (List>) -> Boolean)? = null + filter: MediaGroupFilter? = null ) = buildMediaGroupWaiter(count, initRequest, errorFactory, filter) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CommandHandling.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CommandHandling.kt index 35c88e1f0e..0946a99140 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CommandHandling.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CommandHandling.kt @@ -11,6 +11,7 @@ suspend fun BehaviourContext.command( commandRegex: Regex, requireOnlyCommandInMessage: Boolean = true, includeFilterByChatInBehaviourSubContext: Boolean = true, + additionalFilter: CommonMessageFilter? = null, scenarioReceiver: BehaviourContextAndTypeReceiver> ): Job = onText( includeFilterByChatInBehaviourSubContext, @@ -22,7 +23,9 @@ suspend fun BehaviourContext.command( } else { true } - sizeRequirement && textSources.any { commandRegex.matches(it.asBotCommandTextSource() ?.command ?: return@any false) } + sizeRequirement && textSources.any { + commandRegex.matches(it.asBotCommandTextSource() ?.command ?: return@any false) + } && (additionalFilter ?.invoke(message) != false) }, scenarioReceiver ) @@ -30,19 +33,22 @@ suspend fun BehaviourContext.command( command: String, requireOnlyCommandInMessage: Boolean = true, includeFilterByChatInBehaviourSubContext: Boolean = true, + additionalFilter: CommonMessageFilter? = null, scenarioReceiver: BehaviourContextAndTypeReceiver> -) = command(command.toRegex(), requireOnlyCommandInMessage, includeFilterByChatInBehaviourSubContext, scenarioReceiver) +) = command(command.toRegex(), requireOnlyCommandInMessage, includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) suspend inline fun BehaviourContext.onCommand( commandRegex: Regex, requireOnlyCommandInMessage: Boolean = true, includeFilterByChatInBehaviourSubContext: Boolean = true, + noinline additionalFilter: CommonMessageFilter? = null, noinline scenarioReceiver: BehaviourContextAndTypeReceiver> -): Job = command(commandRegex, requireOnlyCommandInMessage, includeFilterByChatInBehaviourSubContext, scenarioReceiver) +): Job = command(commandRegex, requireOnlyCommandInMessage, includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) suspend inline fun BehaviourContext.onCommand( command: String, requireOnlyCommandInMessage: Boolean = true, includeFilterByChatInBehaviourSubContext: Boolean = true, + noinline additionalFilter: CommonMessageFilter? = null, noinline scenarioReceiver: BehaviourContextAndTypeReceiver> -): Job = onCommand(command.toRegex(), requireOnlyCommandInMessage, includeFilterByChatInBehaviourSubContext, scenarioReceiver) +): Job = onCommand(command.toRegex(), requireOnlyCommandInMessage, includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) From 4e5546083442234fcfbacfcd94c3165c68a4152f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 3 Apr 2021 15:05:25 +0600 Subject: [PATCH 30/49] fix in doInSubContext --- .../tgbotapi/extensions/behaviour_builder/BehaviourContext.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext.kt index 4ff49827ce..109ef09513 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext.kt @@ -57,10 +57,10 @@ suspend fun BehaviourContext.doInSubContextWithUpdatesFilter( ) = doInSubContextWithFlowsUpdatesFilterSetup( newFlowsUpdatesFilterSetUp = updatesFilter ?.let { { oldOne -> - oldOne.allUpdatesFlow.filter { updatesFilter(it) }.subscribeSafelyWithoutExceptions(scope, asUpdateReceiver) + oldOne.allUpdatesFlow.filter { updatesFilter(it) }.subscribeSafelyWithoutExceptions(this, asUpdateReceiver) } } ?: { oldOne -> - oldOne.allUpdatesFlow.subscribeSafelyWithoutExceptions(scope, asUpdateReceiver) + oldOne.allUpdatesFlow.subscribeSafelyWithoutExceptions(this, asUpdateReceiver) }, stopOnCompletion, behaviourContextReceiver From 353df431094f342fe55a8811dc7102c55cbe6eda Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 3 Apr 2021 15:13:20 +0600 Subject: [PATCH 31/49] update microutils --- CHANGELOG.md | 3 +++ gradle.properties | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d321c74513..57b2144a82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 0.33.2 +* `Common`: + * `Version`: + * `MicroUtils`: `0.4.30` -> `0.4.32` * `Behaviour Builder`: * New typealias `MediaGroupFilter` has been added for `MediaGroup` expectators * Several typealiases became `suspend`: diff --git a/gradle.properties b/gradle.properties index 5232c342b4..ac96ac1f7e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ klock_version=2.0.7 uuid_version=0.2.3 ktor_version=1.5.2 -micro_utils_version=0.4.30 +micro_utils_version=0.4.32 javax_activation_version=1.1.1 From f4b1e4a150fedaea1cb39ffdec72e2dafdc27349 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 5 Apr 2021 13:42:48 +0600 Subject: [PATCH 32/49] start 0.33.3 --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57b2144a82..693b3fcc95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # TelegramBotAPI changelog +## 0.33.3 + ## 0.33.2 * `Common`: diff --git a/gradle.properties b/gradle.properties index ac96ac1f7e..2deb99c0d0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,6 +17,6 @@ micro_utils_version=0.4.32 javax_activation_version=1.1.1 library_group=dev.inmo -library_version=0.33.2 +library_version=0.33.3 github_release_plugin_version=2.2.12 From b975a1b036149602910335babcf0e887f7454cfc Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 5 Apr 2021 16:41:27 +0600 Subject: [PATCH 33/49] updates in behaviour builder --- CHANGELOG.md | 4 ++ .../behaviour_builder/BehaviourContext.kt | 39 +++++++++++-------- .../CallbackQueryTriggers.kt | 3 +- .../ChatMemberUpdatedTriggers.kt | 3 +- .../triggers_handling/ContentTriggers.kt | 3 +- .../triggers_handling/EventTriggers.kt | 3 +- .../triggers_handling/InlineQueryTriggers.kt | 3 +- .../triggers_handling/MediaGroupTriggers.kt | 3 +- .../triggers_handling/PassportTriggers.kt | 3 +- 9 files changed, 41 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 693b3fcc95..6eb9564e5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 0.33.3 +* `Behaviour Builder`: + * Rewrite logic of `doInSubContextWithUpdatesFilter` and `doInSubContextWithFlowsUpdatesFilterSetup` extensions + * All triggers now work with `stopOnCompletion` set up to `false` + ## 0.33.2 * `Common`: diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext.kt index 109ef09513..525ba7b046 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext.kt @@ -36,12 +36,13 @@ suspend fun BehaviourContext.doInSubContextWithFlowsUpdatesFilterSetup( newFlowsUpdatesFilterSetUp: BehaviourContextAndTypeReceiver?, stopOnCompletion: Boolean = true, behaviourContextReceiver: BehaviourContextReceiver -) = copy( - flowsUpdatesFilter = FlowsUpdatesFilter(), - scope = CoroutineScope(scope.coroutineContext + SupervisorJob()) -).run { +): T = supervisorScope { + val newContext = copy( + flowsUpdatesFilter = FlowsUpdatesFilter(), + scope = this + ) newFlowsUpdatesFilterSetUp ?.let { - it.apply { invoke(this@run, this@doInSubContextWithFlowsUpdatesFilterSetup.flowsUpdatesFilter) } + it.apply { invoke(newContext, this@doInSubContextWithFlowsUpdatesFilterSetup.flowsUpdatesFilter) } } behaviourContextReceiver().also { if (stopOnCompletion) stop() } } @@ -54,17 +55,23 @@ suspend fun BehaviourContext.doInSubContextWithUpdatesFilter( updatesFilter: BehaviourContextAndTypeReceiver?, stopOnCompletion: Boolean = true, behaviourContextReceiver: BehaviourContextReceiver -) = doInSubContextWithFlowsUpdatesFilterSetup( - newFlowsUpdatesFilterSetUp = updatesFilter ?.let { - { oldOne -> - oldOne.allUpdatesFlow.filter { updatesFilter(it) }.subscribeSafelyWithoutExceptions(this, asUpdateReceiver) - } - } ?: { oldOne -> - oldOne.allUpdatesFlow.subscribeSafelyWithoutExceptions(this, asUpdateReceiver) - }, - stopOnCompletion, - behaviourContextReceiver -) +): T { + val updatesScope = CoroutineScope(coroutineContext + SupervisorJob()) + + return doInSubContextWithFlowsUpdatesFilterSetup( + newFlowsUpdatesFilterSetUp = updatesFilter ?.let { + { oldOne -> + oldOne.allUpdatesFlow.filter { updatesFilter(it) }.subscribeSafelyWithoutExceptions(updatesScope, asUpdateReceiver) + } + } ?: { oldOne -> + oldOne.allUpdatesFlow.subscribeSafelyWithoutExceptions(updatesScope, asUpdateReceiver) + }, + stopOnCompletion + ) { + coroutineContext.job.invokeOnCompletion { updatesScope.cancel() } + behaviourContextReceiver() + } +} suspend fun BehaviourContext.doInSubContext( stopOnCompletion: Boolean = true, diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggers.kt index 8e0f9724f8..1c604ec76f 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggers.kt @@ -26,7 +26,8 @@ internal suspend inline fun BehaviourContext.onCallb { it.sourceChat() ?.id ?.chatId == triggerQuery.user.id.chatId } } else { null - } + }, + stopOnCompletion = false ) { scenarioReceiver(triggerQuery) } diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatMemberUpdatedTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatMemberUpdatedTriggers.kt index 1156af2648..66676f7c6e 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatMemberUpdatedTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ChatMemberUpdatedTriggers.kt @@ -24,7 +24,8 @@ internal suspend inline fun BehaviourConte { it.sourceChat() ?.id ?.chatId == triggerChatMemberUpdated.chat.id.chatId } } else { null - } + }, + stopOnCompletion = false ) { scenarioReceiver(triggerChatMemberUpdated) } diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ContentTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ContentTriggers.kt index 493b58f0ee..b649fe7f90 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ContentTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ContentTriggers.kt @@ -50,7 +50,8 @@ internal suspend inline fun BehaviourContext.onCont { it.sourceChat() ?.id ?.chatId == triggerMessage.chat.id.chatId } } else { null - } + }, + stopOnCompletion = false ) { scenarioReceiver(triggerMessage) } diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt index 6940426c78..62144e443c 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt @@ -29,7 +29,8 @@ internal suspend inline fun BehaviourContext.onEvent( doInSubContextWithUpdatesFilter( updatesFilter = if (includeFilterByChatInBehaviourSubContext) { { it.sourceChat() ?.id ?.chatId == triggerMessage.chat.id.chatId } - } else null + } else null, + stopOnCompletion = false ) { scenarioReceiver(triggerMessage) } diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/InlineQueryTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/InlineQueryTriggers.kt index 317943df52..bc55ed4afd 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/InlineQueryTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/InlineQueryTriggers.kt @@ -27,7 +27,8 @@ internal suspend inline fun BehaviourContext.onInlineQ { it.sourceChat() ?.id ?.chatId == triggerQuery.from.id.chatId } } else { null - } + }, + stopOnCompletion = false ) { scenarioReceiver(triggerQuery) } diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/MediaGroupTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/MediaGroupTriggers.kt index 31a9b9d11c..b49865f902 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/MediaGroupTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/MediaGroupTriggers.kt @@ -32,7 +32,8 @@ internal suspend inline fun BehaviourContext.bui doInSubContextWithUpdatesFilter( updatesFilter = if (includeFilterByChatInBehaviourSubContext) { { it.sourceChat() ?.id ?.chatId == mediaGroupChat.id.chatId } - } else null + } else null, + stopOnCompletion = false ) { scenarioReceiver(mediaGroup) } diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PassportTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PassportTriggers.kt index e954526b0e..92efd5f9cd 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PassportTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PassportTriggers.kt @@ -25,7 +25,8 @@ suspend inline fun BehaviourContext.onPas doInSubContextWithUpdatesFilter( updatesFilter = if (includeFilterByChatInBehaviourSubContext) { { it.sourceChat() ?.id ?.chatId == triggerMessage.chat.id.chatId } - } else null + } else null, + stopOnCompletion = false ) { scenarioReceiver(triggerMessage) } From 32ae9d2b16039da56ef3a3a1f3335a1f2440f82b Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 5 Apr 2021 16:50:31 +0600 Subject: [PATCH 34/49] hotfix --- .../tgbotapi/extensions/behaviour_builder/BehaviourContext.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext.kt index 525ba7b046..da1ce6739b 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext.kt @@ -44,7 +44,7 @@ suspend fun BehaviourContext.doInSubContextWithFlowsUpdatesFilterSetup( newFlowsUpdatesFilterSetUp ?.let { it.apply { invoke(newContext, this@doInSubContextWithFlowsUpdatesFilterSetup.flowsUpdatesFilter) } } - behaviourContextReceiver().also { if (stopOnCompletion) stop() } + newContext.behaviourContextReceiver().also { if (stopOnCompletion) stop() } } /** From 0831f2fa759c19b7bc70dd14626eae2b41629b42 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 5 Apr 2021 17:21:59 +0600 Subject: [PATCH 35/49] update microutils --- CHANGELOG.md | 3 +++ gradle.properties | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6eb9564e5c..00dde954ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 0.33.3 +* `Common`: + * `Version`: + * `MicroUtils`: `0.4.32` -> `0.4.33` * `Behaviour Builder`: * Rewrite logic of `doInSubContextWithUpdatesFilter` and `doInSubContextWithFlowsUpdatesFilterSetup` extensions * All triggers now work with `stopOnCompletion` set up to `false` diff --git a/gradle.properties b/gradle.properties index 2deb99c0d0..19b89239ee 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ klock_version=2.0.7 uuid_version=0.2.3 ktor_version=1.5.2 -micro_utils_version=0.4.32 +micro_utils_version=0.4.33 javax_activation_version=1.1.1 From 019b260888861dfb92c8bc0db70f7cf795b71e85 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 5 Apr 2021 18:11:29 +0600 Subject: [PATCH 36/49] update ktor --- CHANGELOG.md | 1 + gradle.properties | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00dde954ff..3c80a78b58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * `Common`: * `Version`: * `MicroUtils`: `0.4.32` -> `0.4.33` + * `Ktor`: `1.5.2` -> `1.5.3` * `Behaviour Builder`: * Rewrite logic of `doInSubContextWithUpdatesFilter` and `doInSubContextWithFlowsUpdatesFilterSetup` extensions * All triggers now work with `stopOnCompletion` set up to `false` diff --git a/gradle.properties b/gradle.properties index 19b89239ee..dff1d0b1aa 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,7 @@ kotlin_coroutines_version=1.4.3 kotlin_serialisation_runtime_version=1.1.0 klock_version=2.0.7 uuid_version=0.2.3 -ktor_version=1.5.2 +ktor_version=1.5.3 micro_utils_version=0.4.33 From f90ae2f9182cd6541f23d489f0f80bae0a941550 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 5 Apr 2021 18:15:10 +0600 Subject: [PATCH 37/49] include weakLaunch in behaviour builder --- .../behaviour_builder/BehaviourContext.kt | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext.kt index da1ce6739b..f4d91975fb 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions +import dev.inmo.micro_utils.coroutines.weakLaunch import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.types.update.abstracts.Update import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter @@ -55,23 +56,21 @@ suspend fun BehaviourContext.doInSubContextWithUpdatesFilter( updatesFilter: BehaviourContextAndTypeReceiver?, stopOnCompletion: Boolean = true, behaviourContextReceiver: BehaviourContextReceiver -): T { - val updatesScope = CoroutineScope(coroutineContext + SupervisorJob()) - - return doInSubContextWithFlowsUpdatesFilterSetup( - newFlowsUpdatesFilterSetUp = updatesFilter ?.let { - { oldOne -> - oldOne.allUpdatesFlow.filter { updatesFilter(it) }.subscribeSafelyWithoutExceptions(updatesScope, asUpdateReceiver) +): T = doInSubContextWithFlowsUpdatesFilterSetup( + newFlowsUpdatesFilterSetUp = updatesFilter ?.let { + { oldOne -> + weakLaunch { + oldOne.allUpdatesFlow.filter { updatesFilter(it) }.subscribeSafelyWithoutExceptions(this, asUpdateReceiver) } - } ?: { oldOne -> - oldOne.allUpdatesFlow.subscribeSafelyWithoutExceptions(updatesScope, asUpdateReceiver) - }, - stopOnCompletion - ) { - coroutineContext.job.invokeOnCompletion { updatesScope.cancel() } - behaviourContextReceiver() - } -} + } + } ?: { oldOne -> + weakLaunch { + oldOne.allUpdatesFlow.subscribeSafelyWithoutExceptions(this, asUpdateReceiver) + } + }, + stopOnCompletion, + behaviourContextReceiver +) suspend fun BehaviourContext.doInSubContext( stopOnCompletion: Boolean = true, From fc1a029acbb34662fa35a267b8972039f6b90780 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 5 Apr 2021 19:06:49 +0600 Subject: [PATCH 38/49] fix of #358 --- .../kotlin/dev/inmo/tgbotapi/types/Common.kt | 2 + .../extensions/api/send/SendActionDSL.kt | 76 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendActionDSL.kt diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index 8fc47f2a24..c1c935fb26 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -80,6 +80,8 @@ val openPeriodPollSecondsLimit = 5 .. 600 val membersLimit = 1 .. 99999 +const val botActionActualityTime: Seconds = 5 + // Made as lazy for correct work in K/JS val telegramInlineModeGifPermittedMimeTypes by lazy { listOf( diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendActionDSL.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendActionDSL.kt new file mode 100644 index 0000000000..13e964debe --- /dev/null +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/SendActionDSL.kt @@ -0,0 +1,76 @@ +package dev.inmo.tgbotapi.extensions.api.send + +import dev.inmo.micro_utils.coroutines.safely +import dev.inmo.micro_utils.coroutines.safelyWithoutExceptions +import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.requests.send.SendAction +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.actions.* +import dev.inmo.tgbotapi.types.chat.abstracts.Chat +import kotlinx.coroutines.* + +private const val refreshTime: MilliSeconds = (botActionActualityTime - 1) * 1000L +typealias TelegramBotActionCallback = suspend TelegramBot.() -> T + +suspend fun TelegramBot.withAction( + actionRequest: SendAction, + block: TelegramBotActionCallback +): T { + val botActionJob = supervisorScope { + launch { + while (isActive) { + delay(refreshTime) + safelyWithoutExceptions { + execute(actionRequest) + } + } + } + } + return try { + safely { block() } + } finally { + botActionJob.cancel() + } +} + +suspend fun TelegramBot.withAction( + chatId: ChatId, + action: BotAction, + block: TelegramBotActionCallback +) = withAction( + SendAction(chatId, action), + block +) + +suspend fun TelegramBot.withAction( + chat: Chat, + action: BotAction, + block: TelegramBotActionCallback +) = withAction( + chat.id, + action, + block +) + +suspend fun TelegramBot.withTypingAction(chatId: ChatId, block: TelegramBotActionCallback) = withAction(chatId, TypingAction, block) +suspend fun TelegramBot.withUploadPhotoAction(chatId: ChatId, block: TelegramBotActionCallback) = withAction(chatId, UploadPhotoAction, block) +suspend fun TelegramBot.withRecordVideoAction(chatId: ChatId, block: TelegramBotActionCallback) = withAction(chatId, RecordVideoAction, block) +suspend fun TelegramBot.withUploadVideoAction(chatId: ChatId, block: TelegramBotActionCallback) = withAction(chatId, UploadVideoAction, block) +suspend fun TelegramBot.withRecordAudioAction(chatId: ChatId, block: TelegramBotActionCallback) = withAction(chatId, RecordAudioAction, block) +suspend fun TelegramBot.withUploadAudioAction(chatId: ChatId, block: TelegramBotActionCallback) = withAction(chatId, UploadAudioAction, block) +suspend fun TelegramBot.withUploadDocumentAction(chatId: ChatId, block: TelegramBotActionCallback) = withAction(chatId, UploadDocumentAction, block) +suspend fun TelegramBot.withFindLocationAction(chatId: ChatId, block: TelegramBotActionCallback) = withAction(chatId, FindLocationAction, block) +suspend fun TelegramBot.withRecordVideoNoteAction(chatId: ChatId, block: TelegramBotActionCallback) = withAction(chatId, RecordVideoNoteAction, block) +suspend fun TelegramBot.withUploadVideoNoteAction(chatId: ChatId, block: TelegramBotActionCallback) = withAction(chatId, UploadVideoNoteAction, block) + + +suspend fun TelegramBot.withTypingAction(chat: Chat, block: TelegramBotActionCallback) = withAction(chat, TypingAction, block) +suspend fun TelegramBot.withUploadPhotoAction(chat: Chat, block: TelegramBotActionCallback) = withAction(chat, UploadPhotoAction, block) +suspend fun TelegramBot.withRecordVideoAction(chat: Chat, block: TelegramBotActionCallback) = withAction(chat, RecordVideoAction, block) +suspend fun TelegramBot.withUploadVideoAction(chat: Chat, block: TelegramBotActionCallback) = withAction(chat, UploadVideoAction, block) +suspend fun TelegramBot.withRecordAudioAction(chat: Chat, block: TelegramBotActionCallback) = withAction(chat, RecordAudioAction, block) +suspend fun TelegramBot.withUploadAudioAction(chat: Chat, block: TelegramBotActionCallback) = withAction(chat, UploadAudioAction, block) +suspend fun TelegramBot.withUploadDocumentAction(chat: Chat, block: TelegramBotActionCallback) = withAction(chat, UploadDocumentAction, block) +suspend fun TelegramBot.withFindLocationAction(chat: Chat, block: TelegramBotActionCallback) = withAction(chat, FindLocationAction, block) +suspend fun TelegramBot.withRecordVideoNoteAction(chat: Chat, block: TelegramBotActionCallback) = withAction(chat, RecordVideoNoteAction, block) +suspend fun TelegramBot.withUploadVideoNoteAction(chat: Chat, block: TelegramBotActionCallback) = withAction(chat, UploadVideoNoteAction, block) From a42c5c63c410e07210136d9a3b0ea7bef0e4caab Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 5 Apr 2021 19:08:12 +0600 Subject: [PATCH 39/49] fillup changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c80a78b58..77d6445d2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ * `Version`: * `MicroUtils`: `0.4.32` -> `0.4.33` * `Ktor`: `1.5.2` -> `1.5.3` +* `API`: + * Bot actions DSL (fix for [#358](https://github.com/InsanusMokrassar/TelegramBotAPI/issues/358)) * `Behaviour Builder`: * Rewrite logic of `doInSubContextWithUpdatesFilter` and `doInSubContextWithFlowsUpdatesFilterSetup` extensions * All triggers now work with `stopOnCompletion` set up to `false` From 6b761ab37d71ab19bf1dc12d615fa5661a1f9e12 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 11 Apr 2021 04:06:30 +0600 Subject: [PATCH 40/49] Update gradle wrapper --- gradle/wrapper/gradle-wrapper.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 68ca99ac45..f2e1eb1fd4 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip From 6aba2ff6412608a3b5a87a6b00183e4003f5bf77 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 12 Apr 2021 20:57:12 +0600 Subject: [PATCH 41/49] start 0.33.4 --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77d6445d2e..2613c6f787 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # TelegramBotAPI changelog +## 0.33.4 + ## 0.33.3 * `Common`: diff --git a/gradle.properties b/gradle.properties index dff1d0b1aa..ae661b29b3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,6 +17,6 @@ micro_utils_version=0.4.33 javax_activation_version=1.1.1 library_group=dev.inmo -library_version=0.33.3 +library_version=0.33.4 github_release_plugin_version=2.2.12 From 0b361163f275a9d12ae3cb1a86414df9efc6a558 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 12 Apr 2021 23:23:18 +0600 Subject: [PATCH 42/49] TextSourceSerializer --- CHANGELOG.md | 4 + .../tgbotapi/CommonAbstracts/TextSource.kt | 12 +++ .../textsources/BoldTextSource.kt | 3 + .../textsources/BotCommandTextSource.kt | 2 + .../textsources/CashTagTextSource.kt | 2 + .../textsources/CodeTextSource.kt | 2 + .../textsources/EMailTextSource.kt | 2 + .../textsources/HashTagTextSource.kt | 2 + .../textsources/ItalicTextSource.kt | 2 + .../textsources/MentionTextSource.kt | 2 + .../textsources/PhoneNumberTextSource.kt | 2 + .../textsources/PreTextSource.kt | 2 + .../textsources/RegularTextSource.kt | 2 + .../textsources/StrikethroughTextSource.kt | 2 + .../textsources/TextLinkTextSource.kt | 2 + .../textsources/TextMentionTextSource.kt | 2 + .../textsources/TextSourceSerializer.kt | 92 +++++++++++++++++++ .../textsources/URLTextSource.kt | 2 + .../textsources/UnderlineTextSource.kt | 2 + .../inmo/tgbotapi/types/TextSourcesTests.kt | 40 ++++++++ 20 files changed, 181 insertions(+) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextSourceSerializer.kt create mode 100644 tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/TextSourcesTests.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 2613c6f787..c266f5b742 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 0.33.4 +* `Core`: + * All `TextSource` implementators have become `Serializable` + * New serializer `TextSourceSerializer` + ## 0.33.3 * `Common`: 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 06481a6ebe..05590f49b4 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 @@ -1,14 +1,17 @@ package dev.inmo.tgbotapi.CommonAbstracts +import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourceSerializer import dev.inmo.tgbotapi.types.MessageEntity.textsources.regular import dev.inmo.tgbotapi.types.MessageEntity.toTextParts import dev.inmo.tgbotapi.types.captionLength import dev.inmo.tgbotapi.types.textLength +import kotlinx.serialization.Serializable const val DirectInvocationOfTextSourceConstructor = "It is strongly not recommended to use constructors directly instead of factory methods" typealias TextSourcesList = List +@Serializable(TextSourceSerializer::class) interface TextSource { val markdown: String val markdownV2: String @@ -17,6 +20,10 @@ interface TextSource { val asText: String get() = source + + companion object { + fun serializer() = TextSourceSerializer + } } @Suppress("NOTHING_TO_INLINE") @@ -28,8 +35,13 @@ inline operator fun TextSource.plus(text: String) = listOf(this, regular(text)) @Suppress("NOTHING_TO_INLINE") inline operator fun List.plus(text: String) = this + regular(text) +@Serializable(TextSourceSerializer::class) interface MultilevelTextSource : TextSource { val subsources: List + + companion object { + fun serializer() = TextSourceSerializer + } } data class TextPart( 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 83223e01cb..b577bc040f 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 @@ -3,10 +3,13 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.internal.* +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable /** * @see bold */ +@Serializable data class BoldTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, override val subsources: List diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BotCommandTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BotCommandTextSource.kt index 83d00409a0..8b3f90403d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BotCommandTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/BotCommandTextSource.kt @@ -4,12 +4,14 @@ import dev.inmo.tgbotapi.CommonAbstracts.DirectInvocationOfTextSourceConstructor import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.internal.* +import kotlinx.serialization.Serializable private val commandRegex = Regex("[/!][^@\\s]*") /** * @see botCommand */ +@Serializable data class BotCommandTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String ) : TextSource { 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 eb80cbf655..cabb84237d 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 @@ -3,10 +3,12 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.internal.* +import kotlinx.serialization.Serializable /** * @see cashTag */ +@Serializable data class CashTagTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, override val subsources: List diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CodeTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CodeTextSource.kt index e71c556e9e..e96dc0f45c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CodeTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/CodeTextSource.kt @@ -4,10 +4,12 @@ import dev.inmo.tgbotapi.CommonAbstracts.DirectInvocationOfTextSourceConstructor import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.internal.* +import kotlinx.serialization.Serializable /** * @see code */ +@Serializable data class CodeTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String ) : TextSource { 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 83311b871e..515d8dd343 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 @@ -3,10 +3,12 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.internal.* +import kotlinx.serialization.Serializable /** * @see email */ +@Serializable data class EMailTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, override val subsources: List 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 3b33b8faf0..506bc6a584 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 @@ -3,10 +3,12 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.internal.* +import kotlinx.serialization.Serializable /** * @see hashtag */ +@Serializable data class HashTagTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, override val subsources: List 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 e72ed0b357..61bb66bde3 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 @@ -3,10 +3,12 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.internal.* +import kotlinx.serialization.Serializable /** * @see italic */ +@Serializable data class ItalicTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, override val subsources: List 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 288a191773..0dce181677 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 @@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.internal.* +import kotlinx.serialization.Serializable private val String.withoutCommercialAt get() = if (startsWith("@")) { @@ -14,6 +15,7 @@ private val String.withoutCommercialAt /** * @see mention */ +@Serializable data class MentionTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, override val subsources: List 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 e17c1ec716..ae1ef0239f 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 @@ -3,10 +3,12 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.internal.* +import kotlinx.serialization.Serializable /** * @see phone */ +@Serializable data class PhoneNumberTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, override val subsources: List diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PreTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PreTextSource.kt index e22910e0f1..a29ce643ea 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PreTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/PreTextSource.kt @@ -4,10 +4,12 @@ import dev.inmo.tgbotapi.CommonAbstracts.DirectInvocationOfTextSourceConstructor import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.internal.* +import kotlinx.serialization.Serializable /** * @see pre */ +@Serializable data class PreTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, val language: String? = null diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/RegularTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/RegularTextSource.kt index e880d6e2ba..18c69aafd9 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/RegularTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/RegularTextSource.kt @@ -4,10 +4,12 @@ import dev.inmo.tgbotapi.CommonAbstracts.DirectInvocationOfTextSourceConstructor import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.internal.* +import kotlinx.serialization.Serializable /** * @see regular */ +@Serializable data class RegularTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String ) : TextSource { 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 524f3ca1a1..a6c32d4302 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 @@ -3,10 +3,12 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.internal.* +import kotlinx.serialization.Serializable /** * @see strikethrough */ +@Serializable data class StrikethroughTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, override val subsources: List diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextLinkTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextLinkTextSource.kt index c6170764fd..3e3faa5430 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextLinkTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextLinkTextSource.kt @@ -4,10 +4,12 @@ import dev.inmo.tgbotapi.CommonAbstracts.DirectInvocationOfTextSourceConstructor import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.internal.* +import kotlinx.serialization.Serializable /** * @see link */ +@Serializable data class TextLinkTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, val url: String 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 4587b20597..2bb5c59261 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 @@ -4,10 +4,12 @@ import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.internal.* +import kotlinx.serialization.Serializable /** * @see mention */ +@Serializable data class TextMentionTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, val user: User, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextSourceSerializer.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextSourceSerializer.kt new file mode 100644 index 0000000000..8573a941ec --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextSourceSerializer.kt @@ -0,0 +1,92 @@ +package dev.inmo.tgbotapi.types.MessageEntity.textsources + +import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.CommonAbstracts.justTextSources +import dev.inmo.tgbotapi.types.MessageEntity.* +import dev.inmo.tgbotapi.types.MessageEntity.RawMessageEntities +import dev.inmo.tgbotapi.utils.RiskFeature +import kotlinx.serialization.* +import kotlinx.serialization.builtins.serializer +import kotlinx.serialization.descriptors.* +import kotlinx.serialization.encoding.* + +private val baseSerializers: Map> = mapOf( + "regular" to RegularTextSource.serializer(), + "text_link" to TextLinkTextSource.serializer(), + "code" to CodeTextSource.serializer(), + "url" to URLTextSource.serializer(), + "pre" to PreTextSource.serializer(), + "bot_command" to BotCommandTextSource.serializer(), + "strikethrough" to StrikethroughTextSource.serializer(), + "italic" to ItalicTextSource.serializer(), + "bold" to BoldTextSource.serializer(), + "email" to EMailTextSource.serializer(), + "underline" to UnderlineTextSource.serializer(), + "mention" to MentionTextSource.serializer(), + "phone_number" to PhoneNumberTextSource.serializer(), + "text_mention" to TextMentionTextSource.serializer(), + "hashtag" to HashTagTextSource.serializer(), + "cashtag" to CashTagTextSource.serializer(), +) + +@Serializer(TextSource::class) +object TextSourceSerializer : KSerializer { + private val serializers = baseSerializers.toMutableMap() + @InternalSerializationApi + override val descriptor: SerialDescriptor = buildSerialDescriptor( + "TextSourceSerializer", + SerialKind.CONTEXTUAL + ) { + element("type", String.serializer().descriptor) + element("value", ContextualSerializer(TextSource::class).descriptor) + } + + @InternalSerializationApi + override fun deserialize(decoder: Decoder): TextSource { + return decoder.decodeStructure(descriptor) { + var type: String? = null + lateinit var result: TextSource + while (true) { + when (val index = decodeElementIndex(descriptor)) { + 0 -> type = decodeStringElement(descriptor, 0) + 1 -> { + require(type != null) { "Type is null, but it is expected that was inited already" } + result = decodeSerializableElement( + descriptor, + 1, + serializers.getValue(type) + ) + } + CompositeDecoder.DECODE_DONE -> break + else -> error("Unexpected index: $index") + } + } + result + } + } + + @InternalSerializationApi + private fun CompositeEncoder.encode(value: T) { + encodeSerializableElement(descriptor, 1, value::class.serializer() as KSerializer, value) + } + + @InternalSerializationApi + override fun serialize(encoder: Encoder, value: TextSource) { + encoder.encodeStructure(descriptor) { + val valueSerializer = value::class.serializer() + val type = serializers.keys.first { serializers[it] == valueSerializer } + encodeStringElement(descriptor, 0, type) + encode(value) + } + } + + fun include(type: String, serializer: KSerializer) { + require(type !in baseSerializers.keys) + serializers[type] = serializer + } + + fun exclude(type: String) { + require(type !in baseSerializers.keys) + serializers.remove(type) + } +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/URLTextSource.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/URLTextSource.kt index cf84858378..cdfeb3d097 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/URLTextSource.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/URLTextSource.kt @@ -4,10 +4,12 @@ import dev.inmo.tgbotapi.CommonAbstracts.DirectInvocationOfTextSourceConstructor import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.internal.* +import kotlinx.serialization.Serializable /** * @see link */ +@Serializable data class URLTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String ) : TextSource { 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 febc609a9d..b8f3f10510 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 @@ -3,10 +3,12 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources import dev.inmo.tgbotapi.CommonAbstracts.* import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.internal.* +import kotlinx.serialization.Serializable /** * @see underline */ +@Serializable data class UnderlineTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor ( override val source: String, override val subsources: List diff --git a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/TextSourcesTests.kt b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/TextSourcesTests.kt new file mode 100644 index 0000000000..1dd7e893ef --- /dev/null +++ b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/types/TextSourcesTests.kt @@ -0,0 +1,40 @@ +package dev.inmo.tgbotapi.types + +import dev.inmo.tgbotapi.CommonAbstracts.TextSource +import dev.inmo.tgbotapi.CommonAbstracts.makeString +import dev.inmo.tgbotapi.TestsJsonFormat +import dev.inmo.tgbotapi.extensions.utils.formatting.* +import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourceSerializer +import kotlinx.serialization.PolymorphicSerializer +import kotlinx.serialization.builtins.ListSerializer +import kotlinx.serialization.encodeToString +import kotlin.test.Test +import kotlin.test.assertEquals + +class TextSourcesTests { + @Test + fun testThatTextSourcesSerializedCorrectly() { + val testList = buildEntities { + bold( + buildEntities { + italic("It") + regular(" ") + link("is example", "https://is.example") + } + ) + regular(" ") + underline("of") + regular(" ") + strikethrough("complex") + regular(" ") + pre("text", "kotlin") + } + val serialized = TestsJsonFormat.encodeToString(ListSerializer(TextSource.serializer()), testList) + val deserialized = TestsJsonFormat.decodeFromString( + ListSerializer(TextSource.serializer()), + serialized + ) + assertEquals(testList, deserialized) + assertEquals(testList.makeString(), deserialized.makeString()) + } +} \ No newline at end of file From e7bbce3fa758ba0d423ec0300b58cbcb44190580 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 12 Apr 2021 23:32:50 +0600 Subject: [PATCH 43/49] update uuid dependency --- CHANGELOG.md | 3 +++ gradle.properties | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c266f5b742..a5c714f5c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 0.33.4 +* `Common`: + * `Version`: + * `uuid`: `0.2.3` -> `0.2.4` * `Core`: * All `TextSource` implementators have become `Serializable` * New serializer `TextSourceSerializer` diff --git a/gradle.properties b/gradle.properties index ae661b29b3..b5beae4e22 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ kotlin_version=1.4.32 kotlin_coroutines_version=1.4.3 kotlin_serialisation_runtime_version=1.1.0 klock_version=2.0.7 -uuid_version=0.2.3 +uuid_version=0.2.4 ktor_version=1.5.3 micro_utils_version=0.4.33 From 3069a6084cffdd34bf5df9a0f025db1de2614c11 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 13 Apr 2021 01:50:41 +0600 Subject: [PATCH 44/49] fixes in parseCommandsWithParams --- gradle/wrapper/gradle-wrapper.properties | 2 +- .../utils/extensions/TextCaptionBotCommandsParser.kt | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f2e1eb1fd4..9fccb7a76d 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-bin.zip diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/TextCaptionBotCommandsParser.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/TextCaptionBotCommandsParser.kt index 86a63efb23..61eed8ef21 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/TextCaptionBotCommandsParser.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/TextCaptionBotCommandsParser.kt @@ -18,8 +18,11 @@ fun List.parseCommandsWithParams( var currentBotCommandSource: BotCommandTextSource? = null var currentArgs = "" fun includeCurrent() = currentBotCommandSource ?.let { - result[it.command] = currentArgs.split(argsSeparator).toTypedArray() - currentArgs = "" + currentArgs = currentArgs.trim() + if (currentArgs.isNotEmpty()) { + result[it.command] = currentArgs.split(argsSeparator).toTypedArray() + currentArgs = "" + } } for (textSource in this) { if (textSource is BotCommandTextSource) { From 39598dcb696295aac78a8cc4ed7220e9dc704d35 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 13 Apr 2021 01:54:16 +0600 Subject: [PATCH 45/49] fill CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5c714f5c5..2a8e16dbb0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ * `Core`: * All `TextSource` implementators have become `Serializable` * New serializer `TextSourceSerializer` +* `Extensions Utils` + * Fixes in `parseCommandsWithParams` ## 0.33.3 From a9d65944e668c56c71b9e6f3a6dda463b760c5e7 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 13 Apr 2021 15:53:35 +0600 Subject: [PATCH 46/49] update MicroUtils --- CHANGELOG.md | 1 + gradle.properties | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a8e16dbb0..43f3bae82d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * `Common`: * `Version`: * `uuid`: `0.2.3` -> `0.2.4` + * `MicroUtils`: `0.4.33` -> `0.4.34` * `Core`: * All `TextSource` implementators have become `Serializable` * New serializer `TextSourceSerializer` diff --git a/gradle.properties b/gradle.properties index b5beae4e22..8558d8fadf 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ klock_version=2.0.7 uuid_version=0.2.4 ktor_version=1.5.3 -micro_utils_version=0.4.33 +micro_utils_version=0.4.34 javax_activation_version=1.1.1 From c0451d4c8fe052e86134d398429b147833b951c7 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 15 Apr 2021 13:56:52 +0600 Subject: [PATCH 47/49] Update gradle-wrapper.properties --- gradle/wrapper/gradle-wrapper.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 9fccb7a76d..68ca99ac45 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip From 9982534001a61e74c302b4735c6fa9908de8fb04 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 15 Apr 2021 14:34:05 +0600 Subject: [PATCH 48/49] updates in TextSourceSerializer --- CHANGELOG.md | 2 +- gradle.properties | 2 +- tgbotapi.core/build.gradle | 1 + .../textsources/TextSourceSerializer.kt | 60 ++----------------- 4 files changed, 9 insertions(+), 56 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43f3bae82d..afb7c4bd79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ * `Common`: * `Version`: * `uuid`: `0.2.3` -> `0.2.4` - * `MicroUtils`: `0.4.33` -> `0.4.34` + * `MicroUtils`: `0.4.33` -> `0.4.35` * `Core`: * All `TextSource` implementators have become `Serializable` * New serializer `TextSourceSerializer` diff --git a/gradle.properties b/gradle.properties index 8558d8fadf..a74e4d5857 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ klock_version=2.0.7 uuid_version=0.2.4 ktor_version=1.5.3 -micro_utils_version=0.4.34 +micro_utils_version=0.4.35 javax_activation_version=1.1.1 diff --git a/tgbotapi.core/build.gradle b/tgbotapi.core/build.gradle index ff1a823d33..5c01929c53 100644 --- a/tgbotapi.core/build.gradle +++ b/tgbotapi.core/build.gradle @@ -52,6 +52,7 @@ kotlin { api "dev.inmo:micro_utils.coroutines:$micro_utils_version" api "dev.inmo:micro_utils.serialization.base64:$micro_utils_version" api "dev.inmo:micro_utils.serialization.encapsulator:$micro_utils_version" + api "dev.inmo:micro_utils.serialization.typed_serializer:$micro_utils_version" api "io.ktor:ktor-client-core:$ktor_version" } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextSourceSerializer.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextSourceSerializer.kt index 8573a941ec..f3474b1363 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextSourceSerializer.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/MessageEntity/textsources/TextSourceSerializer.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.types.MessageEntity.textsources +import dev.inmo.micro_utils.serialization.typed_serializer.TypedSerializer import dev.inmo.tgbotapi.CommonAbstracts.TextSource import dev.inmo.tgbotapi.CommonAbstracts.justTextSources import dev.inmo.tgbotapi.types.MessageEntity.* @@ -30,63 +31,14 @@ private val baseSerializers: Map> = mapOf( ) @Serializer(TextSource::class) -object TextSourceSerializer : KSerializer { - private val serializers = baseSerializers.toMutableMap() - @InternalSerializationApi - override val descriptor: SerialDescriptor = buildSerialDescriptor( - "TextSourceSerializer", - SerialKind.CONTEXTUAL - ) { - element("type", String.serializer().descriptor) - element("value", ContextualSerializer(TextSource::class).descriptor) - } - - @InternalSerializationApi - override fun deserialize(decoder: Decoder): TextSource { - return decoder.decodeStructure(descriptor) { - var type: String? = null - lateinit var result: TextSource - while (true) { - when (val index = decodeElementIndex(descriptor)) { - 0 -> type = decodeStringElement(descriptor, 0) - 1 -> { - require(type != null) { "Type is null, but it is expected that was inited already" } - result = decodeSerializableElement( - descriptor, - 1, - serializers.getValue(type) - ) - } - CompositeDecoder.DECODE_DONE -> break - else -> error("Unexpected index: $index") - } - } - result - } - } - - @InternalSerializationApi - private fun CompositeEncoder.encode(value: T) { - encodeSerializableElement(descriptor, 1, value::class.serializer() as KSerializer, value) - } - - @InternalSerializationApi - override fun serialize(encoder: Encoder, value: TextSource) { - encoder.encodeStructure(descriptor) { - val valueSerializer = value::class.serializer() - val type = serializers.keys.first { serializers[it] == valueSerializer } - encodeStringElement(descriptor, 0, type) - encode(value) - } - } - - fun include(type: String, serializer: KSerializer) { +object TextSourceSerializer : TypedSerializer(TextSource::class, baseSerializers) { + override fun include(type: String, serializer: KSerializer) { require(type !in baseSerializers.keys) - serializers[type] = serializer + super.include(type, serializer) } - fun exclude(type: String) { + override fun exclude(type: String) { require(type !in baseSerializers.keys) - serializers.remove(type) + super.exclude(type) } } From 5451adf4ac4fa3fe6aea25d5ab01fc81e1ae6229 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 16 Apr 2021 18:07:27 +0600 Subject: [PATCH 49/49] FromUserMessage extends Message --- CHANGELOG.md | 3 +++ .../kotlin/dev/inmo/tgbotapi/CommonAbstracts/FromUser.kt | 7 +++++++ .../tgbotapi/types/message/abstracts/FromUserMessage.kt | 6 ++---- 3 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/FromUser.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index afb7c4bd79..20e22e133d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ * `Core`: * All `TextSource` implementators have become `Serializable` * New serializer `TextSourceSerializer` + * Interface`FromUserMessage` now extends `Message` + * New interface `FromUser` + * Interface `FromUserMessage` now extends `FromUser` * `Extensions Utils` * Fixes in `parseCommandsWithParams` diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/FromUser.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/FromUser.kt new file mode 100644 index 0000000000..d45e65b52f --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/CommonAbstracts/FromUser.kt @@ -0,0 +1,7 @@ +package dev.inmo.tgbotapi.CommonAbstracts + +import dev.inmo.tgbotapi.types.User + +interface FromUser { + val user: User +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/FromUserMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/FromUserMessage.kt index 5852ffb5d8..50255f0cb4 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/FromUserMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/FromUserMessage.kt @@ -1,7 +1,5 @@ package dev.inmo.tgbotapi.types.message.abstracts -import dev.inmo.tgbotapi.types.User +import dev.inmo.tgbotapi.CommonAbstracts.FromUser -interface FromUserMessage { - val user: User -} \ No newline at end of file +interface FromUserMessage : FromUser, Message