From eeb46817c3d66beb07716b2ec2158c07827f3150 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 17 Feb 2021 22:00:46 +0600 Subject: [PATCH 1/5] start 0.32.7 --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 47cf1ffcc2..8ea300a604 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # TelegramBotAPI changelog +## 0.32.7 + ## 0.32.6 * `Common`: diff --git a/gradle.properties b/gradle.properties index 3fdf6502e8..f7cb21ef35 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,6 +17,6 @@ micro_utils_version=0.4.25 javax_activation_version=1.1.1 library_group=dev.inmo -library_version=0.32.6 +library_version=0.32.7 github_release_plugin_version=2.2.12 From fe2dffd8b5a6e301759ac3ffaab3831c21ebdd6a Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 17 Feb 2021 22:11:26 +0600 Subject: [PATCH 2/5] BehaviourContext updates --- CHANGELOG.md | 6 ++++++ .../behaviour_builder/BehaviourContext.kt | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ea300a604..333c7236b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## 0.32.7 +* `Behaviour Builder`: + * Now `doInSubContextWithUpdatesFilter` and `doInSubContext` will automatically subscribe on updates of parent + `BehaviourContext` + * `doInSubContextWithFlowsUpdatesFilterSetup`, `doInSubContextWithUpdatesFilter` and `doInSubContext` got new + parameter `stopOnCompletion` to be able to disable stopping of behaviour context on finishing + ## 0.32.6 * `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 d881a5f1ba..4ff49827ce 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 @@ -4,6 +4,7 @@ import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.types.update.abstracts.Update import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter +import dev.inmo.tgbotapi.utils.RiskFeature import kotlinx.coroutines.* import kotlinx.coroutines.flow.filter @@ -25,12 +26,15 @@ data class BehaviourContext( /** * Creates new one [BehaviourContext], adding subsequent [FlowsUpdatesFilter] in case [newFlowsUpdatesFilterSetUp] is provided and - * [CoroutineScope] as new [BehaviourContext.scope] + * [CoroutineScope] as new [BehaviourContext.scope]. You must do all subscription/running of longPolling manually. * * @param newFlowsUpdatesFilterSetUp As a parameter receives [FlowsUpdatesFilter] from old [this] [BehaviourContext.flowsUpdatesFilter] */ +@RiskFeature("It is recommended to use doInSubContextWithUpdatesFilter instead. " + + "This method is low level and should not be used in case you are not pretty sure you need it.") suspend fun BehaviourContext.doInSubContextWithFlowsUpdatesFilterSetup( newFlowsUpdatesFilterSetUp: BehaviourContextAndTypeReceiver?, + stopOnCompletion: Boolean = true, behaviourContextReceiver: BehaviourContextReceiver ) = copy( flowsUpdatesFilter = FlowsUpdatesFilter(), @@ -39,7 +43,7 @@ suspend fun BehaviourContext.doInSubContextWithFlowsUpdatesFilterSetup( newFlowsUpdatesFilterSetUp ?.let { it.apply { invoke(this@run, this@doInSubContextWithFlowsUpdatesFilterSetup.flowsUpdatesFilter) } } - behaviourContextReceiver().also { stop() } + behaviourContextReceiver().also { if (stopOnCompletion) stop() } } /** @@ -48,19 +52,24 @@ suspend fun BehaviourContext.doInSubContextWithFlowsUpdatesFilterSetup( */ suspend fun BehaviourContext.doInSubContextWithUpdatesFilter( updatesFilter: BehaviourContextAndTypeReceiver?, + stopOnCompletion: Boolean = true, behaviourContextReceiver: BehaviourContextReceiver ) = doInSubContextWithFlowsUpdatesFilterSetup( newFlowsUpdatesFilterSetUp = updatesFilter ?.let { { oldOne -> oldOne.allUpdatesFlow.filter { updatesFilter(it) }.subscribeSafelyWithoutExceptions(scope, asUpdateReceiver) } + } ?: { oldOne -> + oldOne.allUpdatesFlow.subscribeSafelyWithoutExceptions(scope, asUpdateReceiver) }, + stopOnCompletion, behaviourContextReceiver ) suspend fun BehaviourContext.doInSubContext( + stopOnCompletion: Boolean = true, behaviourContextReceiver: BehaviourContextReceiver -) = doInSubContextWithFlowsUpdatesFilterSetup(newFlowsUpdatesFilterSetUp = null, behaviourContextReceiver) +) = doInSubContextWithUpdatesFilter(updatesFilter = null, stopOnCompletion, behaviourContextReceiver) /** * This method will cancel ALL subsequent contexts, expectations and waiters From 23ceaf8e9744acd7578aae33d460d89cbc12d6e4 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 17 Feb 2021 22:12:58 +0600 Subject: [PATCH 3/5] LeftRestrictionsChatPermissions --- CHANGELOG.md | 2 ++ .../dev/inmo/tgbotapi/types/chat/ChatPermissions.kt | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 333c7236b5..ab5ff7585e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 0.32.7 +* `Core`: + * New variable `LeftRestrictionsChatPermissions` * `Behaviour Builder`: * Now `doInSubContextWithUpdatesFilter` and `doInSubContext` will automatically subscribe on updates of parent `BehaviourContext` diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ChatPermissions.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ChatPermissions.kt index 51b00218d1..bb9a9f4e2d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ChatPermissions.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ChatPermissions.kt @@ -23,3 +23,14 @@ data class ChatPermissions( @SerialName(canPinMessagesField) val canPinMessages: Boolean = false ) + +val LeftRestrictionsChatPermissions = ChatPermissions( + canSendMessages = true, + canSendMediaMessages = true, + canSendPolls = true, + canSendOtherMessages = true, + canAddWebPagePreviews = true, + canChangeInfo = true, + canInviteUsers = true, + canPinMessages = true, +) From 0d9f18f346a4f3a4efebcc6ddbb59c5c26786b58 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 17 Feb 2021 22:29:29 +0600 Subject: [PATCH 4/5] DiceAnimationType class casts --- CHANGELOG.md | 2 ++ .../tgbotapi/extensions/utils/ClassCasts.kt | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab5ff7585e..fe015b81ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ * `Core`: * New variable `LeftRestrictionsChatPermissions` +* `Extensions Utils`: + * `DiceAnimationType` class casts * `Behaviour Builder`: * Now `doInSubContextWithUpdatesFilter` and `doInSubContext` will automatically subscribe on updates of parent `BehaviourContext` 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 b4b2716992..5e27c2c544 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 @@ -28,6 +28,7 @@ import dev.inmo.tgbotapi.types.buttons.* import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.* import dev.inmo.tgbotapi.types.chat.abstracts.* import dev.inmo.tgbotapi.types.chat.abstracts.extended.* +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.* @@ -1216,3 +1217,31 @@ inline fun TextSource.requireURLTextSource(): URLTextSource = this as URLTextSou inline fun TextSource.asUnderlineTextSource(): UnderlineTextSource? = this as? UnderlineTextSource @PreviewFeature inline fun TextSource.requireUnderlineTextSource(): UnderlineTextSource = this as UnderlineTextSource +@PreviewFeature +inline fun DiceAnimationType.asBasketballDiceAnimationType(): BasketballDiceAnimationType? = this as? BasketballDiceAnimationType +@PreviewFeature +inline fun DiceAnimationType.requireBasketballDiceAnimationType(): BasketballDiceAnimationType = this as BasketballDiceAnimationType +@PreviewFeature +inline fun DiceAnimationType.asBowlingDiceAnimationType(): BowlingDiceAnimationType? = this as? BowlingDiceAnimationType +@PreviewFeature +inline fun DiceAnimationType.requireBowlingDiceAnimationType(): BowlingDiceAnimationType = this as BowlingDiceAnimationType +@PreviewFeature +inline fun DiceAnimationType.asCubeDiceAnimationType(): CubeDiceAnimationType? = this as? CubeDiceAnimationType +@PreviewFeature +inline fun DiceAnimationType.requireCubeDiceAnimationType(): CubeDiceAnimationType = this as CubeDiceAnimationType +@PreviewFeature +inline fun DiceAnimationType.asCustomDiceAnimationType(): CustomDiceAnimationType? = this as? CustomDiceAnimationType +@PreviewFeature +inline fun DiceAnimationType.requireCustomDiceAnimationType(): CustomDiceAnimationType = this as CustomDiceAnimationType +@PreviewFeature +inline fun DiceAnimationType.asDartsDiceAnimationType(): DartsDiceAnimationType? = this as? DartsDiceAnimationType +@PreviewFeature +inline fun DiceAnimationType.requireDartsDiceAnimationType(): DartsDiceAnimationType = this as DartsDiceAnimationType +@PreviewFeature +inline fun DiceAnimationType.asFootballDiceAnimationType(): FootballDiceAnimationType? = this as? FootballDiceAnimationType +@PreviewFeature +inline fun DiceAnimationType.requireFootballDiceAnimationType(): FootballDiceAnimationType = this as FootballDiceAnimationType +@PreviewFeature +inline fun DiceAnimationType.asSlotMachineDiceAnimationType(): SlotMachineDiceAnimationType? = this as? SlotMachineDiceAnimationType +@PreviewFeature +inline fun DiceAnimationType.requireSlotMachineDiceAnimationType(): SlotMachineDiceAnimationType = this as SlotMachineDiceAnimationType From 563d78460381afe3e723f877a0e1241d1e9c0a99 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 18 Feb 2021 00:28:36 +0600 Subject: [PATCH 5/5] RestrictionsChatPermissions --- CHANGELOG.md | 2 +- .../dev/inmo/tgbotapi/types/chat/ChatPermissions.kt | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe015b81ff..8c7f009416 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## 0.32.7 * `Core`: - * New variable `LeftRestrictionsChatPermissions` + * New variable `LeftRestrictionsChatPermissions` and `RestrictionsChatPermissions` * `Extensions Utils`: * `DiceAnimationType` class casts * `Behaviour Builder`: diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ChatPermissions.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ChatPermissions.kt index bb9a9f4e2d..67091d9bd4 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ChatPermissions.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/chat/ChatPermissions.kt @@ -34,3 +34,14 @@ val LeftRestrictionsChatPermissions = ChatPermissions( canInviteUsers = true, canPinMessages = true, ) + +val RestrictionsChatPermissions = ChatPermissions( + canSendMessages = false, + canSendMediaMessages = false, + canSendPolls = false, + canSendOtherMessages = false, + canAddWebPagePreviews = false, + canChangeInfo = false, + canInviteUsers = false, + canPinMessages = false, +)