diff --git a/CHANGELOG.md b/CHANGELOG.md index 47cf1ffcc2..8c7f009416 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # TelegramBotAPI changelog +## 0.32.7 + +* `Core`: + * New variable `LeftRestrictionsChatPermissions` and `RestrictionsChatPermissions` +* `Extensions Utils`: + * `DiceAnimationType` class casts +* `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/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 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..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 @@ -23,3 +23,25 @@ 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, +) + +val RestrictionsChatPermissions = ChatPermissions( + canSendMessages = false, + canSendMediaMessages = false, + canSendPolls = false, + canSendOtherMessages = false, + canAddWebPagePreviews = false, + canChangeInfo = false, + canInviteUsers = false, + canPinMessages = false, +) 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 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