From 4203a0fdfe3399c4d9d7067f19c5d66f71724893 Mon Sep 17 00:00:00 2001 From: Siarhei Date: Sat, 16 Oct 2021 23:01:10 +0300 Subject: [PATCH 1/2] PossiblyReplyMessage casts Add asPossiblyReplyMessage / requirePossiblyReplyMessage / whenPossiblyReplyMessage --- CHANGELOG.md | 4 ++++ .../dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0752fa9ff0..1fea5b810f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,10 @@ * Two new dsl: * `inlineKeyboard` for creating `InlineKeyboardMarkup` * `replyKeyboard` for creating `ReplyKeyboardMarkup` + * Cast helpers for `Message`: + * `asPossiblyReplyMessage`: tries to cast a `Message` to `PossiblyReplyMessage`, returns `null` if the message is not of that type + * `requirePossiblyReplyMessage`: casts a `Message` to `PossiblyReplyMessage`, fails if the message is not of that type + * `whenPossiblyReplyMessage`: tries to cast a `Message` to `PossiblyReplyMessage` and runs the given block of code with it, if the cast is successful * `Behaviour Builder`: * New expecters and waiters: * `waitShippingQueries`/`onShippingQuery` 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 ad0e69f1f3..c89200d275 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 @@ -1132,6 +1132,15 @@ inline fun Message.asPossiblyEditedMessage(): PossiblyEditedMessage? = this as? @PreviewFeature inline fun Message.requirePossiblyEditedMessage(): PossiblyEditedMessage = this as PossiblyEditedMessage +@PreviewFeature +inline fun Message.whenPossiblyReplyMessage(block: (PossiblyReplyMessage) -> T) = asPossiblyReplyMessage() ?.let(block) + +@PreviewFeature +inline fun Message.asPossiblyReplyMessage(): PossiblyReplyMessage? = this as? PossiblyReplyMessage + +@PreviewFeature +inline fun Message.requirePossiblyReplyMessage(): PossiblyReplyMessage = this as PossiblyReplyMessage + @PreviewFeature inline fun Message.whenPossiblyForwardedMessage(block: (PossiblyForwardedMessage) -> T) = asPossiblyForwardedMessage() ?.let(block) From 2447d3e51fd2851637032714c5dea83f714cb1fa Mon Sep 17 00:00:00 2001 From: madhead Date: Sun, 17 Oct 2021 14:42:24 +0200 Subject: [PATCH 2/2] Don't run the labeler if the actor is not repo owner --- .github/workflows/label.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/label.yml b/.github/workflows/label.yml index be1ee465e3..604a6cd13a 100644 --- a/.github/workflows/label.yml +++ b/.github/workflows/label.yml @@ -12,6 +12,7 @@ on: jobs: triage: runs-on: ubuntu-latest + if: ${{ github.actor == github.repository_owner }} steps: - uses: actions/labeler@v2 with: