mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-11-16 12:00:18 +00:00
Compare commits
182 Commits
0.32.2
...
gradle-wra
| Author | SHA1 | Date | |
|---|---|---|---|
| eaee334ff6 | |||
| 5c694e8625 | |||
| 0306c40fb2 | |||
| fd915553e3 | |||
| ec1c0ba8bb | |||
| 12a64ec1d1 | |||
| 59d7a7c781 | |||
| cabfd7c76b | |||
| f12f52899c | |||
|
|
ed067db20f | ||
| b055268979 | |||
| 2584839d66 | |||
| 63946e860d | |||
| 90df436c63 | |||
| d3c8b49b10 | |||
| c1372b55bc | |||
| b6c7ece995 | |||
| 44e7c80f43 | |||
| 1e41e95333 | |||
| 03d4d715c0 | |||
| ab060d02ea | |||
| f447be02dc | |||
| eb923a6338 | |||
| 0914710cc7 | |||
| 1f7450844f | |||
| 167c214e35 | |||
| 42a8d649cd | |||
| eb3f180cc6 | |||
| 70f96ac8fa | |||
| d69b2e09d5 | |||
| 946b0222df | |||
| 7da315dbaf | |||
| 87071ca52c | |||
| b2770e3ecc | |||
| df63ccfe07 | |||
| 694bec22a2 | |||
| 6a3588bb8d | |||
| a26568aa29 | |||
| cd30660256 | |||
| 1846d20b0d | |||
| f13207064e | |||
| 61be689aca | |||
| 03f8d65bb6 | |||
| 2dc8beba8a | |||
| 5451adf4ac | |||
| 9982534001 | |||
| c0451d4c8f | |||
| a9d65944e6 | |||
| 39598dcb69 | |||
| 3069a6084c | |||
| e7bbce3fa7 | |||
| 0b361163f2 | |||
| 6aba2ff641 | |||
| 6b761ab37d | |||
| b9c8a89af9 | |||
| a42c5c63c4 | |||
| fc1a029acb | |||
| f90ae2f918 | |||
| 019b260888 | |||
| 0831f2fa75 | |||
| 32ae9d2b16 | |||
| b975a1b036 | |||
| f4b1e4a150 | |||
| 97031512d4 | |||
| 353df43109 | |||
| 4e55460834 | |||
| e2e235bd6c | |||
| 8ced95bc2f | |||
| 685e4af8f5 | |||
| 0b2f7a3899 | |||
| 112c86c9da | |||
| 1ddd138ff7 | |||
| 1a5d1cde78 | |||
| 5b620014cb | |||
| 80093cb5a9 | |||
| 9f8e8ee21b | |||
| 3de3bb6133 | |||
| 308fb9274b | |||
| d14ca7bbdc | |||
| dbdd9b5ad2 | |||
| 6dd27cb0bf | |||
| 210a52485b | |||
| 5c11b60ea6 | |||
| 60c3a0d7af | |||
| 8d777e1c0e | |||
| 4e019eb8bb | |||
| bd80562c2a | |||
| 9fc07f2ff3 | |||
| a4bae5133a | |||
| 7bb272f2fa | |||
| 72cf38d3bb | |||
| 0adee13cba | |||
| f9e3e57f24 | |||
| d7d4adc8e4 | |||
| e9b074a36c | |||
| 65cba0f014 | |||
| 36202133a1 | |||
| 66f7801b32 | |||
| e7265829d1 | |||
| 9ad5bfbc57 | |||
| aba62ba930 | |||
| 40d702a311 | |||
| 233d893b5a | |||
| 0faca5838c | |||
| 838f62aa84 | |||
| bc21a680bc | |||
| 8bb60bea34 | |||
| 8daadcff95 | |||
| 2a1e624641 | |||
| 696822db02 | |||
| ded501d963 | |||
| 86e506c33d | |||
| 9902b00e85 | |||
| 53524abcbb | |||
| 7639b15dc6 | |||
| 61b720c61f | |||
| baf4c74b69 | |||
| 367cfff2cb | |||
| 75e8d0f62d | |||
| c521a5f9a4 | |||
| c5513365c2 | |||
| d184ce7a0f | |||
| a3bff3f24d | |||
| a835b1dcbb | |||
| ffed2b80a5 | |||
| ff24b9f35b | |||
| 1287852334 | |||
| fc2f177e38 | |||
| 1efd4dce6e | |||
| 69b5a16b17 | |||
| 77b531ad06 | |||
| a98d5d9abd | |||
| 104653ac41 | |||
| 63337b8285 | |||
| 5cc0bbb31b | |||
| 563d784603 | |||
| 0d9f18f346 | |||
| 23ceaf8e97 | |||
| fe2dffd8b5 | |||
| eeb46817c3 | |||
| 5ab00da31d | |||
| 841ae73f7c | |||
| 41b4d29917 | |||
| f8b3c44146 | |||
| f0eb670c3f | |||
| fe5d94f31e | |||
| 7901d0a223 | |||
| 799f9123ba | |||
| f77f010e66 | |||
| 67ddf8d809 | |||
| 81afa46253 | |||
| a5bba76f07 | |||
| d882cf9c97 | |||
| 2e27b8b64d | |||
| 4df800eaa9 | |||
| 8d27349868 | |||
| 2a89c41a58 | |||
| 098b5cc393 | |||
| 10f4817283 | |||
| 4449893608 | |||
| 3a53f41f66 | |||
| 7cd366d893 | |||
| 1309a4111c | |||
| 0ca815760b | |||
| eca0680f2f | |||
| d472d371ed | |||
| 4748b6813a | |||
| a2ea15d4b0 | |||
| 27dc302f5d | |||
| baf8ed3a77 | |||
| 18913af3c3 | |||
| 51871ea94c | |||
| 6a625d7b9f | |||
| 0b93b472a3 | |||
| ff16f9a315 | |||
| 86bfe043a5 | |||
| fa18e7299d | |||
| c986025075 | |||
| e8a7ea9ce4 | |||
| 30f35e5488 | |||
| b626974ea7 | |||
| 128b782a27 |
11
.github/dependabot.yml
vendored
Normal file
11
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
# To get started with Dependabot version updates, you'll need to specify which
|
||||
# package ecosystems to update and where the package manifests are located.
|
||||
# Please see the documentation for all configuration options:
|
||||
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "gradle" # See documentation for possible values
|
||||
directory: "/tgbotapi.core" # Location of package manifests
|
||||
schedule:
|
||||
interval: "daily"
|
||||
21
.github/workflows/kdocs.yml
vendored
Normal file
21
.github/workflows/kdocs.yml
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
name: Publish KDocs
|
||||
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
|
||||
23
.github/workflows/packages_publishing.yml
vendored
Normal file
23
.github/workflows/packages_publishing.yml
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
name: Publish package to GitHub Packages
|
||||
on: [push]
|
||||
jobs:
|
||||
publishing:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 1.8
|
||||
- name: Rewrite version
|
||||
run: |
|
||||
branch="`echo "${{ github.ref }}" | grep -o "[^/]*$"`"
|
||||
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
|
||||
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 }}
|
||||
16
.github/workflows/regular-build.yml
vendored
16
.github/workflows/regular-build.yml
vendored
@@ -1,16 +0,0 @@
|
||||
name: Build
|
||||
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up JDK 1.8
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 1.8
|
||||
- name: Build with Gradle
|
||||
run: ./gradlew build
|
||||
196
CHANGELOG.md
196
CHANGELOG.md
@@ -1,5 +1,201 @@
|
||||
# TelegramBotAPI changelog
|
||||
|
||||
## 0.34.1
|
||||
|
||||
* `Common`:
|
||||
* `Version`:
|
||||
* `ktor`: `1.5.3` -> `1.5.4`
|
||||
* `MicroUtils`: `0.4.35` -> `0.4.36`
|
||||
* `Core`
|
||||
* Fix in creating of text sources list
|
||||
|
||||
## 0.34.0
|
||||
|
||||
_**It is recommended to use [0.34.1](https://github.com/InsanusMokrassar/TelegramBotAPI/releases/tag/0.34.1) version due to the bug in 0.34.0 related to rewriting of `TextSource`s creating mechanism.**_
|
||||
|
||||
**UPDATE UP TO Telegram Bot API 5.2**
|
||||
|
||||
_**ALL OLD DEPRECATIONS WERE REMOVED**_
|
||||
|
||||
* `Core`:
|
||||
* Type `ChatType` has been added
|
||||
* New `ExtendedChat` for unknown messages `UnknownExtendedChat` has been added
|
||||
* `SendInvoice#startParameter` becomes optional and replaced in `SendInvoice` constructor
|
||||
* New interface `CommonSendInvoiceData` has been added
|
||||
* Fields `CommonSendInvoiceData#maxTipAmount` and `CommonSendInvoiceData#suggestedTipAmounts` have been added
|
||||
* New type `InputInvoiceMessageContent` has been added
|
||||
* New interface `TextedWithTextSources` on top of `Texted` interface
|
||||
* Interface `TextedInput` now extends `TextedWithTextSources` with overriding of `textSources` field as not
|
||||
nullable
|
||||
* `textSources` become main field in `TextedInput`
|
||||
* **MIGRATION** Remove all `import dev.inmo.tgbotapi.CommonAbstracts.textSources` in your project
|
||||
* `textEntities` become are calculable property in `TextedInput`
|
||||
* Interface `Captioned` and `CaptionedInput` now is deprecated
|
||||
* Most of captions usages were replaced with texts
|
||||
* Interface `Explained` and `ExplainedInput` now is deprecated
|
||||
* Most of captions usages were replaced with texts
|
||||
* Interface `VoiceChatEvent` now is `CommonEvent`
|
||||
* Mechanism of `RawMessageEntity` converting were fully rewritten
|
||||
|
||||
## 0.33.4
|
||||
|
||||
* `Common`:
|
||||
* `Version`:
|
||||
* `uuid`: `0.2.3` -> `0.2.4`
|
||||
* `MicroUtils`: `0.4.33` -> `0.4.35`
|
||||
* `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`
|
||||
|
||||
## 0.33.3
|
||||
|
||||
* `Common`:
|
||||
* `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`
|
||||
|
||||
## 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`:
|
||||
* `CallbackQueryMapper`
|
||||
* `ChatMemberUpdatedMapper`
|
||||
* `InlineQueryMapper`
|
||||
* Commands got an additional parameter - `additionalFilter`. It will be called when all command filters were passed
|
||||
|
||||
## 0.33.1
|
||||
|
||||
* `Common`:
|
||||
* `Version`:
|
||||
* `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
|
||||
|
||||
**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
|
||||
|
||||
* `Common`:
|
||||
* `Version`:
|
||||
* `Kotlin`: `1.4.30` -> `1.4.31`
|
||||
* `Ktor`: `1.5.1` -> `1.5.2`
|
||||
* `MicroUtils`: `0.4.26` -> `0.4.28`
|
||||
* `Coroutines`: `1.4.2` -> `1.4.3`
|
||||
|
||||
## 0.32.8
|
||||
|
||||
* `Common`:
|
||||
* `Version`:
|
||||
* `Serialization`: `1.1.0-RC` -> `1.1.0`
|
||||
* `MicroUtils`: `0.4.25` -> `0.4.26`
|
||||
|
||||
## 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`:
|
||||
* `Version`:
|
||||
* `MicroUtils`: `0.4.24` -> `0.4.25`
|
||||
* `Extensions API`:
|
||||
* New extension `TelegramBot#replyWithDice`
|
||||
* `Extensions Utils`:
|
||||
* `SlotMachineReelImages` has been renamed to `SlotMachineReelImage`
|
||||
* `SlotMachineReelImage` got two built-in parameters: `text` and `number`
|
||||
* New extension `String#asSlotMachineReelImage`
|
||||
|
||||
## 0.32.5
|
||||
|
||||
* `Core`:
|
||||
* Add `mention` variants for user ids and receiver variants ([#294](https://github.com/InsanusMokrassar/TelegramBotAPI/issues/294))
|
||||
* Now `AbstractRequestCallFactory` will set up one-second delay for zero timeouts in `GetUpdate` requests
|
||||
* Several extensions for `TelegramBotAPI` like `retrieveAccumulatedUpdates` have been added as a solution for
|
||||
[#293](https://github.com/InsanusMokrassar/TelegramBotAPI/issues/293)
|
||||
* Links for `tg://user?id=<user_id>` have been updated ([#292](https://github.com/InsanusMokrassar/TelegramBotAPI/issues/292))
|
||||
* All usages of captions or texts in resends and same things have been replaced with `textSources`
|
||||
* Global `defaultParseMode` has been added ([#291](https://github.com/InsanusMokrassar/TelegramBotAPI/issues/291))
|
||||
|
||||
## 0.32.4
|
||||
|
||||
* `Common`:
|
||||
* `Version`:
|
||||
* `Kotlin`: `1.4.21` -> `1.4.30`
|
||||
* `Klock`: `2.0.4` -> `2.0.6`
|
||||
* `MicroUtils`: `0.4.23` -> `0.4.24`
|
||||
* `Core`:
|
||||
* Renames:
|
||||
* `ChannelMessage` -> `ChannelContentMessage`
|
||||
* `PublicMessage` -> `PublicContentMessage`
|
||||
* `GroupMessage` -> `GroupContentMessage`
|
||||
* `FromChannelGroupMessage` -> `FromChannelGroupContentMessage`
|
||||
* `AnonymousGroupMessage` -> `AnonymousGroupContentMessage`
|
||||
* `CommonGroupMessage` -> `CommonGroupContentMessage`
|
||||
* `PrivateMessage` -> `PrivateContentMessage`
|
||||
* `Extensions Utils`:
|
||||
* Renames of extensions in `ClassCasts` according to changes in `Core`
|
||||
|
||||
## 0.32.3
|
||||
|
||||
* `Behaviour Builder`:
|
||||
* Add expectators and waiters for inline queries
|
||||
|
||||
## 0.32.2
|
||||
|
||||
* `Core`:
|
||||
|
||||
223
README.md
223
README.md
@@ -1,153 +1,118 @@
|
||||
[Participate in our common survey ☺](https://forms.gle/q6Xf8K3fD1pPsYUw9)
|
||||
|
||||
# TelegramBotAPI
|
||||
|
||||
<details>
|
||||
<summary><b>I do not wanna read a lot, just give me my bot</b></summary>
|
||||
Hello! This is a set of libraries for working with Telegram Bot API.
|
||||
|
||||
You can simply use <a href="https://github.com/InsanusMokrassar/TelegramBotAPI-bot_template">this template</a> (and button
|
||||
<a href="https://github.com/InsanusMokrassar/TelegramBotAPI-bot_template/generate">Use template</a>) to get your copy of bot and start to code.
|
||||
<p></p>
|
||||
<b>P.S. Do not forget to look into our <a href="https://bookstack.inmo.dev/books/telegrambotapi/">minidocs</a> and
|
||||
<a href="https://tgbotapi.inmo.dev/docs/index.html">kdocs</a></b>
|
||||
|
||||
</details>
|
||||
|
||||
| Common info | [](https://github.com/KotlinBy/awesome-kotlin) [](https://travis-ci.com/InsanusMokrassar/TelegramBotAPI) [Small survey](https://forms.gle/2Hex2ynbHWHhi1KY7)|
|
||||
| Common info | [](https://github.com/KotlinBy/awesome-kotlin) [](https://github.com/InsanusMokrassar/TelegramBotAPI/actions) [Small survey](https://forms.gle/2Hex2ynbHWHhi1KY7)|
|
||||
| -------------------------------------:|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||
| Useful links | [](https://t.me/InMoTelegramBotAPI) [](https://github.com/InsanusMokrassar/TelegramBotAPI-bot_template/generate) [](https://tgbotapi.inmo.dev/docs/index.html) [Examples](https://github.com/InsanusMokrassar/TelegramBotAPI-examples/), [Mini tutorial](https://bookstack.inmo.dev/books/telegrambotapi/chapter/introduction-tutorial) |
|
||||
| TelegramBotAPI Core status | [](https://bintray.com/insanusmokrassar/TelegramBotAPI/tgbotapi.core/_latestVersion) [](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.core) |
|
||||
| TelegramBotAPI API Extensions status | [](https://bintray.com/insanusmokrassar/TelegramBotAPI/tgbotapi.extensions.api/_latestVersion) [](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.extensions.api) |
|
||||
| TelegramBotAPI Util Extensions status | [](https://bintray.com/insanusmokrassar/TelegramBotAPI/tgbotapi.extensions.utils/_latestVersion) [](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.extensions.utils) |
|
||||
| TelegramBotAPI Behaviour Builder Extensions status | [](https://bintray.com/insanusmokrassar/TelegramBotAPI/tgbotapi.extensions.behaviour_builder/_latestVersion) [](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.extensions.behaviour_builder) |
|
||||
| TelegramBotAPI All status | [](https://bintray.com/insanusmokrassar/TelegramBotAPI/tgbotapi/_latestVersion) [](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi) |
|
||||
| TelegramBotAPI Core status | [](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.core) |
|
||||
| TelegramBotAPI API Extensions status | [](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.extensions.api) |
|
||||
| TelegramBotAPI Util Extensions status | [](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.extensions.utils) |
|
||||
| TelegramBotAPI Behaviour Builder Extensions status | [](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.extensions.behaviour_builder) |
|
||||
| TelegramBotAPI All status | [](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi) |
|
||||
|
||||
**At the time of publication of version `0.28.0` there are errors in serialization plugins like
|
||||
[kotlinx.serialization#1004](https://github.com/Kotlin/kotlinx.serialization/issues/1004). It is possible, that both JVM
|
||||
and JS version may work improperly in some cases with `kotlinx.serialization` version `1.0.0-RC`**
|
||||
## Examples
|
||||
|
||||
## What is it?
|
||||
There are several things you need to do to launch examples below:
|
||||
|
||||
It is a complex of libraries for working with `TelegramBotAPI` in type-safe and strict way as much as it possible. In
|
||||
the list of this complex currently next projects:
|
||||
* Add `mavenCentral()` to your project repositories
|
||||
* [Maven variant](https://github.com/InsanusMokrassar/TelegramBotAPI/wiki/Including-in-your-project#pomxml)
|
||||
* Add dependency `implementation "dev.inmo:tgbotapi:$tgbotapi_version"`
|
||||
* Replace `tgbotapi_version` with exact version (see last one in the table above) or put variable with this name in project
|
||||
* Alternative variant for maven [here](https://github.com/InsanusMokrassar/TelegramBotAPI/wiki/Including-in-your-project#telegrambotapi)
|
||||
|
||||
* [TelegramBotAPI Core](tgbotapi.core/README.md) - core of library. In fact it is independent library and can be used alone
|
||||
without any additional library
|
||||
* [TelegramBotAPI API Extensions](tgbotapi.extensions.api/README.md) - contains extensions (mostly for
|
||||
`RequestsExecutor`), which allows to use the core library in more pleasant way
|
||||
* [TelegramBotAPI Util Extensions](tgbotapi.extensions.utils/README.md) - contains extensions for more comfortable
|
||||
work with commands, updates and other different things
|
||||
* [TelegramBotAPI Behaviour Builder Extensions](tgbotapi.extensions.behaviour_builder/README.md) - builder for
|
||||
step-by-step handling of bot behaviour in more comfortable manner
|
||||
* [TelegramBotAPI](tgbotapi/README.md) - concentration of all previously mentioned libraries
|
||||
More including instructions [available here](https://github.com/InsanusMokrassar/TelegramBotAPI/wiki/Including-in-your-project).
|
||||
Other configuration examples:
|
||||
|
||||
Most part of some specific solves or unuseful
|
||||
moments are describing by official [Telegram Bot API](https://core.telegram.org/bots/api).
|
||||
* [For multiplatform](https://github.com/InsanusMokrassar/TelegramBotAPI-examples/tree/master/ResenderBot)
|
||||
* [For JVM](https://github.com/InsanusMokrassar/TelegramBotAPI-examples/blob/master/GetMeBot/build.gradle)
|
||||
|
||||
## JavaScript notes
|
||||
### Most common example
|
||||
|
||||
### Versions before `0.28.0`
|
||||
```kotlin
|
||||
suspend fun main() {
|
||||
val bot = telegramBot(TOKEN)
|
||||
|
||||
In case if you are want to use this library inside of browser, you will need additional settings (thanks for help to [Alexander Nozik](https://research.jetbrains.org/researchers/altavir)):
|
||||
|
||||
<details>
|
||||
<summary>Gradle build script help (for versions before 0.28.0)</summary>
|
||||
|
||||
```groovy
|
||||
dependencies {
|
||||
/* ... */
|
||||
|
||||
implementation "com.github.insanusmokrassar:TelegramBotAPI:$tgbot_api_version"
|
||||
implementation "com.github.insanusmokrassar:TelegramBotAPI-extensions-api:$tgbot_api_version" // optional
|
||||
implementation "com.github.insanusmokrassar:TelegramBotAPI-extensions-utils:$tgbot_api_version" // optional
|
||||
|
||||
/* Block of dependencies for correct building in browser */
|
||||
implementation(npm("fs"))
|
||||
implementation(npm("bufferutil"))
|
||||
implementation(npm("utf-8-validate"))
|
||||
implementation(npm("abort-controller"))
|
||||
implementation(npm("text-encoding"))
|
||||
}
|
||||
|
||||
/* ... */
|
||||
|
||||
kotlin {
|
||||
target {
|
||||
browser {
|
||||
/* Block for fix of exception in absence of some functionality, https://github.com/ktorio/ktor/issues/1339 */
|
||||
dceTask {
|
||||
dceOptions {
|
||||
keep("ktor-ktor-io.\$\$importsForInline\$\$.ktor-ktor-io.io.ktor.utils.io")
|
||||
}
|
||||
}
|
||||
}
|
||||
bot.buildBehaviour {
|
||||
println(getMe())
|
||||
|
||||
onCommand("start") {
|
||||
reply(it, "Hi:)")
|
||||
}
|
||||
}.join()
|
||||
}
|
||||
```
|
||||
|
||||
</details>
|
||||
In this example you will see information about this bot at the moment of starting and answer with `Hi:)` every time it
|
||||
gets message `/start`
|
||||
|
||||
## Ok, where should I start?
|
||||
### Handling only last messages
|
||||
|
||||

|
||||
```kotlin
|
||||
suspend fun main() {
|
||||
val bot = telegramBot(TOKEN)
|
||||
|
||||
In most cases, the most simple way will be to implement [TelegramBotAPI](tgbotapi/README.md) - it contains
|
||||
all necessary tools for comfort usage of this library. If you want to exclude some libraries, you can implement just
|
||||
[TelegramBotAPI BehaviourBuilder Extensions](tgbotapi.extensions.behaviour_builder/README.md),
|
||||
[TelegramBotAPI API Extensions](tgbotapi.extensions.api/README.md),
|
||||
[TelegramBotAPI Util Extensions](tgbotapi.extensions.utils/README.md) or even
|
||||
[TelegramBotAPI Core](tgbotapi.core/README.md).
|
||||
val flowsUpdatesFilter = FlowsUpdatesFilter()
|
||||
bot.buildBehaviour(flowUpdatesFilter = flowsUpdatesFilter) {
|
||||
println(getMe())
|
||||
|
||||
onCommand("start") {
|
||||
reply(it, "Hi:)")
|
||||
}
|
||||
|
||||
If you want to dive deeper in the core of library or develop something for it - welcome to learn more from
|
||||
[TelegramBotAPI Core](tgbotapi.core/README.md) and our [Telegram Chat](https://teleg.one/InMoTelegramBotAPIChat).
|
||||
|
||||
Anyway, all libraries are very typical inside of them. Examples:
|
||||
|
||||
* In `TelegramBotAPI` common request look like `requestsExecutor.execute(SomeRequest())`
|
||||
* `tgbotapi.extensions.api` typical syntax look like `requestsExecutor.someRequest()` (in most cases it would be
|
||||
better to use `bot` name instead of `requestsExecutor`)
|
||||
* `tgbotapi.extensions.utils` will look like `filter.filterBaseMessageUpdates(chatId).filterExactCommands(Regex("^.*$"))...`
|
||||
|
||||
## Build instruction
|
||||
|
||||
If you want to build this project or to contribute, there are several recommendations:
|
||||
|
||||
### Build
|
||||
|
||||
In case if you want to just build project, run next command:
|
||||
|
||||
```bash
|
||||
./gradlew clean build
|
||||
```
|
||||
|
||||
On windows:
|
||||
|
||||
```
|
||||
gradlew.bat clean build
|
||||
```
|
||||
|
||||
### Publishing for work with your version locally
|
||||
|
||||
In case, if you want to work in your other projects using your modification (or some state) of this library,
|
||||
you can use next code:
|
||||
|
||||
```bash
|
||||
./gradlew clean build publishToMavenLocal
|
||||
```
|
||||
|
||||
On windows:
|
||||
|
||||
```
|
||||
gradlew.bat clean build publishToMavenLocal
|
||||
```
|
||||
|
||||
But you must remember, that in this case your local maven repo must be the first one from
|
||||
your project retrieving libraries:
|
||||
|
||||
```groovy
|
||||
repositories {
|
||||
mavenLocal() // that must be the first one
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
retrieveAccumulatedUpdates(this).join()
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Besides, for your own version you can change variable `library_version` in the file [gradle.properties](./gradle.properties).
|
||||
The main difference with the previous example is that bot will get only last updates (accumulated before bot launch
|
||||
and maybe some updates it got after launch)
|
||||
|
||||
### Build a little bit more complex behaviour
|
||||
|
||||
```kotlin
|
||||
suspend fun main() {
|
||||
val bot = telegramBot(TOKEN)
|
||||
|
||||
bot.buildBehaviour {
|
||||
println(getMe())
|
||||
|
||||
val nameReplyMarkup = ReplyKeyboardMarkup(
|
||||
matrix {
|
||||
row {
|
||||
+SimpleKeyboardButton("nope")
|
||||
}
|
||||
}
|
||||
)
|
||||
onCommand("start") {
|
||||
val photo = waitPhoto(
|
||||
SendTextMessage(it.chat.id, "Send me your photo please")
|
||||
).first()
|
||||
|
||||
val name = waitText(
|
||||
SendTextMessage(
|
||||
it.chat.id,
|
||||
"Send me your name or choose \"nope\"",
|
||||
replyMarkup = nameReplyMarkup
|
||||
)
|
||||
).first().text.takeIf { it != "nope" }
|
||||
|
||||
sendPhoto(
|
||||
it.chat,
|
||||
photo.mediaCollection,
|
||||
entities = buildEntities {
|
||||
if (name != null) regular(name) // may be collapsed up to name ?.let(::regular)
|
||||
}
|
||||
)
|
||||
}
|
||||
}.join()
|
||||
}
|
||||
```
|
||||
|
||||
### More examples
|
||||
|
||||
You may find examples in [this project](https://github.com/InsanusMokrassar/TelegramBotAPI-examples). Besides, you are
|
||||
always welcome in our [wiki](https://github.com/InsanusMokrassar/TelegramBotAPI/wiki/About-this-project) and
|
||||
[chat](https://t.me/InMoTelegramBotAPIChat).
|
||||
|
||||
11
build.gradle
11
build.gradle
@@ -18,6 +18,17 @@ plugins {
|
||||
id "org.jetbrains.kotlin.plugin.serialization" version "$kotlin_version" apply false
|
||||
}
|
||||
|
||||
// temporal crutch until legacy tests will be stabled or legacy target will be removed
|
||||
allprojects {
|
||||
if (it != rootProject.findProject("docs")) {
|
||||
tasks.whenTaskAdded { task ->
|
||||
if(task.name == "jsLegacyBrowserTest" || task.name == "jsLegacyNodeTest") {
|
||||
task.enabled = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getCurrentVersionChangelog() {
|
||||
OutputStream changelogDataOS = new ByteArrayOutputStream()
|
||||
exec {
|
||||
|
||||
@@ -36,7 +36,7 @@ kotlin {
|
||||
dependencies {
|
||||
implementation kotlin('stdlib')
|
||||
|
||||
project.parent.subprojects.forEach {
|
||||
rootProject.subprojects.forEach {
|
||||
if (it != project) {
|
||||
api it
|
||||
}
|
||||
@@ -56,7 +56,7 @@ private List<SourceDirectorySet> findSourcesWithName(String... approximateNames)
|
||||
}.collect { it.kotlin }
|
||||
}
|
||||
|
||||
tasks.dokkaHtml {
|
||||
Object callback = {
|
||||
switch (true) {
|
||||
case project.hasProperty("DOKKA_PATH"):
|
||||
outputDirectory = project.property("DOKKA_PATH").toString()
|
||||
@@ -82,11 +82,14 @@ tasks.dokkaHtml {
|
||||
}
|
||||
|
||||
named("jsMain") {
|
||||
sourceRoots.setFrom(findSourcesWithName("jsMain", "commonMain"))
|
||||
sourceRoots.setFrom(findSourcesWithName("jsMain"))
|
||||
}
|
||||
|
||||
named("jvmMain") {
|
||||
sourceRoots.setFrom(findSourcesWithName("jvmMain", "commonMain"))
|
||||
sourceRoots.setFrom(findSourcesWithName("jvmMain"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks.dokkaGfm(callback)
|
||||
tasks.dokkaHtml(callback)
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
dokka_version=1.4.20
|
||||
dokka_version=1.4.32
|
||||
|
||||
org.gradle.jvmargs=-Xmx1024m
|
||||
|
||||
@@ -5,18 +5,18 @@ kotlin.js.generate.externals=true
|
||||
kotlin.incremental=true
|
||||
kotlin.incremental.js=true
|
||||
|
||||
kotlin_version=1.4.21
|
||||
kotlin_coroutines_version=1.4.2
|
||||
kotlin_serialisation_runtime_version=1.0.1
|
||||
klock_version=2.0.4
|
||||
uuid_version=0.2.3
|
||||
ktor_version=1.5.1
|
||||
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.4
|
||||
ktor_version=1.5.4
|
||||
|
||||
micro_utils_version=0.4.23
|
||||
micro_utils_version=0.4.36
|
||||
|
||||
javax_activation_version=1.1.1
|
||||
|
||||
library_group=dev.inmo
|
||||
library_version=0.32.2
|
||||
library_version=0.34.1
|
||||
|
||||
github_release_plugin_version=2.2.12
|
||||
|
||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -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.1-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-bin.zip
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
# TelegramBotAPI Core
|
||||
|
||||
[ ](https://bintray.com/insanusmokrassar/TelegramBotAPI/tgbotapi.core/_latestVersion)
|
||||
[](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi.core)
|
||||
|
||||
## What is it?
|
||||
@@ -10,7 +9,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 [26th of April 2021 update of TelegramBotAPI (version 5.2)](https://core.telegram.org/bots/api-changelog#april-26-2021).
|
||||
|
||||
## How to implement library?
|
||||
|
||||
|
||||
@@ -29,7 +29,9 @@ repositories {
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvm()
|
||||
jvm {
|
||||
compilations.main.kotlinOptions.useIR = true
|
||||
}
|
||||
js(BOTH) {
|
||||
browser()
|
||||
nodejs()
|
||||
@@ -50,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"
|
||||
}
|
||||
@@ -58,6 +61,7 @@ kotlin {
|
||||
dependencies {
|
||||
implementation kotlin('test-common')
|
||||
implementation kotlin('test-annotations-common')
|
||||
implementation project(":tgbotapi.extensions.utils")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"bintrayConfig":{"repo":"TelegramBotAPI","packageName":"${project.name}","packageVcs":"https://github.com/InsanusMokrassar/TelegramBotAPI","autoPublish":true,"overridePublish":true},"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"}],"mavenConfig":{"name":"Telegram Bot API Core","description":"Library for Object-Oriented and type-safe work with Telegram Bot API","url":"https://insanusmokrassar.github.io/TelegramBotAPI","vcsUrl":"https://github.com/insanusmokrassar/TelegramBotAPI.git","includeGpgSigning":true,"developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"}]}}
|
||||
{"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"}],"mavenConfig":{"name":"Telegram Bot API Core","description":"Library for Object-Oriented and type-safe work with Telegram Bot API","url":"https://insanusmokrassar.github.io/TelegramBotAPI","vcsUrl":"https://github.com/insanusmokrassar/TelegramBotAPI.git","includeGpgSigning":true,"developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"}],"repositories":[{"name":"GithubPackages","url":"https://maven.pkg.github.com/InsanusMokrassar/TelegramBotAPI"},{"name":"sonatype","url":"https://oss.sonatype.org/service/local/staging/deploy/maven2/"}]}}
|
||||
@@ -4,22 +4,6 @@ apply plugin: 'signing'
|
||||
task javadocsJar(type: Jar) {
|
||||
classifier = 'javadoc'
|
||||
}
|
||||
task sourceJar (type : Jar) {
|
||||
classifier = 'sources'
|
||||
}
|
||||
|
||||
afterEvaluate {
|
||||
project.publishing.publications.all {
|
||||
// rename artifacts
|
||||
groupId "${project.group}"
|
||||
if (it.name.contains('kotlinMultiplatform')) {
|
||||
artifactId = "${project.name}"
|
||||
artifact sourceJar
|
||||
} else {
|
||||
artifactId = "${project.name}-$name"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications.all {
|
||||
@@ -54,22 +38,32 @@ publishing {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
name = "bintray"
|
||||
url = uri("https://api.bintray.com/maven/${project.hasProperty('BINTRAY_USER') ? project.property('BINTRAY_USER') : System.getenv('BINTRAY_USER')}/TelegramBotAPI/${project.name}/;publish=1;override=1")
|
||||
credentials {
|
||||
username = project.hasProperty('BINTRAY_USER') ? project.property('BINTRAY_USER') : System.getenv('BINTRAY_USER')
|
||||
password = project.hasProperty('BINTRAY_KEY') ? project.property('BINTRAY_KEY') : System.getenv('BINTRAY_KEY')
|
||||
if ((project.hasProperty('GITHUBPACKAGES_USER') || System.getenv('GITHUBPACKAGES_USER') != null) && (project.hasProperty('GITHUBPACKAGES_PASSWORD') || System.getenv('GITHUBPACKAGES_PASSWORD') != null)) {
|
||||
maven {
|
||||
name = "GithubPackages"
|
||||
url = uri("https://maven.pkg.github.com/InsanusMokrassar/TelegramBotAPI")
|
||||
credentials {
|
||||
username = project.hasProperty('GITHUBPACKAGES_USER') ? project.property('GITHUBPACKAGES_USER') : System.getenv('GITHUBPACKAGES_USER')
|
||||
password = project.hasProperty('GITHUBPACKAGES_PASSWORD') ? project.property('GITHUBPACKAGES_PASSWORD') : System.getenv('GITHUBPACKAGES_PASSWORD')
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((project.hasProperty('SONATYPE_USER') || System.getenv('SONATYPE_USER') != null) && (project.hasProperty('SONATYPE_PASSWORD') || System.getenv('SONATYPE_PASSWORD') != null)) {
|
||||
maven {
|
||||
name = "sonatype"
|
||||
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
|
||||
credentials {
|
||||
username = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : System.getenv('SONATYPE_USER')
|
||||
password = project.hasProperty('SONATYPE_PASSWORD') ? project.property('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
signing {
|
||||
useGpgCmd()
|
||||
publishing.publications.forEach { sign it }
|
||||
sign publishing.publications
|
||||
}
|
||||
|
||||
@@ -1,25 +1,20 @@
|
||||
package dev.inmo.tgbotapi.CommonAbstracts
|
||||
|
||||
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
|
||||
const val CaptionDeprecation = "Captioned interface and others will be removed soon and not recommended to use"
|
||||
|
||||
interface Captioned {
|
||||
@Deprecated(CaptionDeprecation)
|
||||
interface Captioned : Texted {
|
||||
@Deprecated(CaptionDeprecation)
|
||||
val caption: String?
|
||||
get() = text
|
||||
}
|
||||
|
||||
interface CaptionedOutput : Captioned {
|
||||
val parseMode: ParseMode?
|
||||
}
|
||||
|
||||
interface CaptionedInput : Captioned {
|
||||
@Deprecated(CaptionDeprecation)
|
||||
interface CaptionedInput : Captioned, TextedInput {
|
||||
/**
|
||||
* Full list of entities. This list WILL contain [TextPart]s with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource]
|
||||
*/
|
||||
@Deprecated(CaptionDeprecation)
|
||||
val captionEntities: List<TextPart>
|
||||
get() = textEntities
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CaptionedInput.captionEntities
|
||||
* @see justTextSources
|
||||
*/
|
||||
val CaptionedInput.textSources
|
||||
get() = captionEntities.justTextSources()
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package dev.inmo.tgbotapi.CommonAbstracts
|
||||
|
||||
import dev.inmo.tgbotapi.types.payments.abstracts.Currencied
|
||||
import dev.inmo.tgbotapi.types.payments.abstracts.Priced
|
||||
|
||||
interface CommonSendInvoiceData : Titled, Currencied, Priced {
|
||||
val description: String
|
||||
val payload: String
|
||||
val providerToken: String
|
||||
val maxTipAmount: Int?
|
||||
val suggestedTipAmounts: List<Int>?
|
||||
val providerData: String?
|
||||
val requireName: Boolean
|
||||
val requirePhoneNumber: Boolean
|
||||
val requireEmail: Boolean
|
||||
val requireShippingAddress: Boolean
|
||||
val shouldSendPhoneNumberToProvider: Boolean
|
||||
val shouldSendEmailToProvider: Boolean
|
||||
val priceDependOnShipAddress: Boolean
|
||||
|
||||
val photoUrl: String?
|
||||
val photoSize: Long?
|
||||
val photoWidth: Int?
|
||||
val photoHeight: Int?
|
||||
|
||||
|
||||
|
||||
fun setPhoto(
|
||||
photoUrl: String,
|
||||
photoSize: Long? = null,
|
||||
photoWidth: Int? = null,
|
||||
photoHeight: Int? = null
|
||||
)
|
||||
|
||||
fun unsetPhoto()
|
||||
}
|
||||
@@ -1,31 +1,26 @@
|
||||
package dev.inmo.tgbotapi.CommonAbstracts
|
||||
|
||||
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
|
||||
|
||||
interface Explained {
|
||||
@Deprecated("Will be removed soon")
|
||||
interface Explained : Texted {
|
||||
val explanation: String?
|
||||
get() = text
|
||||
}
|
||||
|
||||
interface ParsableExplainedOutput : Explained {
|
||||
val parseMode: ParseMode?
|
||||
}
|
||||
@Deprecated("Will be removed soon")
|
||||
interface ParsableExplainedOutput : Explained, TextedOutput
|
||||
|
||||
interface EntitiesExplainedOutput : Explained {
|
||||
val entities: List<TextSource>?
|
||||
}
|
||||
@Deprecated("Will be removed soon")
|
||||
interface EntitiesExplainedOutput : Explained, EntitiesOutput
|
||||
|
||||
@Deprecated("Will be removed soon")
|
||||
interface ExplainedOutput : ParsableExplainedOutput, EntitiesExplainedOutput
|
||||
|
||||
@Deprecated("Will be removed soon")
|
||||
interface ExplainedInput : Explained {
|
||||
val textSources: TextSourcesList
|
||||
/**
|
||||
* Full list of entities. This list WILL contain [TextPart]s with [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource]
|
||||
*/
|
||||
val explanationEntities: List<TextPart>
|
||||
get() = textSources.toTextParts()
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ExplainedInput.explanationEntities
|
||||
* @see justTextSources
|
||||
*/
|
||||
val ExplainedInput.textSources
|
||||
get() = explanationEntities.justTextSources()
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package dev.inmo.tgbotapi.CommonAbstracts
|
||||
|
||||
import dev.inmo.tgbotapi.types.User
|
||||
|
||||
interface FromUser {
|
||||
val user: User
|
||||
}
|
||||
@@ -1,14 +1,16 @@
|
||||
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<TextSource>
|
||||
|
||||
@Serializable(TextSourceSerializer::class)
|
||||
interface TextSource {
|
||||
val markdown: String
|
||||
val markdownV2: String
|
||||
@@ -17,6 +19,10 @@ interface TextSource {
|
||||
|
||||
val asText: String
|
||||
get() = source
|
||||
|
||||
companion object {
|
||||
fun serializer() = TextSourceSerializer
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
@@ -28,18 +34,36 @@ inline operator fun TextSource.plus(text: String) = listOf(this, regular(text))
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline operator fun List<TextSource>.plus(text: String) = this + regular(text)
|
||||
|
||||
@Serializable(TextSourceSerializer::class)
|
||||
interface MultilevelTextSource : TextSource {
|
||||
val subsources: List<TextSource>
|
||||
|
||||
companion object {
|
||||
fun serializer() = TextSourceSerializer
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated("This class will be removed soon. Use TextSources instead")
|
||||
data class TextPart(
|
||||
val range: IntRange,
|
||||
val source: TextSource
|
||||
)
|
||||
|
||||
@Deprecated("This method is no longer required to work with TextSources")
|
||||
fun List<TextPart>.justTextSources() = map { it.source }
|
||||
internal fun List<TextSource>.toTextParts(preOffset: Int = 0): List<TextPart> {
|
||||
var i = preOffset
|
||||
return map {
|
||||
TextPart(
|
||||
i until (i + it.source.length),
|
||||
it
|
||||
).also {
|
||||
i = it.range.last + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun List<TextSource>.makeString() = joinToString("") { it.source }
|
||||
internal fun MultilevelTextSource.textParts(offset: Int): List<TextPart> = subsources.toTextParts(offset)
|
||||
fun List<TextSource>.separateForMessage(limit: IntRange, numberOfParts: Int? = null): List<List<TextSource>> {
|
||||
if (isEmpty()) {
|
||||
return emptyList()
|
||||
|
||||
@@ -5,31 +5,31 @@ import dev.inmo.tgbotapi.types.ParseMode.ParseMode
|
||||
interface Texted {
|
||||
val text: String?
|
||||
}
|
||||
interface TextedWithTextSources : Texted {
|
||||
/**
|
||||
* Full list of [TextSource] built from source[TextedInput.textEntities]
|
||||
*/
|
||||
val textSources: List<TextSource>?
|
||||
}
|
||||
|
||||
interface ParsableOutput : Texted {
|
||||
val parseMode: ParseMode?
|
||||
}
|
||||
|
||||
interface EntitiesOutput : Texted {
|
||||
interface EntitiesOutput : TextedWithTextSources {
|
||||
val entities: List<TextSource>?
|
||||
get() = textSources
|
||||
}
|
||||
|
||||
interface TextedOutput : ParsableOutput, EntitiesOutput
|
||||
|
||||
interface TextedInput : Texted {
|
||||
interface TextedInput : TextedWithTextSources {
|
||||
override val textSources: List<TextSource>
|
||||
/**
|
||||
* Here must be full list of entities. This list must contains [TextPart]s with
|
||||
* [dev.inmo.tgbotapi.types.MessageEntity.textsources.RegularTextSource] in case if source text contains parts of
|
||||
* regular text
|
||||
*/
|
||||
val textEntities: List<TextPart>
|
||||
get() = textSources.toTextParts()
|
||||
}
|
||||
|
||||
/**
|
||||
* Full list of [TextSource] built from source[TextedInput.textEntities]
|
||||
*
|
||||
* @see TextedInput.textEntities
|
||||
* @see justTextSources
|
||||
*/
|
||||
val TextedInput.textSources
|
||||
get() = textEntities.justTextSources()
|
||||
|
||||
@@ -16,6 +16,8 @@ import io.ktor.http.ContentType
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlin.collections.set
|
||||
|
||||
var defaultUpdateTimeoutForZeroDelay = 1000L
|
||||
|
||||
abstract class AbstractRequestCallFactory : KtorCallFactory {
|
||||
private val methodsCache: MutableMap<String, String> = mutableMapOf()
|
||||
override suspend fun <T : Any> makeCall(
|
||||
@@ -41,6 +43,11 @@ abstract class AbstractRequestCallFactory : KtorCallFactory {
|
||||
requestTimeoutMillis = customTimeoutMillis
|
||||
socketTimeoutMillis = customTimeoutMillis
|
||||
}
|
||||
} else {
|
||||
timeout {
|
||||
requestTimeoutMillis = defaultUpdateTimeoutForZeroDelay
|
||||
socketTimeoutMillis = defaultUpdateTimeoutForZeroDelay
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -17,7 +17,9 @@ class CommonLimiter(
|
||||
@Transient
|
||||
private val scope: CoroutineScope = CoroutineScope(Dispatchers.Default)
|
||||
) : RequestLimiter {
|
||||
@Transient
|
||||
private val quotaSemaphore = Semaphore(lockCount)
|
||||
@Transient
|
||||
private val counterRegeneratorJob = scope.launch {
|
||||
val regenDelay: MilliSeconds = (regenTime.toDouble() / lockCount).roundToLong()
|
||||
while (isActive) {
|
||||
|
||||
@@ -37,11 +37,12 @@ class ExceptionsOnlyLimiter(
|
||||
override suspend fun <T> limit(block: suspend () -> T): T {
|
||||
while (true) {
|
||||
lockState.first { !it }
|
||||
var throwable: Throwable? = null
|
||||
val result = safely({
|
||||
when (it) {
|
||||
throwable = when (it) {
|
||||
is TooMuchRequestsException -> {
|
||||
lock(it.retryAfter.leftToRetry)
|
||||
Result.failure(it)
|
||||
it
|
||||
}
|
||||
is ClientRequestException -> {
|
||||
if (it.response.status == HttpStatusCode.TooManyRequests) {
|
||||
@@ -49,15 +50,16 @@ class ExceptionsOnlyLimiter(
|
||||
} else {
|
||||
throw it
|
||||
}
|
||||
Result.failure(it)
|
||||
it
|
||||
}
|
||||
else -> throw it
|
||||
}
|
||||
null
|
||||
}) {
|
||||
Result.success(block())
|
||||
block()
|
||||
}
|
||||
if (result.isSuccess) {
|
||||
return result.getOrNull()!!
|
||||
if (throwable == null) {
|
||||
return result!!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package dev.inmo.tgbotapi.requests.chat.abstracts
|
||||
|
||||
import com.soywiz.klock.DateTime
|
||||
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import kotlinx.serialization.DeserializationStrategy
|
||||
|
||||
interface ChatInviteLinkRequest : SimpleRequest<CommonInviteLink> {
|
||||
val chatId: ChatIdentifier
|
||||
|
||||
override val resultDeserializer: DeserializationStrategy<CommonInviteLink>
|
||||
get() = CommonInviteLink.serializer()
|
||||
}
|
||||
interface KnownChatInviteLinkRequest : ChatInviteLinkRequest {
|
||||
val inviteLink: String
|
||||
}
|
||||
interface EditChatInviteLinkRequest : ChatInviteLinkRequest {
|
||||
val expireDate: DateTime?
|
||||
val membersLimit: MembersLimit?
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package dev.inmo.tgbotapi.requests.chat.invite_links
|
||||
|
||||
import com.soywiz.klock.DateTime
|
||||
import dev.inmo.tgbotapi.requests.chat.abstracts.EditChatInviteLinkRequest
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class CreateChatInviteLink(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(expireDateField)
|
||||
private val expirationUnixTimeStamp: TelegramDate? = null,
|
||||
@SerialName(memberLimitField)
|
||||
override val membersLimit: MembersLimit? = null
|
||||
) : EditChatInviteLinkRequest {
|
||||
override val expireDate: DateTime?
|
||||
get() = expirationUnixTimeStamp ?.asDate
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
|
||||
override fun method(): String = "createChatInviteLink"
|
||||
}
|
||||
|
||||
fun CreateChatInviteLink(
|
||||
chatId: ChatId,
|
||||
expireDate: DateTime,
|
||||
membersLimit: MembersLimit? = null
|
||||
): CreateChatInviteLink = CreateChatInviteLink(
|
||||
chatId, expireDate.toTelegramDate(), membersLimit
|
||||
)
|
||||
@@ -0,0 +1,35 @@
|
||||
package dev.inmo.tgbotapi.requests.chat.invite_links
|
||||
|
||||
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.*
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class EditChatInviteLink(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(inviteLinkField)
|
||||
override val inviteLink: String,
|
||||
@SerialName(expireDateField)
|
||||
private val expirationUnixTimeStamp: TelegramDate? = null,
|
||||
@SerialName(memberLimitField)
|
||||
override val membersLimit: MembersLimit? = null
|
||||
) : EditChatInviteLinkRequest, KnownChatInviteLinkRequest {
|
||||
override val expireDate: DateTime?
|
||||
get() = expirationUnixTimeStamp ?.asDate
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
|
||||
override fun method(): String = "editChatInviteLink"
|
||||
}
|
||||
|
||||
fun EditChatInviteLink(
|
||||
chatId: ChatIdentifier,
|
||||
inviteLink: String,
|
||||
expireDate: DateTime,
|
||||
membersLimit: MembersLimit? = null
|
||||
): EditChatInviteLink = EditChatInviteLink(
|
||||
chatId, inviteLink, expireDate.toTelegramDate(), membersLimit
|
||||
)
|
||||
@@ -0,0 +1,18 @@
|
||||
package dev.inmo.tgbotapi.requests.chat.invite_links
|
||||
|
||||
import dev.inmo.tgbotapi.requests.chat.abstracts.KnownChatInviteLinkRequest
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class RevokeChatInviteLink(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier,
|
||||
@SerialName(inviteLinkField)
|
||||
override val inviteLink: String
|
||||
) : KnownChatInviteLinkRequest {
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
|
||||
override fun method(): String = "revokeChatInviteLink"
|
||||
}
|
||||
@@ -13,7 +13,9 @@ data class KickChatMember(
|
||||
@SerialName(userIdField)
|
||||
override val userId: UserId,
|
||||
@SerialName(untilDateField)
|
||||
override val untilDate: TelegramDate? = null
|
||||
override val untilDate: TelegramDate? = null,
|
||||
@SerialName(revokeMessagesField)
|
||||
val revokeMessages: Boolean? = null
|
||||
) : ChatMemberRequest<Boolean>, UntilDate {
|
||||
override fun method(): String = "kickChatMember"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
|
||||
@@ -31,7 +31,11 @@ data class PromoteChatMember(
|
||||
@SerialName(canPinMessagesField)
|
||||
private val canPinMessages: Boolean? = null,
|
||||
@SerialName(canPromoteMembersField)
|
||||
private val canPromoteMembers: Boolean? = null
|
||||
private val canPromoteMembers: Boolean? = null,
|
||||
@SerialName(canManageVoiceChatsField)
|
||||
private val canManageVoiceChats: Boolean? = null,
|
||||
@SerialName(canManageChatField)
|
||||
private val canManageChat: Boolean? = null
|
||||
) : ChatMemberRequest<Boolean>, UntilDate {
|
||||
override fun method(): String = "promoteChatMember"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
|
||||
@@ -18,6 +18,8 @@ data class SetChatPhoto (
|
||||
override fun method(): String = "setChatPhoto"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = Boolean.serializer()
|
||||
@Transient
|
||||
override val mediaMap: Map<String, MultipartFile> = mapOf(photoField to photo)
|
||||
@Transient
|
||||
override val paramsJson: JsonObject = toJson(serializer())
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.inmo.tgbotapi.requests.edit.caption
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.makeString
|
||||
import dev.inmo.tgbotapi.requests.edit.abstracts.*
|
||||
import dev.inmo.tgbotapi.requests.edit.media.MediaContentMessageResultDeserializer
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
@@ -58,8 +59,8 @@ data class EditChatMessageCaption internal constructor(
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditChatMessage<MediaContent>, EditTextChatMessage, EditReplyMessage {
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text) ?.justTextSources()
|
||||
override val textSources: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextSources(text)
|
||||
}
|
||||
|
||||
override fun method(): String = editMessageCaptionMethod
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.inmo.tgbotapi.requests.edit.caption
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.makeString
|
||||
import dev.inmo.tgbotapi.requests.edit.abstracts.*
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.MessageEntity.*
|
||||
@@ -47,8 +48,8 @@ data class EditInlineMessageCaption internal constructor(
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditInlineMessage, EditTextChatMessage, EditReplyMessage {
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text) ?.justTextSources()
|
||||
override val textSources: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextSources(text)
|
||||
}
|
||||
|
||||
override fun method(): String = editMessageCaptionMethod
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.inmo.tgbotapi.requests.edit.text
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.makeString
|
||||
import dev.inmo.tgbotapi.requests.edit.abstracts.*
|
||||
import dev.inmo.tgbotapi.requests.send.TextContentMessageResultDeserializer
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
@@ -64,8 +65,8 @@ data class EditChatMessageText internal constructor(
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditChatMessage<TextContent>, EditTextChatMessage, EditReplyMessage, EditDisableWebPagePreviewMessage {
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text) ?.justTextSources()
|
||||
override val textSources: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextSources(text)
|
||||
}
|
||||
|
||||
override fun method(): String = editMessageTextMethod
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.inmo.tgbotapi.requests.edit.text
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.makeString
|
||||
import dev.inmo.tgbotapi.requests.edit.abstracts.*
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.MessageEntity.*
|
||||
@@ -53,8 +54,8 @@ data class EditInlineMessageText internal constructor(
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditInlineMessage, EditTextChatMessage, EditReplyMessage, EditDisableWebPagePreviewMessage {
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text) ?.justTextSources()
|
||||
override val textSources: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextSources(text)
|
||||
}
|
||||
|
||||
override fun method(): String = editMessageTextMethod
|
||||
|
||||
@@ -62,8 +62,8 @@ data class CopyMessage internal constructor(
|
||||
TextedOutput {
|
||||
override val chatId: ChatIdentifier
|
||||
get() = fromChatId
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
|
||||
override val textSources: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextSources(text ?: return@lazy null)
|
||||
}
|
||||
|
||||
override fun method(): String = "copyMessage"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.inmo.tgbotapi.requests.send
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.makeString
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.types.DisableWebPagePreview
|
||||
import dev.inmo.tgbotapi.requests.send.abstracts.*
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
@@ -83,8 +84,8 @@ data class SendTextMessage internal constructor(
|
||||
TextableSendMessageRequest<ContentMessage<TextContent>>,
|
||||
DisableWebPagePreview
|
||||
{
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text) ?.justTextSources()
|
||||
override val textSources: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextSources(text)
|
||||
}
|
||||
|
||||
init {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.inmo.tgbotapi.requests.send.media
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.makeString
|
||||
import dev.inmo.tgbotapi.requests.abstracts.*
|
||||
import dev.inmo.tgbotapi.requests.send.abstracts.*
|
||||
import dev.inmo.tgbotapi.requests.send.media.base.*
|
||||
@@ -20,7 +21,7 @@ fun SendAnimation(
|
||||
chatId: ChatIdentifier,
|
||||
animation: InputFile,
|
||||
thumb: InputFile? = null,
|
||||
caption: String? = null,
|
||||
text: String? = null,
|
||||
parseMode: ParseMode? = null,
|
||||
duration: Long? = null,
|
||||
width: Int? = null,
|
||||
@@ -39,7 +40,7 @@ fun SendAnimation(
|
||||
chatId,
|
||||
animationAsFileId,
|
||||
thumbAsFileId,
|
||||
caption,
|
||||
text,
|
||||
parseMode,
|
||||
null,
|
||||
duration,
|
||||
@@ -144,8 +145,8 @@ data class SendAnimationData internal constructor(
|
||||
DuratedSendMessageRequest<ContentMessage<AnimationContent>>,
|
||||
SizedSendMessageRequest<ContentMessage<AnimationContent>>
|
||||
{
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
|
||||
override val textSources: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextSources(text ?: return@lazy null)
|
||||
}
|
||||
|
||||
init {
|
||||
|
||||
@@ -20,7 +20,7 @@ fun SendAudio(
|
||||
chatId: ChatIdentifier,
|
||||
audio: InputFile,
|
||||
thumb: InputFile? = null,
|
||||
caption: String? = null,
|
||||
text: String? = null,
|
||||
parseMode: ParseMode? = null,
|
||||
duration: Long? = null,
|
||||
performer: String? = null,
|
||||
@@ -39,7 +39,7 @@ fun SendAudio(
|
||||
chatId,
|
||||
audioAsFileId,
|
||||
thumbAsFileId,
|
||||
caption,
|
||||
text,
|
||||
parseMode,
|
||||
null,
|
||||
duration,
|
||||
@@ -145,8 +145,8 @@ data class SendAudioData internal constructor(
|
||||
DuratedSendMessageRequest<ContentMessage<AudioContent>>,
|
||||
Performerable
|
||||
{
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
|
||||
override val textSources: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextSources(text ?: return@lazy null)
|
||||
}
|
||||
|
||||
init {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.inmo.tgbotapi.requests.send.media
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.makeString
|
||||
import dev.inmo.tgbotapi.requests.abstracts.*
|
||||
import dev.inmo.tgbotapi.requests.send.abstracts.*
|
||||
import dev.inmo.tgbotapi.requests.send.media.base.*
|
||||
@@ -29,7 +30,7 @@ fun SendDocument(
|
||||
chatId: ChatIdentifier,
|
||||
document: InputFile,
|
||||
thumb: InputFile? = null,
|
||||
caption: String? = null,
|
||||
text: String? = null,
|
||||
parseMode: ParseMode? = null,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
@@ -46,7 +47,7 @@ fun SendDocument(
|
||||
chatId,
|
||||
documentAsFileId,
|
||||
thumbAsFileId,
|
||||
caption,
|
||||
text,
|
||||
parseMode,
|
||||
null,
|
||||
disableNotification,
|
||||
@@ -157,8 +158,8 @@ data class SendDocumentData internal constructor(
|
||||
TextableSendMessageRequest<ContentMessage<DocumentContent>>,
|
||||
ThumbedSendMessageRequest<ContentMessage<DocumentContent>>
|
||||
{
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
|
||||
override val textSources: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextSources(text ?: return@lazy null)
|
||||
}
|
||||
|
||||
init {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.inmo.tgbotapi.requests.send.media
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.makeString
|
||||
import dev.inmo.tgbotapi.requests.abstracts.*
|
||||
import dev.inmo.tgbotapi.requests.send.abstracts.*
|
||||
import dev.inmo.tgbotapi.requests.send.media.base.*
|
||||
@@ -18,7 +19,7 @@ import kotlinx.serialization.*
|
||||
fun SendPhoto(
|
||||
chatId: ChatIdentifier,
|
||||
photo: InputFile,
|
||||
caption: String? = null,
|
||||
text: String? = null,
|
||||
parseMode: ParseMode? = null,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
@@ -28,7 +29,7 @@ fun SendPhoto(
|
||||
val data = SendPhotoData(
|
||||
chatId,
|
||||
(photo as? FileId) ?.fileId,
|
||||
caption,
|
||||
text,
|
||||
parseMode,
|
||||
null,
|
||||
disableNotification,
|
||||
@@ -100,8 +101,8 @@ data class SendPhotoData internal constructor(
|
||||
ReplyingMarkupSendMessageRequest<ContentMessage<PhotoContent>>,
|
||||
TextableSendMessageRequest<ContentMessage<PhotoContent>>
|
||||
{
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
|
||||
override val textSources: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextSources(text ?: return@lazy null)
|
||||
}
|
||||
|
||||
init {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.inmo.tgbotapi.requests.send.media
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.makeString
|
||||
import dev.inmo.tgbotapi.requests.abstracts.*
|
||||
import dev.inmo.tgbotapi.requests.send.abstracts.*
|
||||
import dev.inmo.tgbotapi.requests.send.media.base.*
|
||||
@@ -20,7 +21,7 @@ fun SendVideo(
|
||||
chatId: ChatIdentifier,
|
||||
video: InputFile,
|
||||
thumb: InputFile? = null,
|
||||
caption: String? = null,
|
||||
text: String? = null,
|
||||
parseMode: ParseMode? = null,
|
||||
duration: Long? = null,
|
||||
width: Int? = null,
|
||||
@@ -40,7 +41,7 @@ fun SendVideo(
|
||||
chatId,
|
||||
videoAsFileId,
|
||||
thumbAsFileId,
|
||||
caption,
|
||||
text,
|
||||
parseMode,
|
||||
null,
|
||||
duration,
|
||||
@@ -150,8 +151,8 @@ data class SendVideoData internal constructor(
|
||||
DuratedSendMessageRequest<ContentMessage<VideoContent>>,
|
||||
SizedSendMessageRequest<ContentMessage<VideoContent>>
|
||||
{
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
|
||||
override val textSources: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextSources(text ?: return@lazy null)
|
||||
}
|
||||
|
||||
init {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.inmo.tgbotapi.requests.send.media
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.makeString
|
||||
import dev.inmo.tgbotapi.requests.abstracts.*
|
||||
import dev.inmo.tgbotapi.requests.send.abstracts.*
|
||||
import dev.inmo.tgbotapi.requests.send.media.base.*
|
||||
@@ -19,7 +20,7 @@ import kotlinx.serialization.*
|
||||
fun SendVoice(
|
||||
chatId: ChatIdentifier,
|
||||
voice: InputFile,
|
||||
caption: String? = null,
|
||||
text: String? = null,
|
||||
parseMode: ParseMode? = null,
|
||||
duration: Long? = null,
|
||||
disableNotification: Boolean = false,
|
||||
@@ -33,7 +34,7 @@ fun SendVoice(
|
||||
val data = SendVoiceData(
|
||||
chatId,
|
||||
voiceAsFileId,
|
||||
caption,
|
||||
text,
|
||||
parseMode,
|
||||
null,
|
||||
duration,
|
||||
@@ -120,8 +121,8 @@ data class SendVoiceData internal constructor(
|
||||
TextableSendMessageRequest<ContentMessage<VoiceContent>>,
|
||||
DuratedSendMessageRequest<ContentMessage<VoiceContent>>
|
||||
{
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
|
||||
override val textSources: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextSources(text ?: return@lazy null)
|
||||
}
|
||||
|
||||
init {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package dev.inmo.tgbotapi.requests.send.payments
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.CommonSendInvoiceData
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.types.*
|
||||
import dev.inmo.tgbotapi.requests.send.abstracts.SendMessageRequest
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
@@ -9,7 +10,7 @@ import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializ
|
||||
import dev.inmo.tgbotapi.types.message.payments.InvoiceContent
|
||||
import dev.inmo.tgbotapi.types.payments.LabeledPrice
|
||||
import dev.inmo.tgbotapi.types.payments.LabeledPricesSerializer
|
||||
import dev.inmo.tgbotapi.types.payments.abstracts.*
|
||||
import dev.inmo.tgbotapi.types.payments.abstracts.Currency
|
||||
import kotlinx.serialization.*
|
||||
|
||||
private val invoiceMessageSerializer: DeserializationStrategy<ContentMessage<InvoiceContent>>
|
||||
@@ -23,36 +24,40 @@ data class SendInvoice(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatId,
|
||||
@SerialName(titleField)
|
||||
val title: String,
|
||||
override val title: String,
|
||||
@SerialName(descriptionField)
|
||||
val description: String,
|
||||
override val description: String,
|
||||
@SerialName(payloadField)
|
||||
val payload: String,
|
||||
override val payload: String,
|
||||
@SerialName(providerTokenField)
|
||||
val providerToken: String,
|
||||
@SerialName(startParameterField)
|
||||
val startParameter: StartParameter,
|
||||
override val providerToken: String,
|
||||
@SerialName(currencyField)
|
||||
override val currency: Currency,
|
||||
@Serializable(LabeledPricesSerializer::class)
|
||||
@SerialName(pricesField)
|
||||
override val prices: List<LabeledPrice>,
|
||||
@SerialName(maxTipAmountField)
|
||||
override val maxTipAmount: Int? = null,
|
||||
@SerialName(suggestedTipAmountsField)
|
||||
override val suggestedTipAmounts: List<Int>? = null,
|
||||
@SerialName(startParameterField)
|
||||
val startParameter: StartParameter? = null,
|
||||
@SerialName(providerDataField)
|
||||
val providerData: String? = null,
|
||||
override val providerData: String? = null,
|
||||
@SerialName(requireNameField)
|
||||
val requireName: Boolean = false,
|
||||
override val requireName: Boolean = false,
|
||||
@SerialName(requirePhoneNumberField)
|
||||
val requirePhoneNumber: Boolean = false,
|
||||
override val requirePhoneNumber: Boolean = false,
|
||||
@SerialName(requireEmailField)
|
||||
val requireEmail: Boolean = false,
|
||||
override val requireEmail: Boolean = false,
|
||||
@SerialName(requireShippingAddressField)
|
||||
val requireShippingAddress: Boolean = false,
|
||||
override val requireShippingAddress: Boolean = false,
|
||||
@SerialName(shouldSendPhoneNumberToProviderField)
|
||||
val shouldSendPhoneNumberToProvider: Boolean = false,
|
||||
override val shouldSendPhoneNumberToProvider: Boolean = false,
|
||||
@SerialName(shouldSendEmailToProviderField)
|
||||
val shouldSendEmailToProvider: Boolean = false,
|
||||
override val shouldSendEmailToProvider: Boolean = false,
|
||||
@SerialName(priceDependOnShipAddressField)
|
||||
val priceDependOnShipAddress: Boolean = false,
|
||||
override val priceDependOnShipAddress: Boolean = false,
|
||||
@SerialName(disableNotificationField)
|
||||
override val disableNotification: Boolean = false,
|
||||
@SerialName(replyToMessageIdField)
|
||||
@@ -61,8 +66,7 @@ data class SendInvoice(
|
||||
override val allowSendingWithoutReply: Boolean? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : Currencied,
|
||||
Priced,
|
||||
) : CommonSendInvoiceData,
|
||||
ChatRequest,
|
||||
DisableNotification,
|
||||
ReplyMessageId,
|
||||
@@ -75,24 +79,35 @@ data class SendInvoice(
|
||||
get() = serializer()
|
||||
|
||||
@SerialName(photoUrlField)
|
||||
var photoUrl: String? = null
|
||||
override var photoUrl: String? = null
|
||||
private set
|
||||
@SerialName(photoSizeField)
|
||||
var photoSize: Long? = null
|
||||
override var photoSize: Long? = null
|
||||
private set
|
||||
|
||||
@SerialName(photoWidthField)
|
||||
var photoWidth: Int? = null
|
||||
override var photoWidth: Int? = null
|
||||
private set
|
||||
@SerialName(photoHeightField)
|
||||
var photoHeight: Int? = null
|
||||
override var photoHeight: Int? = null
|
||||
private set
|
||||
|
||||
fun setPhoto(
|
||||
init {
|
||||
suggestedTipAmounts ?.let { _ ->
|
||||
require(suggestedTipAmounts.size in suggestedTipAmountsLimit)
|
||||
maxTipAmount ?.let { _ ->
|
||||
require(
|
||||
suggestedTipAmounts.none { it > maxTipAmount }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun setPhoto(
|
||||
photoUrl: String,
|
||||
photoSize: Long? = null,
|
||||
photoWidth: Int? = null,
|
||||
photoHeight: Int? = null
|
||||
photoSize: Long?,
|
||||
photoWidth: Int?,
|
||||
photoHeight: Int?
|
||||
) {
|
||||
this.photoUrl = photoUrl
|
||||
this.photoSize = photoSize
|
||||
@@ -100,7 +115,7 @@ data class SendInvoice(
|
||||
this.photoHeight = photoHeight
|
||||
}
|
||||
|
||||
fun unsetPhoto() {
|
||||
override fun unsetPhoto() {
|
||||
photoUrl = null
|
||||
photoSize = null
|
||||
photoWidth = null
|
||||
|
||||
@@ -16,6 +16,11 @@ import kotlinx.serialization.*
|
||||
|
||||
private val commonResultDeserializer: DeserializationStrategy<ContentMessage<PollContent>> = TelegramBotAPIMessageDeserializationStrategyClass()
|
||||
|
||||
private inline val ApproximateScheduledCloseInfo.openPeriod
|
||||
get() = openDuration.millisecondsLong.div(1000)
|
||||
private inline val ExactScheduledCloseInfo.closeDate
|
||||
get() = closeDateTime.unixMillisLong.div(1000)
|
||||
|
||||
private fun checkPollInfo(
|
||||
question: String,
|
||||
options: List<String>
|
||||
@@ -138,12 +143,23 @@ sealed class SendPoll : SendMessageRequest<ContentMessage<PollContent>>,
|
||||
abstract val options: List<String>
|
||||
abstract val isAnonymous: Boolean
|
||||
abstract val isClosed: Boolean
|
||||
abstract val closeInfo: ScheduledCloseInfo?
|
||||
abstract val type: String
|
||||
|
||||
internal abstract val openPeriod: LongSeconds?
|
||||
internal abstract val closeDate: LongSeconds?
|
||||
|
||||
protected val creationDate = DateTime.now()
|
||||
open val closeInfo: ScheduledCloseInfo?
|
||||
get() {
|
||||
val openPeriod = openPeriod
|
||||
val closeDate = closeDate
|
||||
return when {
|
||||
openPeriod != null -> openPeriod.asApproximateScheduledCloseInfo(creationDate)
|
||||
closeDate != null -> closeDate.asExactScheduledCloseInfo
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
override fun method(): String = "sendPoll"
|
||||
override val resultDeserializer: DeserializationStrategy<ContentMessage<PollContent>>
|
||||
get() = commonResultDeserializer
|
||||
@@ -163,8 +179,10 @@ data class SendRegularPoll(
|
||||
override val isClosed: Boolean = false,
|
||||
@SerialName(allowsMultipleAnswersField)
|
||||
val allowMultipleAnswers: Boolean = false,
|
||||
@Transient
|
||||
override val closeInfo: ScheduledCloseInfo? = null,
|
||||
@SerialName(openPeriodField)
|
||||
override val openPeriod: LongSeconds?= null,
|
||||
@SerialName(closeDateField)
|
||||
override val closeDate: LongSeconds?,
|
||||
@SerialName(disableNotificationField)
|
||||
override val disableNotification: Boolean = false,
|
||||
@SerialName(replyToMessageIdField)
|
||||
@@ -178,20 +196,39 @@ data class SendRegularPoll(
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
|
||||
@SerialName(openPeriodField)
|
||||
override val openPeriod: LongSeconds?
|
||||
= (closeInfo as? ApproximateScheduledCloseInfo) ?.openDuration ?.millisecondsLong ?.div(1000)
|
||||
|
||||
@SerialName(closeDateField)
|
||||
override val closeDate: LongSeconds?
|
||||
= (closeInfo as? ExactScheduledCloseInfo) ?.closeDateTime ?.unixMillisLong ?.div(1000)
|
||||
|
||||
init {
|
||||
checkPollInfo(question, options)
|
||||
closeInfo ?.checkSendData()
|
||||
}
|
||||
}
|
||||
|
||||
fun SendRegularPoll(
|
||||
chatId: ChatIdentifier,
|
||||
question: String,
|
||||
options: List<String>,
|
||||
isAnonymous: Boolean = true,
|
||||
isClosed: Boolean = false,
|
||||
allowMultipleAnswers: Boolean = false,
|
||||
closeInfo: ScheduledCloseInfo? = null,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
allowSendingWithoutReply: Boolean? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
) = SendRegularPoll(
|
||||
chatId,
|
||||
question,
|
||||
options,
|
||||
isAnonymous,
|
||||
isClosed,
|
||||
allowMultipleAnswers,
|
||||
(closeInfo as? ApproximateScheduledCloseInfo) ?.openPeriod,
|
||||
(closeInfo as? ExactScheduledCloseInfo) ?.closeDate,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
allowSendingWithoutReply,
|
||||
replyMarkup
|
||||
)
|
||||
|
||||
fun SendQuizPoll(
|
||||
chatId: ChatIdentifier,
|
||||
question: String,
|
||||
@@ -253,6 +290,39 @@ fun SendQuizPoll(
|
||||
replyMarkup
|
||||
)
|
||||
|
||||
internal fun SendQuizPoll(
|
||||
chatId: ChatIdentifier,
|
||||
question: String,
|
||||
options: List<String>,
|
||||
correctOptionId: Int,
|
||||
isAnonymous: Boolean = true,
|
||||
isClosed: Boolean = false,
|
||||
explanation: String? = null,
|
||||
parseMode: ParseMode? = null,
|
||||
rawEntities: List<RawMessageEntity>? = null,
|
||||
closeInfo: ScheduledCloseInfo? = null,
|
||||
disableNotification: Boolean = false,
|
||||
replyToMessageId: MessageIdentifier? = null,
|
||||
allowSendingWithoutReply: Boolean? = null,
|
||||
replyMarkup: KeyboardMarkup? = null
|
||||
) = SendQuizPoll(
|
||||
chatId,
|
||||
question,
|
||||
options,
|
||||
correctOptionId,
|
||||
isAnonymous,
|
||||
isClosed,
|
||||
explanation,
|
||||
parseMode,
|
||||
rawEntities,
|
||||
(closeInfo as? ApproximateScheduledCloseInfo) ?.openPeriod,
|
||||
(closeInfo as? ExactScheduledCloseInfo) ?.closeDate,
|
||||
disableNotification,
|
||||
replyToMessageId,
|
||||
allowSendingWithoutReply,
|
||||
replyMarkup
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class SendQuizPoll internal constructor(
|
||||
@SerialName(chatIdField)
|
||||
@@ -268,13 +338,15 @@ data class SendQuizPoll internal constructor(
|
||||
@SerialName(isClosedField)
|
||||
override val isClosed: Boolean = false,
|
||||
@SerialName(explanationField)
|
||||
override val explanation: String? = null,
|
||||
override val text: String? = null,
|
||||
@SerialName(explanationParseModeField)
|
||||
override val parseMode: ParseMode? = null,
|
||||
@SerialName(explanationEntitiesField)
|
||||
private val rawEntities: List<RawMessageEntity>? = null,
|
||||
@Transient
|
||||
override val closeInfo: ScheduledCloseInfo? = null,
|
||||
@SerialName(openPeriodField)
|
||||
override val openPeriod: LongSeconds? = null,
|
||||
@SerialName(closeDateField)
|
||||
override val closeDate: LongSeconds? = null,
|
||||
@SerialName(disableNotificationField)
|
||||
override val disableNotification: Boolean = false,
|
||||
@SerialName(replyToMessageIdField)
|
||||
@@ -283,22 +355,14 @@ data class SendQuizPoll internal constructor(
|
||||
override val allowSendingWithoutReply: Boolean? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: KeyboardMarkup? = null
|
||||
) : SendPoll(), ExplainedOutput {
|
||||
) : SendPoll(), ExplainedOutput, TextedOutput {
|
||||
override val type: String = quizPollType
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(explanation ?: return@lazy null) ?.justTextSources()
|
||||
override val textSources: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextSources(text ?: return@lazy null)
|
||||
}
|
||||
|
||||
@SerialName(openPeriodField)
|
||||
override val openPeriod: LongSeconds?
|
||||
= (closeInfo as? ApproximateScheduledCloseInfo) ?.openDuration ?.millisecondsLong ?.div(1000)
|
||||
|
||||
@SerialName(closeDateField)
|
||||
override val closeDate: LongSeconds?
|
||||
= (closeInfo as? ExactScheduledCloseInfo) ?.closeDateTime ?.unixMillisLong ?.div(1000)
|
||||
|
||||
init {
|
||||
checkPollInfo(question, options)
|
||||
closeInfo ?.checkSendData()
|
||||
@@ -307,9 +371,9 @@ data class SendQuizPoll internal constructor(
|
||||
throw IllegalArgumentException("Correct option id must be in range of $correctOptionIdRange, but actual " +
|
||||
"value is $correctOptionId")
|
||||
}
|
||||
if (explanation != null && explanation.length !in explanationLimit) {
|
||||
if (text != null && text.length !in explanationLimit) {
|
||||
error("Quiz poll explanation size must be in range $explanationLimit," +
|
||||
"but actual explanation contains ${explanation.length} symbols")
|
||||
"but actual explanation contains ${text.length} symbols")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package dev.inmo.tgbotapi.types
|
||||
|
||||
import dev.inmo.micro_utils.common.Warning
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
@@ -17,9 +18,20 @@ data class ChatId(
|
||||
val chatId: Identifier
|
||||
) : ChatIdentifier()
|
||||
|
||||
|
||||
val ChatId.link: String
|
||||
get() = "tg://user?id=$chatId"
|
||||
/**
|
||||
* https://core.telegram.org/bots/api#formatting-options
|
||||
*/
|
||||
@Warning("This API have restrictions in Telegram System")
|
||||
val Identifier.link: String
|
||||
get() = "tg://user?id=$this"
|
||||
/**
|
||||
* https://core.telegram.org/bots/api#formatting-options
|
||||
*/
|
||||
@Warning("This API have restrictions in Telegram System")
|
||||
val UserId.link: String
|
||||
get() = chatId.link
|
||||
val User.link: String
|
||||
get() = id.link
|
||||
|
||||
typealias UserId = ChatId
|
||||
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
package dev.inmo.tgbotapi.types
|
||||
|
||||
import com.soywiz.klock.DateTime
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
|
||||
@Serializable
|
||||
private data class RawChatInviteLink(
|
||||
@SerialName(inviteLinkField)
|
||||
val inviteLink: String,
|
||||
@SerialName(creatorField)
|
||||
val creator: User,
|
||||
@SerialName(isPrimaryField)
|
||||
val isPrimary: Boolean,
|
||||
@SerialName(isRevokedField)
|
||||
val isRevoked: Boolean,
|
||||
@SerialName(expireDateField)
|
||||
val expirationDateTime: TelegramDate? = null,
|
||||
@SerialName(memberLimitField)
|
||||
val membersLimit: MembersLimit ?= null
|
||||
)
|
||||
|
||||
private fun ChatInviteLink.toRawChatInviteLink() = RawChatInviteLink(
|
||||
inviteLink,
|
||||
creator,
|
||||
isPrimary,
|
||||
isRevoked,
|
||||
expirationDateTime ?.toTelegramDate(),
|
||||
membersLimit
|
||||
)
|
||||
|
||||
@Serializable(ChatInviteLinkSerializer::class)
|
||||
sealed class ChatInviteLink {
|
||||
abstract val inviteLink: String
|
||||
abstract val creator: User
|
||||
abstract val isPrimary: Boolean
|
||||
abstract val isRevoked: Boolean
|
||||
abstract val expirationDateTime: DateTime?
|
||||
abstract val membersLimit: MembersLimit?
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class PrimaryInviteLink(
|
||||
@SerialName(inviteLinkField)
|
||||
override val inviteLink: String,
|
||||
@SerialName(creatorField)
|
||||
override val creator: User,
|
||||
@SerialName(isRevokedField)
|
||||
override val isRevoked: Boolean = false,
|
||||
@SerialName(expireDateField)
|
||||
private val expireDate: TelegramDate? = null,
|
||||
@SerialName(memberLimitField)
|
||||
override val membersLimit: MembersLimit? = null
|
||||
) : ChatInviteLink() {
|
||||
override val isPrimary: Boolean
|
||||
get() = true
|
||||
override val expirationDateTime: DateTime?
|
||||
get() = expireDate ?.asDate
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class CommonInviteLink(
|
||||
@SerialName(inviteLinkField)
|
||||
override val inviteLink: String,
|
||||
@SerialName(creatorField)
|
||||
override val creator: User,
|
||||
@SerialName(isRevokedField)
|
||||
override val isRevoked: Boolean = false,
|
||||
@SerialName(expireDateField)
|
||||
private val expireDate: TelegramDate? = null,
|
||||
@SerialName(memberLimitField)
|
||||
override val membersLimit: MembersLimit? = null
|
||||
) : ChatInviteLink() {
|
||||
override val isPrimary: Boolean
|
||||
get() = false
|
||||
override val expirationDateTime: DateTime?
|
||||
get() = expireDate ?.asDate
|
||||
}
|
||||
|
||||
@Serializer(ChatInviteLink::class)
|
||||
object ChatInviteLinkSerializer : KSerializer<ChatInviteLink> {
|
||||
override val descriptor: SerialDescriptor
|
||||
get() = RawChatInviteLink.serializer().descriptor
|
||||
|
||||
override fun deserialize(decoder: Decoder): ChatInviteLink {
|
||||
val deserializedRaw = RawChatInviteLink.serializer().deserialize(decoder)
|
||||
return deserializedRaw.run {
|
||||
when {
|
||||
deserializedRaw.isPrimary -> PrimaryInviteLink(
|
||||
inviteLink, creator, isRevoked, expirationDateTime, membersLimit
|
||||
)
|
||||
else -> CommonInviteLink(
|
||||
inviteLink, creator, isRevoked, expirationDateTime, membersLimit
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, value: ChatInviteLink) {
|
||||
RawChatInviteLink.serializer().serialize(encoder, value.toRawChatInviteLink())
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,10 @@ data class AdministratorChatMemberImpl(
|
||||
override val canPinMessages: Boolean = false,
|
||||
@SerialName(canPromoteMembersField)
|
||||
override val canPromoteMembers: Boolean = false,
|
||||
@SerialName(canManageVoiceChatsField)
|
||||
override val canManageVoiceChats: Boolean = false,
|
||||
@SerialName(canManageChatField)
|
||||
override val canManageChat: Boolean = false,
|
||||
@SerialName(isAnonymousField)
|
||||
override val isAnonymous: Boolean = false,
|
||||
@SerialName(customTitleField)
|
||||
|
||||
@@ -30,6 +30,10 @@ data class CreatorChatMember(
|
||||
override val canPinMessages: Boolean = true
|
||||
@Transient
|
||||
override val canPromoteMembers: Boolean = true
|
||||
@Transient
|
||||
override val canManageVoiceChats: Boolean = true
|
||||
@Transient
|
||||
override val canManageChat: Boolean = true
|
||||
@SerialName(statusField)
|
||||
@Required
|
||||
private val type: String = "creator"
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package dev.inmo.tgbotapi.types.ChatMember.abstracts
|
||||
|
||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
@@ -13,12 +14,15 @@ interface AdministratorChatMember : SpecialRightsChatMember {
|
||||
val canRemoveMessages: Boolean
|
||||
val canRestrictMembers: Boolean
|
||||
val canPromoteMembers: Boolean
|
||||
val canManageVoiceChats: Boolean
|
||||
val canManageChat: Boolean
|
||||
val isAnonymous: Boolean
|
||||
val customTitle: String?
|
||||
}
|
||||
|
||||
@Serializer(AdministratorChatMember::class)
|
||||
internal object AdministratorChatMemberSerializer : KSerializer<AdministratorChatMember> {
|
||||
@RiskFeature
|
||||
object AdministratorChatMemberSerializer : KSerializer<AdministratorChatMember> {
|
||||
override val descriptor: SerialDescriptor = ChatMemberSerializer.descriptor
|
||||
|
||||
override fun deserialize(decoder: Decoder): AdministratorChatMember = ChatMemberSerializer.deserialize(decoder) as AdministratorChatMember
|
||||
|
||||
@@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.types.ChatMember.abstracts
|
||||
import dev.inmo.tgbotapi.types.ChatMember.*
|
||||
import dev.inmo.tgbotapi.types.User
|
||||
import dev.inmo.tgbotapi.types.statusField
|
||||
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||
import dev.inmo.tgbotapi.utils.nonstrictJsonFormat
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
@@ -17,7 +18,8 @@ interface ChatMember {
|
||||
}
|
||||
|
||||
@Serializer(ChatMember::class)
|
||||
internal object ChatMemberSerializer : KSerializer<ChatMember> {
|
||||
@RiskFeature
|
||||
object ChatMemberSerializer : KSerializer<ChatMember> {
|
||||
override val descriptor: SerialDescriptor = JsonObject.serializer().descriptor
|
||||
|
||||
override fun deserialize(decoder: Decoder): ChatMember {
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package dev.inmo.tgbotapi.types
|
||||
|
||||
import dev.inmo.tgbotapi.types.ChatMember.abstracts.ChatMember
|
||||
import dev.inmo.tgbotapi.types.chat.abstracts.Chat
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class ChatMemberUpdated(
|
||||
@SerialName(chatField)
|
||||
val chat: Chat,
|
||||
@SerialName(fromField)
|
||||
val user: User,
|
||||
@SerialName(dateField)
|
||||
val date: TelegramDate,
|
||||
@SerialName(oldChatMemberField)
|
||||
val oldChatMemberState: ChatMember,
|
||||
@SerialName(newChatMemberField)
|
||||
val newChatMemberState: ChatMember,
|
||||
@SerialName(inviteLinkField)
|
||||
val inviteLink: ChatInviteLink? = null
|
||||
)
|
||||
@@ -26,10 +26,12 @@ typealias FoursquareId = String
|
||||
typealias FoursquareType = String
|
||||
typealias GooglePlaceId = String
|
||||
typealias GooglePlaceType = String
|
||||
typealias MembersLimit = Int
|
||||
|
||||
typealias Seconds = Int
|
||||
typealias MilliSeconds = Long
|
||||
typealias LongSeconds = Long
|
||||
typealias UnixTimeStamp = LongSeconds
|
||||
|
||||
typealias Meters = Float
|
||||
typealias Degrees = Int
|
||||
@@ -76,6 +78,12 @@ val explanationLimit = 0 .. 200
|
||||
|
||||
val openPeriodPollSecondsLimit = 5 .. 600
|
||||
|
||||
val membersLimit = 1 .. 99999
|
||||
|
||||
val suggestedTipAmountsLimit = 1 .. 4
|
||||
|
||||
const val botActionActualityTime: Seconds = 5
|
||||
|
||||
// Made as lazy for correct work in K/JS
|
||||
val telegramInlineModeGifPermittedMimeTypes by lazy {
|
||||
listOf(
|
||||
@@ -162,6 +170,12 @@ const val optionIdsField = "option_ids"
|
||||
const val ipAddressField = "ip_address"
|
||||
const val linkedChatIdField = "linked_chat_id"
|
||||
const val horizontalAccuracyField = "horizontal_accuracy"
|
||||
const val revokeMessagesField = "revoke_messages"
|
||||
const val messageAutoDeleteTimeField = "message_auto_delete_time"
|
||||
const val isPrimaryField = "is_primary"
|
||||
const val isRevokedField = "is_revoked"
|
||||
const val expireDateField = "expire_date"
|
||||
const val memberLimitField = "member_limit"
|
||||
|
||||
const val requestContactField = "request_contact"
|
||||
const val requestLocationField = "request_location"
|
||||
@@ -239,8 +253,12 @@ const val canInviteUsersField = "can_invite_users"
|
||||
const val canRestrictMembersField = "can_restrict_members"
|
||||
const val canPinMessagesField = "can_pin_messages"
|
||||
const val canPromoteMembersField = "can_promote_members"
|
||||
const val canManageVoiceChatsField = "can_manage_voice_chats"
|
||||
const val canManageChatField = "can_manage_chat"
|
||||
const val pngStickerField = "png_sticker"
|
||||
const val tgsStickerField = "tgs_sticker"
|
||||
const val oldChatMemberField = "old_chat_member"
|
||||
const val newChatMemberField = "new_chat_member"
|
||||
|
||||
const val okField = "ok"
|
||||
const val captionField = "caption"
|
||||
@@ -292,12 +310,17 @@ const val payField = "pay"
|
||||
const val permissionsField = "permissions"
|
||||
const val typeField = "type"
|
||||
const val valueField = "value"
|
||||
const val creatorField = "creator"
|
||||
|
||||
const val pointField = "point"
|
||||
const val xShiftField = "x_shift"
|
||||
const val yShiftField = "y_shift"
|
||||
const val scaleField = "scale"
|
||||
|
||||
const val maxTipAmountField = "max_tip_amount"
|
||||
const val suggestedTipAmountsField = "suggested_tip_amounts"
|
||||
const val chatTypeField = "chat_type"
|
||||
|
||||
const val explanationEntitiesField = "explanation_entities"
|
||||
const val explanationParseModeField = "explanation_parse_mode"
|
||||
const val openPeriodField = "open_period"
|
||||
@@ -331,6 +354,8 @@ const val telegramPaymentChargeIdField = "telegram_payment_charge_id"
|
||||
const val providerPaymentChargeIdField = "provider_payment_charge_id"
|
||||
const val providerTokenField = "provider_token"
|
||||
const val providerDataField = "provider_data"
|
||||
const val usersField = "users"
|
||||
const val startDateField = "start_date"
|
||||
|
||||
const val requireNameField = "need_name"
|
||||
const val requirePhoneNumberField = "need_phone_number"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.makeString
|
||||
import dev.inmo.tgbotapi.requests.abstracts.FileId
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.audio.InlineQueryResultAudioCached
|
||||
@@ -48,7 +49,7 @@ data class InlineQueryResultAudioCachedImpl internal constructor(
|
||||
override val inputMessageContent: InputMessageContent? = null
|
||||
) : InlineQueryResultAudioCached {
|
||||
override val type: String = inlineQueryResultAudioType
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
|
||||
override val textSources: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextSources(text ?: return@lazy null)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.makeString
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.audio.InlineQueryResultAudio
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.audio.inlineQueryResultAudioType
|
||||
@@ -59,7 +60,7 @@ data class InlineQueryResultAudioImpl internal constructor(
|
||||
override val inputMessageContent: InputMessageContent? = null
|
||||
) : InlineQueryResultAudio {
|
||||
override val type: String = inlineQueryResultAudioType
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
|
||||
override val textSources: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextSources(text ?: return@lazy null)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.makeString
|
||||
import dev.inmo.tgbotapi.requests.abstracts.FileId
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.document.InlineQueryResultDocumentCached
|
||||
@@ -56,7 +57,7 @@ data class InlineQueryResultDocumentCachedImpl internal constructor(
|
||||
override val inputMessageContent: InputMessageContent? = null
|
||||
) : InlineQueryResultDocumentCached {
|
||||
override val type: String = inlineQueryResultDocumentType
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
|
||||
override val textSources: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextSources(text ?: return@lazy null)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.makeString
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.document.InlineQueryResultDocument
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.document.inlineQueryResultDocumentType
|
||||
@@ -73,7 +74,7 @@ data class InlineQueryResultDocumentImpl internal constructor(
|
||||
override val inputMessageContent: InputMessageContent? = null
|
||||
) : InlineQueryResultDocument {
|
||||
override val type: String = inlineQueryResultDocumentType
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
|
||||
override val textSources: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextSources(text ?: return@lazy null)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.makeString
|
||||
import dev.inmo.tgbotapi.requests.abstracts.FileId
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.gif.InlineQueryResultGifCached
|
||||
@@ -52,7 +53,7 @@ data class InlineQueryResultGifCachedImpl internal constructor(
|
||||
override val inputMessageContent: InputMessageContent? = null
|
||||
) : InlineQueryResultGifCached {
|
||||
override val type: String = inlineQueryResultGifType
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
|
||||
override val textSources: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextSources(text ?: return@lazy null)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.makeString
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.gif.InlineQueryResultGif
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.gif.inlineQueryResultGifType
|
||||
@@ -72,8 +73,8 @@ data class InlineQueryResultGifImpl internal constructor(
|
||||
override val inputMessageContent: InputMessageContent? = null
|
||||
) : InlineQueryResultGif {
|
||||
override val type: String = inlineQueryResultGifType
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
|
||||
override val textSources: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextSources(text ?: return@lazy null)
|
||||
}
|
||||
|
||||
init {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.makeString
|
||||
import dev.inmo.tgbotapi.requests.abstracts.FileId
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.mpeg4gif.InlineQueryResultMpeg4GifCached
|
||||
@@ -52,7 +53,7 @@ data class InlineQueryResultMpeg4GifCachedImpl internal constructor(
|
||||
override val inputMessageContent: InputMessageContent? = null
|
||||
) : InlineQueryResultMpeg4GifCached {
|
||||
override val type: String = inlineQueryResultMpeg4GifType
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
|
||||
override val textSources: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextSources(text ?: return@lazy null)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.makeString
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.mpeg4gif.InlineQueryResultMpeg4Gif
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.mpeg4gif.inlineQueryResultMpeg4GifType
|
||||
@@ -72,8 +73,8 @@ data class InlineQueryResultMpeg4GifImpl internal constructor(
|
||||
override val inputMessageContent: InputMessageContent? = null
|
||||
) : InlineQueryResultMpeg4Gif {
|
||||
override val type: String = inlineQueryResultMpeg4GifType
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
|
||||
override val textSources: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextSources(text ?: return@lazy null)
|
||||
}
|
||||
|
||||
init {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.makeString
|
||||
import dev.inmo.tgbotapi.requests.abstracts.FileId
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.photo.InlineQueryResultPhotoCached
|
||||
@@ -56,7 +57,7 @@ data class InlineQueryResultPhotoCachedImpl internal constructor(
|
||||
override val inputMessageContent: InputMessageContent? = null
|
||||
) : InlineQueryResultPhotoCached {
|
||||
override val type: String = inlineQueryResultPhotoType
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
|
||||
override val textSources: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextSources(text ?: return@lazy null)
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.makeString
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.photo.InlineQueryResultPhoto
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.photo.inlineQueryResultPhotoType
|
||||
@@ -67,7 +68,7 @@ data class InlineQueryResultPhotoImpl internal constructor(
|
||||
override val inputMessageContent: InputMessageContent? = null
|
||||
) : InlineQueryResultPhoto {
|
||||
override val type: String = inlineQueryResultPhotoType
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
|
||||
override val textSources: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextSources(text ?: return@lazy null)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.makeString
|
||||
import dev.inmo.tgbotapi.requests.abstracts.FileId
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.video.InlineQueryResultVideoCached
|
||||
@@ -56,7 +57,7 @@ data class InlineQueryResultVideoCachedImpl internal constructor(
|
||||
override val inputMessageContent: InputMessageContent? = null
|
||||
) : InlineQueryResultVideoCached {
|
||||
override val type: String = inlineQueryResultVideoType
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
|
||||
override val textSources: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextSources(text ?: return@lazy null)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.makeString
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.video.InlineQueryResultVideo
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.video.inlineQueryResultVideoType
|
||||
@@ -77,7 +78,7 @@ data class InlineQueryResultVideoImpl internal constructor(
|
||||
override val inputMessageContent: InputMessageContent? = null
|
||||
) : InlineQueryResultVideo {
|
||||
override val type: String = inlineQueryResultVideoType
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
|
||||
override val textSources: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextSources(text ?: return@lazy null)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.makeString
|
||||
import dev.inmo.tgbotapi.requests.abstracts.FileId
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.voice.InlineQueryResultVoiceCached
|
||||
@@ -52,7 +53,7 @@ data class InlineQueryResultVoiceCachedImpl internal constructor(
|
||||
override val inputMessageContent: InputMessageContent? = null
|
||||
) : InlineQueryResultVoiceCached {
|
||||
override val type: String = inlineQueryResultVoiceType
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
|
||||
override val textSources: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextSources(text ?: return@lazy null)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.makeString
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.voice.InlineQueryResultVoice
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.voice.inlineQueryResultVoiceType
|
||||
@@ -65,7 +66,7 @@ data class InlineQueryResultVoiceImpl internal constructor(
|
||||
override val inputMessageContent: InputMessageContent? = null
|
||||
) : InlineQueryResultVoice {
|
||||
override val type: String = inlineQueryResultVoiceType
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
|
||||
override val textSources: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextSources(text ?: return@lazy null)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package dev.inmo.tgbotapi.types.InlineQueries.InputMessageContent
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.CommonSendInvoiceData
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InputMessageContent
|
||||
import dev.inmo.tgbotapi.types.payments.LabeledPrice
|
||||
import dev.inmo.tgbotapi.types.payments.LabeledPricesSerializer
|
||||
import dev.inmo.tgbotapi.types.payments.abstracts.Currency
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
class InputInvoiceMessageContent(
|
||||
@SerialName(titleField)
|
||||
override val title: String,
|
||||
@SerialName(descriptionField)
|
||||
override val description: String,
|
||||
@SerialName(payloadField)
|
||||
override val payload: String,
|
||||
@SerialName(providerTokenField)
|
||||
override val providerToken: String,
|
||||
@SerialName(currencyField)
|
||||
override val currency: Currency,
|
||||
@Serializable(LabeledPricesSerializer::class)
|
||||
@SerialName(pricesField)
|
||||
override val prices: List<LabeledPrice>,
|
||||
@SerialName(maxTipAmountField)
|
||||
override val maxTipAmount: Int? = null,
|
||||
@SerialName(suggestedTipAmountsField)
|
||||
override val suggestedTipAmounts: List<Int>? = null,
|
||||
@SerialName(providerDataField)
|
||||
override val providerData: String? = null,
|
||||
@SerialName(requireNameField)
|
||||
override val requireName: Boolean = false,
|
||||
@SerialName(requirePhoneNumberField)
|
||||
override val requirePhoneNumber: Boolean = false,
|
||||
@SerialName(requireEmailField)
|
||||
override val requireEmail: Boolean = false,
|
||||
@SerialName(requireShippingAddressField)
|
||||
override val requireShippingAddress: Boolean = false,
|
||||
@SerialName(shouldSendPhoneNumberToProviderField)
|
||||
override val shouldSendPhoneNumberToProvider: Boolean = false,
|
||||
@SerialName(shouldSendEmailToProviderField)
|
||||
override val shouldSendEmailToProvider: Boolean = false,
|
||||
@SerialName(priceDependOnShipAddressField)
|
||||
override val priceDependOnShipAddress: Boolean = false
|
||||
) : InputMessageContent, CommonSendInvoiceData {
|
||||
@SerialName(photoUrlField)
|
||||
override var photoUrl: String? = null
|
||||
private set
|
||||
@SerialName(photoSizeField)
|
||||
override var photoSize: Long? = null
|
||||
private set
|
||||
|
||||
@SerialName(photoWidthField)
|
||||
override var photoWidth: Int? = null
|
||||
private set
|
||||
@SerialName(photoHeightField)
|
||||
override var photoHeight: Int? = null
|
||||
private set
|
||||
|
||||
override fun setPhoto(
|
||||
photoUrl: String,
|
||||
photoSize: Long?,
|
||||
photoWidth: Int?,
|
||||
photoHeight: Int?
|
||||
) {
|
||||
this.photoUrl = photoUrl
|
||||
this.photoSize = photoSize
|
||||
this.photoWidth = photoWidth
|
||||
this.photoHeight = photoHeight
|
||||
}
|
||||
|
||||
override fun unsetPhoto() {
|
||||
photoUrl = null
|
||||
photoSize = null
|
||||
photoWidth = null
|
||||
photoHeight = null
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,7 @@ data class InputTextMessageContent internal constructor(
|
||||
@SerialName(disableWebPagePreviewField)
|
||||
override val disableWebPagePreview: Boolean? = null
|
||||
) : TextedOutput, DisableWebPagePreview, InputMessageContent {
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text) ?.justTextSources()
|
||||
override val textSources: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextSources(text)
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ internal object InputMessageContentSerializer : KSerializer<InputMessageContent>
|
||||
is InputLocationMessageContent -> InputLocationMessageContent.serializer().serialize(encoder, value)
|
||||
is InputTextMessageContent -> InputTextMessageContent.serializer().serialize(encoder, value)
|
||||
is InputVenueMessageContent -> InputVenueMessageContent.serializer().serialize(encoder, value)
|
||||
is InputInvoiceMessageContent -> InputInvoiceMessageContent.serializer().serialize(encoder, value)
|
||||
else -> throw IllegalArgumentException("Unknown for serializing InputContactMessageContent")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,12 @@ package dev.inmo.tgbotapi.types.InlineQueries.abstracts
|
||||
|
||||
import dev.inmo.tgbotapi.types.InlineQueryIdentifier
|
||||
import dev.inmo.tgbotapi.types.User
|
||||
import dev.inmo.tgbotapi.types.chat.ChatType
|
||||
|
||||
interface InlineQuery {
|
||||
val id: InlineQueryIdentifier
|
||||
val from: User
|
||||
val query: String
|
||||
val offset: String
|
||||
val chatType: ChatType?
|
||||
}
|
||||
@@ -3,10 +3,12 @@ package dev.inmo.tgbotapi.types.InlineQueries.query
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InlineQuery
|
||||
import dev.inmo.tgbotapi.types.InlineQueryIdentifier
|
||||
import dev.inmo.tgbotapi.types.User
|
||||
import dev.inmo.tgbotapi.types.chat.ChatType
|
||||
|
||||
data class BaseInlineQuery(
|
||||
override val id: InlineQueryIdentifier,
|
||||
override val from: User,
|
||||
override val query: String,
|
||||
override val offset: String
|
||||
override val offset: String,
|
||||
override val chatType: ChatType?
|
||||
) : InlineQuery
|
||||
|
||||
@@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.types.InlineQueries.query
|
||||
import dev.inmo.tgbotapi.types.InlineQueries.abstracts.InlineQuery
|
||||
import dev.inmo.tgbotapi.types.InlineQueryIdentifier
|
||||
import dev.inmo.tgbotapi.types.User
|
||||
import dev.inmo.tgbotapi.types.chat.ChatType
|
||||
import dev.inmo.tgbotapi.types.location.Location
|
||||
|
||||
data class LocationInlineQuery(
|
||||
@@ -10,5 +11,6 @@ data class LocationInlineQuery(
|
||||
override val from: User,
|
||||
override val query: String,
|
||||
override val offset: String,
|
||||
override val chatType: ChatType?,
|
||||
val location: Location
|
||||
) : InlineQuery
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package dev.inmo.tgbotapi.types.InlineQueries.query
|
||||
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
import dev.inmo.tgbotapi.types.chat.ChatType
|
||||
import dev.inmo.tgbotapi.types.chat.ChatTypeSerializer
|
||||
import dev.inmo.tgbotapi.types.location.Location
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
@@ -15,12 +17,15 @@ internal data class RawInlineQuery(
|
||||
val query: String,
|
||||
@SerialName(offsetField)
|
||||
val offset: String,
|
||||
@SerialName(chatTypeField)
|
||||
@Serializable(ChatTypeSerializer::class)
|
||||
val chatType: ChatType? = null,
|
||||
@SerialName(locationField)
|
||||
val location: Location? = null
|
||||
) {
|
||||
val asInlineQuery by lazy {
|
||||
location ?.let {
|
||||
LocationInlineQuery(id, from, query, offset, location)
|
||||
} ?: BaseInlineQuery(id, from, query, offset)
|
||||
LocationInlineQuery(id, from, query, offset, chatType, location)
|
||||
} ?: BaseInlineQuery(id, from, query, offset, chatType)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,8 +44,8 @@ data class InputMediaAnimation internal constructor(
|
||||
override val thumb: InputFile? = null
|
||||
) : InputMedia, SizedInputMedia, DuratedInputMedia, ThumbedInputMedia, TextedOutput {
|
||||
override val type: String = "animation"
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
|
||||
override val textSources: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextSources(text ?: return@lazy null)
|
||||
}
|
||||
|
||||
@SerialName(mediaField)
|
||||
|
||||
@@ -50,8 +50,8 @@ data class InputMediaAudio internal constructor(
|
||||
override val thumb: InputFile? = null
|
||||
) : InputMedia, AudioMediaGroupMemberInputMedia, DuratedInputMedia, ThumbedInputMedia, TitledInputMedia, Performerable {
|
||||
override val type: String = audioInputMediaType
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
|
||||
override val textSources: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextSources(text ?: return@lazy null)
|
||||
}
|
||||
|
||||
override fun serialize(format: StringFormat): String = format.encodeToString(serializer(), this)
|
||||
@@ -62,15 +62,27 @@ data class InputMediaAudio internal constructor(
|
||||
}
|
||||
|
||||
fun AudioFile.toInputMediaAudio(
|
||||
caption: String? = null,
|
||||
text: String? = null,
|
||||
parseMode: ParseMode? = null,
|
||||
title: String? = this.title
|
||||
): InputMediaAudio = InputMediaAudio(
|
||||
fileId,
|
||||
caption,
|
||||
text,
|
||||
parseMode,
|
||||
duration,
|
||||
performer,
|
||||
title,
|
||||
thumb ?.fileId
|
||||
)
|
||||
|
||||
fun AudioFile.toInputMediaAudio(
|
||||
textSources: TextSourcesList = emptyList(),
|
||||
title: String? = this.title
|
||||
): InputMediaAudio = InputMediaAudio(
|
||||
fileId,
|
||||
textSources,
|
||||
duration,
|
||||
performer,
|
||||
title,
|
||||
thumb ?.fileId
|
||||
)
|
||||
|
||||
@@ -13,11 +13,11 @@ internal const val documentInputMediaType = "document"
|
||||
|
||||
fun InputMediaDocument(
|
||||
file: InputFile,
|
||||
caption: String? = null,
|
||||
text: String? = null,
|
||||
parseMode: ParseMode? = null,
|
||||
thumb: InputFile? = null,
|
||||
disableContentTypeDetection: Boolean? = null
|
||||
) = InputMediaDocument(file, caption, parseMode, null, thumb, disableContentTypeDetection)
|
||||
) = InputMediaDocument(file, text, parseMode, null, thumb, disableContentTypeDetection)
|
||||
|
||||
fun InputMediaDocument(
|
||||
file: InputFile,
|
||||
@@ -50,8 +50,8 @@ data class InputMediaDocument internal constructor(
|
||||
val disableContentTypeDetection: Boolean? = null
|
||||
) : InputMedia, DocumentMediaGroupMemberInputMedia, ThumbedInputMedia {
|
||||
override val type: String = documentInputMediaType
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
|
||||
override val textSources: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextSources(text ?: return@lazy null)
|
||||
}
|
||||
|
||||
override fun serialize(format: StringFormat): String = format.encodeToString(serializer(), this)
|
||||
@@ -62,11 +62,19 @@ data class InputMediaDocument internal constructor(
|
||||
}
|
||||
|
||||
fun DocumentFile.toInputMediaDocument(
|
||||
caption: String? = null,
|
||||
text: String? = null,
|
||||
parseMode: ParseMode? = null
|
||||
) = InputMediaDocument(
|
||||
fileId,
|
||||
caption,
|
||||
text,
|
||||
parseMode,
|
||||
thumb ?.fileId
|
||||
)
|
||||
|
||||
fun DocumentFile.toInputMediaDocument(
|
||||
textSources: TextSourcesList = emptyList()
|
||||
) = InputMediaDocument(
|
||||
fileId,
|
||||
textSources,
|
||||
thumb ?.fileId
|
||||
)
|
||||
|
||||
@@ -34,8 +34,8 @@ data class InputMediaPhoto internal constructor(
|
||||
private val rawEntities: List<RawMessageEntity>? = null
|
||||
) : InputMedia, VisualMediaGroupMemberInputMedia {
|
||||
override val type: String = photoInputMediaType
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
|
||||
override val textSources: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextSources(text ?: return@lazy null)
|
||||
}
|
||||
|
||||
override fun serialize(format: StringFormat): String = format.encodeToString(serializer(), this)
|
||||
@@ -46,10 +46,17 @@ data class InputMediaPhoto internal constructor(
|
||||
}
|
||||
|
||||
fun PhotoSize.toInputMediaPhoto(
|
||||
caption: String? = null,
|
||||
text: String? = null,
|
||||
parseMode: ParseMode? = null
|
||||
): InputMediaPhoto = InputMediaPhoto(
|
||||
fileId,
|
||||
caption,
|
||||
text,
|
||||
parseMode
|
||||
)
|
||||
|
||||
fun PhotoSize.toInputMediaPhoto(
|
||||
textSources: TextSourcesList = emptyList()
|
||||
): InputMediaPhoto = InputMediaPhoto(
|
||||
fileId,
|
||||
textSources
|
||||
)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.inmo.tgbotapi.types.InputMedia
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.makeString
|
||||
import dev.inmo.tgbotapi.requests.abstracts.InputFile
|
||||
import dev.inmo.tgbotapi.requests.abstracts.fileIdToSend
|
||||
import dev.inmo.tgbotapi.types.*
|
||||
@@ -45,8 +46,8 @@ data class InputMediaVideo internal constructor (
|
||||
override val thumb: InputFile? = null
|
||||
) : InputMedia, SizedInputMedia, DuratedInputMedia, ThumbedInputMedia, VisualMediaGroupMemberInputMedia {
|
||||
override val type: String = videoInputMediaType
|
||||
override val entities: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
|
||||
override val textSources: List<TextSource>? by lazy {
|
||||
rawEntities ?.asTextSources(text ?: return@lazy null)
|
||||
}
|
||||
|
||||
override fun serialize(format: StringFormat): String = format.encodeToString(serializer(), this)
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package dev.inmo.tgbotapi.types.MessageEntity
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.MultilevelTextSource
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
|
||||
import dev.inmo.tgbotapi.types.MessageEntity.textsources.*
|
||||
import dev.inmo.tgbotapi.types.User
|
||||
import dev.inmo.tgbotapi.utils.internal.fullListOfSubSource
|
||||
import dev.inmo.tgbotapi.utils.internal.shiftSourcesToTheLeft
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
@@ -15,70 +14,115 @@ internal data class RawMessageEntity(
|
||||
val url: String? = null,
|
||||
val user: User? = null,
|
||||
val language: String? = null
|
||||
)
|
||||
|
||||
internal fun RawMessageEntity.asTextParts(
|
||||
source: String,
|
||||
subParts: List<TextPart>
|
||||
): List<TextPart> {
|
||||
val sourceSubstring: String = source.substring(offset, offset + length)
|
||||
val range = offset until (offset + length)
|
||||
val shiftedSubSources = sourceSubstring.fullListOfSubSource(subParts.shiftSourcesToTheLeft(offset)).justTextSources()
|
||||
return when (type) {
|
||||
"mention" -> MentionTextSource(sourceSubstring, shiftedSubSources)
|
||||
"hashtag" -> HashTagTextSource(sourceSubstring, shiftedSubSources)
|
||||
"cashtag" -> CashTagTextSource(sourceSubstring, shiftedSubSources)
|
||||
"bot_command" -> BotCommandTextSource(sourceSubstring)
|
||||
"url" -> URLTextSource(sourceSubstring)
|
||||
"email" -> EMailTextSource(sourceSubstring, shiftedSubSources)
|
||||
"phone_number" -> PhoneNumberTextSource(sourceSubstring, shiftedSubSources)
|
||||
"bold" -> BoldTextSource(sourceSubstring, shiftedSubSources)
|
||||
"italic" -> ItalicTextSource(sourceSubstring, shiftedSubSources)
|
||||
"code" -> CodeTextSource(sourceSubstring)
|
||||
"pre" -> PreTextSource(sourceSubstring, language)
|
||||
"text_link" -> TextLinkTextSource(sourceSubstring, url ?: throw IllegalStateException("URL must not be null for text link"))
|
||||
"text_mention" -> TextMentionTextSource(sourceSubstring, user ?: throw IllegalStateException("User must not be null for text mention"), shiftedSubSources)
|
||||
"underline" -> UnderlineTextSource(sourceSubstring, shiftedSubSources)
|
||||
"strikethrough" -> StrikethroughTextSource(sourceSubstring, shiftedSubSources)
|
||||
else -> RegularTextSource(sourceSubstring)
|
||||
}.let {
|
||||
val part = TextPart(range, it)
|
||||
if (it !is MultilevelTextSource && subParts.isNotEmpty()) {
|
||||
(subParts + part).sortedBy { currentPart -> currentPart.range.first }
|
||||
} else {
|
||||
listOf(part)
|
||||
}
|
||||
) {
|
||||
internal val range by lazy {
|
||||
offset until (offset + length)
|
||||
}
|
||||
}
|
||||
|
||||
internal fun createTextPart(originalFullString: String, entities: RawMessageEntities): List<TextPart> {
|
||||
val mutableEntities = entities.toMutableList()
|
||||
mutableEntities.sortBy { it.offset }
|
||||
val resultList = mutableListOf<TextPart>()
|
||||
internal fun RawMessageEntity.asTextSource(
|
||||
source: String,
|
||||
subParts: List<TextSource>
|
||||
): TextSource {
|
||||
val sourceSubstring: String = source.substring(range)
|
||||
val subPartsWithRegulars by lazy {
|
||||
subParts.fillWithRegulars(sourceSubstring)
|
||||
}
|
||||
return when (type) {
|
||||
"mention" -> MentionTextSource(sourceSubstring, subPartsWithRegulars)
|
||||
"hashtag" -> HashTagTextSource(sourceSubstring, subPartsWithRegulars)
|
||||
"cashtag" -> CashTagTextSource(sourceSubstring, subPartsWithRegulars)
|
||||
"bot_command" -> BotCommandTextSource(sourceSubstring)
|
||||
"url" -> URLTextSource(sourceSubstring)
|
||||
"email" -> EMailTextSource(sourceSubstring, subPartsWithRegulars)
|
||||
"phone_number" -> PhoneNumberTextSource(sourceSubstring, subPartsWithRegulars)
|
||||
"bold" -> BoldTextSource(sourceSubstring, subPartsWithRegulars)
|
||||
"italic" -> ItalicTextSource(sourceSubstring, subPartsWithRegulars)
|
||||
"code" -> CodeTextSource(sourceSubstring)
|
||||
"pre" -> PreTextSource(sourceSubstring, language)
|
||||
"text_link" -> TextLinkTextSource(sourceSubstring, url ?: throw IllegalStateException("URL must not be null for text link"))
|
||||
"text_mention" -> TextMentionTextSource(sourceSubstring, user ?: throw IllegalStateException("User must not be null for text mention"), subPartsWithRegulars)
|
||||
"underline" -> UnderlineTextSource(sourceSubstring, subPartsWithRegulars)
|
||||
"strikethrough" -> StrikethroughTextSource(sourceSubstring, subPartsWithRegulars)
|
||||
else -> RegularTextSource(sourceSubstring)
|
||||
}
|
||||
}
|
||||
|
||||
private inline operator fun <T : Comparable<T>> ClosedRange<T>.contains(other: ClosedRange<T>): Boolean {
|
||||
return start <= other.start && endInclusive >= other.endInclusive
|
||||
}
|
||||
|
||||
internal fun List<TextSource>.fillWithRegulars(source: String): List<TextSource> {
|
||||
var index = 0
|
||||
val result = mutableListOf<TextSource>()
|
||||
for (i in 0 until size) {
|
||||
val textSource = get(i)
|
||||
val thisSourceInStart = source.startsWith(textSource.source, index)
|
||||
if (!thisSourceInStart) {
|
||||
val regularEndIndex = source.indexOf(textSource.source, index)
|
||||
result.add(regular(source.substring(index, regularEndIndex)))
|
||||
index = regularEndIndex
|
||||
}
|
||||
result.add(textSource)
|
||||
index += textSource.source.length
|
||||
}
|
||||
|
||||
if (index != source.length) {
|
||||
result.add(regular(source.substring(index, source.length)))
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
private fun createTextSources(originalFullString: String, entities: RawMessageEntities): List<TextSource> {
|
||||
val mutableEntities = entities.toMutableList().apply { sortBy { it.offset } }
|
||||
val resultList = mutableListOf<TextSource>()
|
||||
|
||||
while (mutableEntities.isNotEmpty()) {
|
||||
val currentFirst = mutableEntities.removeAt(0)
|
||||
val subEntities = if (mutableEntities.isNotEmpty()) {
|
||||
val lastIndex = currentFirst.offset + currentFirst.length
|
||||
val subEntities = mutableListOf<RawMessageEntity>()
|
||||
while (mutableEntities.isNotEmpty()) {
|
||||
val currentPossibleSubEntity = mutableEntities.first()
|
||||
if (currentPossibleSubEntity.offset < lastIndex) {
|
||||
subEntities.add(currentPossibleSubEntity)
|
||||
mutableEntities.removeAt(0)
|
||||
} else {
|
||||
break
|
||||
var parent = mutableEntities.removeFirst()
|
||||
val subentities = mutableListOf<RawMessageEntity>()
|
||||
val toAddCutted = mutableListOf<RawMessageEntity>()
|
||||
while (mutableEntities.isNotEmpty()) {
|
||||
val potentialParent = mutableEntities.first()
|
||||
when {
|
||||
potentialParent.range.first > parent.range.last -> break
|
||||
potentialParent.range in parent.range -> {
|
||||
subentities.add(potentialParent)
|
||||
}
|
||||
potentialParent.offset == parent.offset && potentialParent.length > parent.length -> {
|
||||
subentities.add(parent)
|
||||
parent = potentialParent
|
||||
}
|
||||
else -> { // need to cut
|
||||
toAddCutted.add(potentialParent)
|
||||
}
|
||||
}
|
||||
subEntities
|
||||
} else {
|
||||
emptyList<RawMessageEntity>()
|
||||
mutableEntities.remove(potentialParent)
|
||||
}
|
||||
|
||||
resultList.addAll(
|
||||
currentFirst.asTextParts(
|
||||
val subtextSources = if (subentities.isNotEmpty()) {
|
||||
mutableEntities.removeAll(subentities)
|
||||
if (toAddCutted.isNotEmpty()) {
|
||||
val borderIndex = parent.range.last + 1
|
||||
mutableEntities.addAll(
|
||||
0,
|
||||
toAddCutted.map {
|
||||
val firstLength = borderIndex - it.offset
|
||||
subentities.add(it.copy(length = firstLength))
|
||||
it.copy(
|
||||
offset = borderIndex,
|
||||
length = it.length - firstLength
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
createTextSources(originalFullString, subentities)
|
||||
} else {
|
||||
emptyList()
|
||||
}
|
||||
resultList.add(
|
||||
parent.asTextSource(
|
||||
originalFullString,
|
||||
createTextPart(originalFullString, subEntities)
|
||||
subtextSources
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -86,46 +130,41 @@ internal fun createTextPart(originalFullString: String, entities: RawMessageEnti
|
||||
return resultList
|
||||
}
|
||||
|
||||
internal fun TextPart.asRawMessageEntities(): List<RawMessageEntity> {
|
||||
internal fun TextSource.toRawMessageEntities(offset: Int = 0): List<RawMessageEntity> {
|
||||
val source = source
|
||||
val length = range.last - range.first + 1
|
||||
|
||||
val length = source.length
|
||||
return listOfNotNull(
|
||||
when (source) {
|
||||
is MentionTextSource -> RawMessageEntity("mention", range.first, length)
|
||||
is HashTagTextSource -> RawMessageEntity("hashtag", range.first, length)
|
||||
is CashTagTextSource -> RawMessageEntity("cashtag", range.first, length)
|
||||
is BotCommandTextSource -> RawMessageEntity("bot_command", range.first, length)
|
||||
is URLTextSource -> RawMessageEntity("url", range.first, length)
|
||||
is EMailTextSource -> RawMessageEntity("email", range.first, length)
|
||||
is PhoneNumberTextSource -> RawMessageEntity("phone_number", range.first, length)
|
||||
is BoldTextSource -> RawMessageEntity("bold", range.first, length)
|
||||
is ItalicTextSource -> RawMessageEntity("italic", range.first, length)
|
||||
is CodeTextSource -> RawMessageEntity("code", range.first, length)
|
||||
is PreTextSource -> RawMessageEntity("pre", range.first, length, language = source.language)
|
||||
is TextLinkTextSource -> RawMessageEntity("text_link", range.first, length, source.url)
|
||||
is TextMentionTextSource -> RawMessageEntity("text_mention", range.first, length, user = source.user)
|
||||
is UnderlineTextSource -> RawMessageEntity("underline", range.first, length)
|
||||
is StrikethroughTextSource -> RawMessageEntity("strikethrough", range.first, length)
|
||||
when (this) {
|
||||
is MentionTextSource -> RawMessageEntity("mention", offset, length)
|
||||
is HashTagTextSource -> RawMessageEntity("hashtag", offset, length)
|
||||
is CashTagTextSource -> RawMessageEntity("cashtag", offset, length)
|
||||
is BotCommandTextSource -> RawMessageEntity("bot_command", offset, length)
|
||||
is URLTextSource -> RawMessageEntity("url", offset, length)
|
||||
is EMailTextSource -> RawMessageEntity("email", offset, length)
|
||||
is PhoneNumberTextSource -> RawMessageEntity("phone_number", offset, length)
|
||||
is BoldTextSource -> RawMessageEntity("bold", offset, length)
|
||||
is ItalicTextSource -> RawMessageEntity("italic", offset, length)
|
||||
is CodeTextSource -> RawMessageEntity("code", offset, length)
|
||||
is PreTextSource -> RawMessageEntity("pre", offset, length, language = language)
|
||||
is TextLinkTextSource -> RawMessageEntity("text_link", offset, length, url)
|
||||
is TextMentionTextSource -> RawMessageEntity("text_mention", offset, length, user = user)
|
||||
is UnderlineTextSource -> RawMessageEntity("underline", offset, length)
|
||||
is StrikethroughTextSource -> RawMessageEntity("strikethrough", offset, length)
|
||||
else -> null
|
||||
}
|
||||
) + if (source is MultilevelTextSource) {
|
||||
source.textParts(range.first).asRawMessageEntities()
|
||||
) + if (this is MultilevelTextSource) {
|
||||
subsources.toRawMessageEntities(offset)
|
||||
} else {
|
||||
emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
internal fun List<TextPart>.asRawMessageEntities(): List<RawMessageEntity> = flatMap { it.asRawMessageEntities() }
|
||||
|
||||
internal fun List<TextSource>.toTextParts(preOffset: Int = 0): List<TextPart> {
|
||||
internal fun List<TextSource>.toRawMessageEntities(preOffset: Int = 0): List<RawMessageEntity> {
|
||||
var i = preOffset
|
||||
return map {
|
||||
TextPart(
|
||||
i until (i + it.source.length),
|
||||
it
|
||||
).also {
|
||||
i = it.range.last + 1
|
||||
return flatMap { textSource ->
|
||||
textSource.toRawMessageEntities(i).also {
|
||||
i += it.maxByOrNull { it.length } ?.length ?: textSource.source.length
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -136,10 +175,8 @@ fun String.removeLeading(word: String) = if (startsWith(word)){
|
||||
this
|
||||
}
|
||||
|
||||
internal fun List<TextSource>.toRawMessageEntities(): List<RawMessageEntity> = toTextParts().asRawMessageEntities()
|
||||
internal fun List<TextSource>.toRawMessageEntities(): List<RawMessageEntity> = toRawMessageEntities(0)
|
||||
|
||||
internal fun RawMessageEntities.asTextParts(sourceString: String): List<TextPart> = sourceString.fullListOfSubSource(
|
||||
createTextPart(sourceString, this)
|
||||
)
|
||||
internal fun RawMessageEntities.asTextSources(sourceString: String): List<TextSource> = createTextSources(sourceString, this).fillWithRegulars(sourceString)
|
||||
|
||||
internal typealias RawMessageEntities = List<RawMessageEntity>
|
||||
|
||||
@@ -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 bold
|
||||
*/
|
||||
@Serializable
|
||||
data class BoldTextSource @RiskFeature(DirectInvocationOfTextSourceConstructor) constructor (
|
||||
override val source: String,
|
||||
override val subsources: List<TextSource>
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<TextSource>
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<TextSource>
|
||||
|
||||
@@ -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<TextSource>
|
||||
|
||||
@@ -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<TextSource>
|
||||
|
||||
@@ -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<TextSource>
|
||||
|
||||
@@ -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<TextSource>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<TextSource>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
package dev.inmo.tgbotapi.types.MessageEntity.textsources
|
||||
|
||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||
import dev.inmo.tgbotapi.types.User
|
||||
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,
|
||||
@@ -21,6 +23,26 @@ data class TextMentionTextSource @RiskFeature(DirectInvocationOfTextSourceConstr
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun mention(parts: List<TextSource>, user: User) = TextMentionTextSource(parts.makeString(), user, parts)
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun User.mention(parts: List<TextSource>) = mention(parts, this)
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun mention(parts: List<TextSource>, userId: UserId) = mention(parts, CommonUser(userId, ""))
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun UserId.mention(parts: List<TextSource>) = mention(parts, this)
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun mention(parts: List<TextSource>, id: Identifier) = mention(parts, UserId(id))
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun Identifier.mention(parts: List<TextSource>) = mention(parts, this)
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun mention(user: User, vararg parts: TextSource) = mention(parts.toList(), user)
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun mention(text: String, user: User) = mention(user, regular(text))
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun User.mention(text: String) = mention(this, regular(text))
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun mention(text: String, userId: UserId) = mention(text, CommonUser(userId, ""))
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun UserId.mention(text: String) = mention(text, this)
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun mention(text: String, id: Identifier) = mention(text, UserId(id))
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun Identifier.mention(text: String) = mention(text, this)
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
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.types.MessageEntity.RawMessageEntity
|
||||
import dev.inmo.tgbotapi.types.MessageEntity.asTextSources
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.Serializer
|
||||
import kotlinx.serialization.builtins.ListSerializer
|
||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
|
||||
private val baseSerializers: Map<String, KSerializer<out TextSource>> = 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(),
|
||||
)
|
||||
|
||||
object TextSourceSerializer : TypedSerializer<TextSource>(TextSource::class, baseSerializers) {
|
||||
override fun <T: TextSource> include(type: String, serializer: KSerializer<T>) {
|
||||
require(type !in baseSerializers.keys)
|
||||
super.include(type, serializer)
|
||||
}
|
||||
|
||||
override fun exclude(type: String) {
|
||||
require(type !in baseSerializers.keys)
|
||||
super.exclude(type)
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<TextSource>
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user