mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-11-17 12:30:20 +00:00
Compare commits
130 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 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 | |||
| dc83b8d77a | |||
| 2aac6c0bde | |||
| b637d0d2a6 |
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
|
|
||||||
149
CHANGELOG.md
149
CHANGELOG.md
@@ -1,5 +1,154 @@
|
|||||||
# TelegramBotAPI changelog
|
# TelegramBotAPI changelog
|
||||||
|
|
||||||
|
## 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`:
|
||||||
|
* Fix of [#275](https://github.com/InsanusMokrassar/TelegramBotAPI/issues/275)
|
||||||
|
|
||||||
## 0.32.1
|
## 0.32.1
|
||||||
|
|
||||||
* `Core`:
|
* `Core`:
|
||||||
|
|||||||
223
README.md
223
README.md
@@ -1,153 +1,118 @@
|
|||||||
|
[Participate in our common survey ☺](https://forms.gle/q6Xf8K3fD1pPsYUw9)
|
||||||
|
|
||||||
# TelegramBotAPI
|
# TelegramBotAPI
|
||||||
|
|
||||||
<details>
|
Hello! This is a set of libraries for working with Telegram Bot API.
|
||||||
<summary><b>I do not wanna read a lot, just give me my bot</b></summary>
|
|
||||||
|
|
||||||
You can simply use <a href="https://github.com/InsanusMokrassar/TelegramBotAPI-bot_template">this template</a> (and button
|
| Common info | [](https://github.com/KotlinBy/awesome-kotlin) [](https://github.com/InsanusMokrassar/TelegramBotAPI/actions) [Small survey](https://forms.gle/2Hex2ynbHWHhi1KY7)|
|
||||||
<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)|
|
|
||||||
| -------------------------------------:|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
| -------------------------------------:|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||||
| 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) |
|
| 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 Core status | [](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 API Extensions status | [](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 Util Extensions status | [](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 Behaviour Builder Extensions status | [](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 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
|
## Examples
|
||||||
[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`**
|
|
||||||
|
|
||||||
## 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
|
* Add `mavenCentral()` to your project repositories
|
||||||
the list of this complex currently next projects:
|
* [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
|
More including instructions [available here](https://github.com/InsanusMokrassar/TelegramBotAPI/wiki/Including-in-your-project).
|
||||||
without any additional library
|
Other configuration examples:
|
||||||
* [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
|
|
||||||
|
|
||||||
Most part of some specific solves or unuseful
|
* [For multiplatform](https://github.com/InsanusMokrassar/TelegramBotAPI-examples/tree/master/ResenderBot)
|
||||||
moments are describing by official [Telegram Bot API](https://core.telegram.org/bots/api).
|
* [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)):
|
bot.buildBehaviour {
|
||||||
|
println(getMe())
|
||||||
<details>
|
|
||||||
<summary>Gradle build script help (for versions before 0.28.0)</summary>
|
onCommand("start") {
|
||||||
|
reply(it, "Hi:)")
|
||||||
```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")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}.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
|
val flowsUpdatesFilter = FlowsUpdatesFilter()
|
||||||
all necessary tools for comfort usage of this library. If you want to exclude some libraries, you can implement just
|
bot.buildBehaviour(flowUpdatesFilter = flowsUpdatesFilter) {
|
||||||
[TelegramBotAPI BehaviourBuilder Extensions](tgbotapi.extensions.behaviour_builder/README.md),
|
println(getMe())
|
||||||
[TelegramBotAPI API Extensions](tgbotapi.extensions.api/README.md),
|
|
||||||
[TelegramBotAPI Util Extensions](tgbotapi.extensions.utils/README.md) or even
|
onCommand("start") {
|
||||||
[TelegramBotAPI Core](tgbotapi.core/README.md).
|
reply(it, "Hi:)")
|
||||||
|
}
|
||||||
|
|
||||||
If you want to dive deeper in the core of library or develop something for it - welcome to learn more from
|
retrieveAccumulatedUpdates(this).join()
|
||||||
[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()
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
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).
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ kotlin {
|
|||||||
dependencies {
|
dependencies {
|
||||||
implementation kotlin('stdlib')
|
implementation kotlin('stdlib')
|
||||||
|
|
||||||
project.parent.subprojects.forEach {
|
rootProject.subprojects.forEach {
|
||||||
if (it != project) {
|
if (it != project) {
|
||||||
api it
|
api it
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,7 @@ private List<SourceDirectorySet> findSourcesWithName(String... approximateNames)
|
|||||||
}.collect { it.kotlin }
|
}.collect { it.kotlin }
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.dokkaHtml {
|
Object callback = {
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case project.hasProperty("DOKKA_PATH"):
|
case project.hasProperty("DOKKA_PATH"):
|
||||||
outputDirectory = project.property("DOKKA_PATH").toString()
|
outputDirectory = project.property("DOKKA_PATH").toString()
|
||||||
@@ -82,11 +82,14 @@ tasks.dokkaHtml {
|
|||||||
}
|
}
|
||||||
|
|
||||||
named("jsMain") {
|
named("jsMain") {
|
||||||
sourceRoots.setFrom(findSourcesWithName("jsMain", "commonMain"))
|
sourceRoots.setFrom(findSourcesWithName("jsMain"))
|
||||||
}
|
}
|
||||||
|
|
||||||
named("jvmMain") {
|
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.30
|
||||||
|
|
||||||
org.gradle.jvmargs=-Xmx1024m
|
org.gradle.jvmargs=-Xmx1024m
|
||||||
|
|||||||
@@ -5,18 +5,18 @@ kotlin.js.generate.externals=true
|
|||||||
kotlin.incremental=true
|
kotlin.incremental=true
|
||||||
kotlin.incremental.js=true
|
kotlin.incremental.js=true
|
||||||
|
|
||||||
kotlin_version=1.4.21
|
kotlin_version=1.4.32
|
||||||
kotlin_coroutines_version=1.4.2
|
kotlin_coroutines_version=1.4.3
|
||||||
kotlin_serialisation_runtime_version=1.0.1
|
kotlin_serialisation_runtime_version=1.1.0
|
||||||
klock_version=2.0.4
|
klock_version=2.0.7
|
||||||
uuid_version=0.2.3
|
uuid_version=0.2.3
|
||||||
ktor_version=1.5.1
|
ktor_version=1.5.3
|
||||||
|
|
||||||
micro_utils_version=0.4.23
|
micro_utils_version=0.4.33
|
||||||
|
|
||||||
javax_activation_version=1.1.1
|
javax_activation_version=1.1.1
|
||||||
|
|
||||||
library_group=dev.inmo
|
library_group=dev.inmo
|
||||||
library_version=0.32.1
|
library_version=0.33.3
|
||||||
|
|
||||||
github_release_plugin_version=2.2.12
|
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
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.1-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
|
||||||
|
|||||||
@@ -1,4 +1,11 @@
|
|||||||
pluginManagement {
|
pluginManagement {
|
||||||
|
resolutionStrategy {
|
||||||
|
eachPlugin {
|
||||||
|
if (requested.id.id == "org.jetbrains.dokka") {
|
||||||
|
useModule("org.jetbrains.dokka:dokka-gradle-plugin:${requested.version}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
repositories {
|
repositories {
|
||||||
gradlePluginPortal()
|
gradlePluginPortal()
|
||||||
jcenter()
|
jcenter()
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ moments are describing by official [Telegram Bot API](https://core.telegram.org/
|
|||||||
|
|
||||||
## Compatibility
|
## Compatibility
|
||||||
|
|
||||||
This version compatible with [4th of November 2020 update of TelegramBotAPI (version 5.0)](https://core.telegram.org/bots/api#november-4-2020).
|
This version compatible with [9th of March 2021 update of TelegramBotAPI (version 5.1)](https://core.telegram.org/bots/api-changelog#march-9-2021).
|
||||||
|
|
||||||
## How to implement library?
|
## How to implement library?
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,9 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
kotlin {
|
kotlin {
|
||||||
jvm()
|
jvm {
|
||||||
|
compilations.main.kotlinOptions.useIR = true
|
||||||
|
}
|
||||||
js(BOTH) {
|
js(BOTH) {
|
||||||
browser()
|
browser()
|
||||||
nodejs()
|
nodejs()
|
||||||
@@ -58,6 +60,7 @@ kotlin {
|
|||||||
dependencies {
|
dependencies {
|
||||||
implementation kotlin('test-common')
|
implementation kotlin('test-common')
|
||||||
implementation kotlin('test-annotations-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) {
|
task javadocsJar(type: Jar) {
|
||||||
classifier = 'javadoc'
|
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 {
|
publishing {
|
||||||
publications.all {
|
publications.all {
|
||||||
@@ -54,22 +38,32 @@ publishing {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
maven {
|
if ((project.hasProperty('GITHUBPACKAGES_USER') || System.getenv('GITHUBPACKAGES_USER') != null) && (project.hasProperty('GITHUBPACKAGES_PASSWORD') || System.getenv('GITHUBPACKAGES_PASSWORD') != null)) {
|
||||||
name = "bintray"
|
maven {
|
||||||
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")
|
name = "GithubPackages"
|
||||||
credentials {
|
url = uri("https://maven.pkg.github.com/InsanusMokrassar/TelegramBotAPI")
|
||||||
username = project.hasProperty('BINTRAY_USER') ? project.property('BINTRAY_USER') : System.getenv('BINTRAY_USER')
|
credentials {
|
||||||
password = project.hasProperty('BINTRAY_KEY') ? project.property('BINTRAY_KEY') : System.getenv('BINTRAY_KEY')
|
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 {
|
signing {
|
||||||
useGpgCmd()
|
useGpgCmd()
|
||||||
publishing.publications.forEach { sign it }
|
sign publishing.publications
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ interface Captioned {
|
|||||||
val caption: String?
|
val caption: String?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated("This interface is not used in library and will be removed soon")
|
||||||
interface CaptionedOutput : Captioned {
|
interface CaptionedOutput : Captioned {
|
||||||
val parseMode: ParseMode?
|
val parseMode: ParseMode?
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ import io.ktor.http.ContentType
|
|||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import kotlin.collections.set
|
import kotlin.collections.set
|
||||||
|
|
||||||
|
var defaultUpdateTimeoutForZeroDelay = 1000L
|
||||||
|
|
||||||
abstract class AbstractRequestCallFactory : KtorCallFactory {
|
abstract class AbstractRequestCallFactory : KtorCallFactory {
|
||||||
private val methodsCache: MutableMap<String, String> = mutableMapOf()
|
private val methodsCache: MutableMap<String, String> = mutableMapOf()
|
||||||
override suspend fun <T : Any> makeCall(
|
override suspend fun <T : Any> makeCall(
|
||||||
@@ -41,6 +43,11 @@ abstract class AbstractRequestCallFactory : KtorCallFactory {
|
|||||||
requestTimeoutMillis = customTimeoutMillis
|
requestTimeoutMillis = customTimeoutMillis
|
||||||
socketTimeoutMillis = customTimeoutMillis
|
socketTimeoutMillis = customTimeoutMillis
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
timeout {
|
||||||
|
requestTimeoutMillis = defaultUpdateTimeoutForZeroDelay
|
||||||
|
socketTimeoutMillis = defaultUpdateTimeoutForZeroDelay
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ fun newRequestException(
|
|||||||
cause: Throwable? = null
|
cause: Throwable? = null
|
||||||
) = response.description ?.let { description ->
|
) = response.description ?.let { description ->
|
||||||
when {
|
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 == "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.contains("Bad Request: message is not modified") -> MessageIsNotModifiedException(response, plainAnswer, message, cause)
|
||||||
description == "Unauthorized" -> UnauthorizedException(response, plainAnswer, message, cause)
|
description == "Unauthorized" -> UnauthorizedException(response, plainAnswer, message, cause)
|
||||||
|
|||||||
@@ -17,7 +17,9 @@ class CommonLimiter(
|
|||||||
@Transient
|
@Transient
|
||||||
private val scope: CoroutineScope = CoroutineScope(Dispatchers.Default)
|
private val scope: CoroutineScope = CoroutineScope(Dispatchers.Default)
|
||||||
) : RequestLimiter {
|
) : RequestLimiter {
|
||||||
|
@Transient
|
||||||
private val quotaSemaphore = Semaphore(lockCount)
|
private val quotaSemaphore = Semaphore(lockCount)
|
||||||
|
@Transient
|
||||||
private val counterRegeneratorJob = scope.launch {
|
private val counterRegeneratorJob = scope.launch {
|
||||||
val regenDelay: MilliSeconds = (regenTime.toDouble() / lockCount).roundToLong()
|
val regenDelay: MilliSeconds = (regenTime.toDouble() / lockCount).roundToLong()
|
||||||
while (isActive) {
|
while (isActive) {
|
||||||
|
|||||||
@@ -37,11 +37,12 @@ class ExceptionsOnlyLimiter(
|
|||||||
override suspend fun <T> limit(block: suspend () -> T): T {
|
override suspend fun <T> limit(block: suspend () -> T): T {
|
||||||
while (true) {
|
while (true) {
|
||||||
lockState.first { !it }
|
lockState.first { !it }
|
||||||
|
var throwable: Throwable? = null
|
||||||
val result = safely({
|
val result = safely({
|
||||||
when (it) {
|
throwable = when (it) {
|
||||||
is TooMuchRequestsException -> {
|
is TooMuchRequestsException -> {
|
||||||
lock(it.retryAfter.leftToRetry)
|
lock(it.retryAfter.leftToRetry)
|
||||||
Result.failure(it)
|
it
|
||||||
}
|
}
|
||||||
is ClientRequestException -> {
|
is ClientRequestException -> {
|
||||||
if (it.response.status == HttpStatusCode.TooManyRequests) {
|
if (it.response.status == HttpStatusCode.TooManyRequests) {
|
||||||
@@ -49,15 +50,16 @@ class ExceptionsOnlyLimiter(
|
|||||||
} else {
|
} else {
|
||||||
throw it
|
throw it
|
||||||
}
|
}
|
||||||
Result.failure(it)
|
it
|
||||||
}
|
}
|
||||||
else -> throw it
|
else -> throw it
|
||||||
}
|
}
|
||||||
|
null
|
||||||
}) {
|
}) {
|
||||||
Result.success(block())
|
block()
|
||||||
}
|
}
|
||||||
if (result.isSuccess) {
|
if (throwable == null) {
|
||||||
return result.getOrNull()!!
|
return result!!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package dev.inmo.tgbotapi.requests
|
package dev.inmo.tgbotapi.requests
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
|
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
|
||||||
import dev.inmo.tgbotapi.types.*
|
import dev.inmo.tgbotapi.types.*
|
||||||
import dev.inmo.tgbotapi.types.passport.PassportElementError
|
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)
|
@SerialName(userIdField)
|
||||||
override val userId: UserId,
|
override val userId: UserId,
|
||||||
@SerialName(untilDateField)
|
@SerialName(untilDateField)
|
||||||
override val untilDate: TelegramDate? = null
|
override val untilDate: TelegramDate? = null,
|
||||||
|
@SerialName(revokeMessagesField)
|
||||||
|
val revokeMessages: Boolean? = null
|
||||||
) : ChatMemberRequest<Boolean>, UntilDate {
|
) : ChatMemberRequest<Boolean>, UntilDate {
|
||||||
override fun method(): String = "kickChatMember"
|
override fun method(): String = "kickChatMember"
|
||||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||||
|
|||||||
@@ -31,7 +31,11 @@ data class PromoteChatMember(
|
|||||||
@SerialName(canPinMessagesField)
|
@SerialName(canPinMessagesField)
|
||||||
private val canPinMessages: Boolean? = null,
|
private val canPinMessages: Boolean? = null,
|
||||||
@SerialName(canPromoteMembersField)
|
@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 {
|
) : ChatMemberRequest<Boolean>, UntilDate {
|
||||||
override fun method(): String = "promoteChatMember"
|
override fun method(): String = "promoteChatMember"
|
||||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ data class SetChatPhoto (
|
|||||||
override fun method(): String = "setChatPhoto"
|
override fun method(): String = "setChatPhoto"
|
||||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||||
get() = Boolean.serializer()
|
get() = Boolean.serializer()
|
||||||
|
@Transient
|
||||||
override val mediaMap: Map<String, MultipartFile> = mapOf(photoField to photo)
|
override val mediaMap: Map<String, MultipartFile> = mapOf(photoField to photo)
|
||||||
|
@Transient
|
||||||
override val paramsJson: JsonObject = toJson(serializer())
|
override val paramsJson: JsonObject = toJson(serializer())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import dev.inmo.tgbotapi.utils.throwRangeError
|
|||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
|
|
||||||
private val commonResultDeserializer = TelegramBotAPIMessageDeserializationStrategyClass<ContentMessage<LocationContent>>()
|
private val commonResultDeserializer = TelegramBotAPIMessageDeserializationStrategyClass<ContentMessage<LocationContent>>()
|
||||||
|
const val editMessageLiveLocationMethod = "editMessageLiveLocation"
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class EditChatMessageLiveLocation(
|
data class EditChatMessageLiveLocation(
|
||||||
@@ -30,7 +31,7 @@ data class EditChatMessageLiveLocation(
|
|||||||
@SerialName(replyMarkupField)
|
@SerialName(replyMarkupField)
|
||||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||||
) : EditChatMessage<LocationContent>, EditReplyMessage, EditLocationMessage {
|
) : EditChatMessage<LocationContent>, EditReplyMessage, EditLocationMessage {
|
||||||
override fun method(): String = "editMessageLiveLocation"
|
override fun method(): String = editMessageLiveLocationMethod
|
||||||
override val resultDeserializer: DeserializationStrategy<ContentMessage<LocationContent>>
|
override val resultDeserializer: DeserializationStrategy<ContentMessage<LocationContent>>
|
||||||
get() = commonResultDeserializer
|
get() = commonResultDeserializer
|
||||||
override val requestSerializer: SerializationStrategy<*>
|
override val requestSerializer: SerializationStrategy<*>
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ data class EditInlineMessageLiveLocation(
|
|||||||
@SerialName(replyMarkupField)
|
@SerialName(replyMarkupField)
|
||||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||||
) : EditInlineMessage, EditReplyMessage, EditLocationMessage {
|
) : EditInlineMessage, EditReplyMessage, EditLocationMessage {
|
||||||
override fun method(): String = "editMessageLiveLocation"
|
override fun method(): String = editMessageLiveLocationMethod
|
||||||
override val requestSerializer: SerializationStrategy<*>
|
override val requestSerializer: SerializationStrategy<*>
|
||||||
get() = serializer()
|
get() = serializer()
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import dev.inmo.tgbotapi.types.message.content.LocationContent
|
|||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
|
|
||||||
private val commonResultDeserializer = TelegramBotAPIMessageDeserializationStrategyClass<ContentMessage<LocationContent>>()
|
private val commonResultDeserializer = TelegramBotAPIMessageDeserializationStrategyClass<ContentMessage<LocationContent>>()
|
||||||
|
const val stopMessageLiveLocationMethod = "stopMessageLiveLocation"
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class StopChatMessageLiveLocation(
|
data class StopChatMessageLiveLocation(
|
||||||
@@ -20,7 +21,7 @@ data class StopChatMessageLiveLocation(
|
|||||||
@SerialName(replyMarkupField)
|
@SerialName(replyMarkupField)
|
||||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||||
) : EditChatMessage<LocationContent>, EditReplyMessage {
|
) : EditChatMessage<LocationContent>, EditReplyMessage {
|
||||||
override fun method(): String = "stopMessageLiveLocation"
|
override fun method(): String = stopMessageLiveLocationMethod
|
||||||
override val resultDeserializer: DeserializationStrategy<ContentMessage<LocationContent>>
|
override val resultDeserializer: DeserializationStrategy<ContentMessage<LocationContent>>
|
||||||
get() = commonResultDeserializer
|
get() = commonResultDeserializer
|
||||||
override val requestSerializer: SerializationStrategy<*>
|
override val requestSerializer: SerializationStrategy<*>
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ data class StopInlineMessageLiveLocation(
|
|||||||
@SerialName(replyMarkupField)
|
@SerialName(replyMarkupField)
|
||||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||||
) : EditInlineMessage, EditReplyMessage {
|
) : EditInlineMessage, EditReplyMessage {
|
||||||
override fun method(): String = "stopMessageLiveLocation"
|
override fun method(): String = stopMessageLiveLocationMethod
|
||||||
override val requestSerializer: SerializationStrategy<*>
|
override val requestSerializer: SerializationStrategy<*>
|
||||||
get() = serializer()
|
get() = serializer()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package dev.inmo.tgbotapi.requests.edit.text
|
|||||||
|
|
||||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||||
import dev.inmo.tgbotapi.requests.edit.abstracts.*
|
import dev.inmo.tgbotapi.requests.edit.abstracts.*
|
||||||
import dev.inmo.tgbotapi.requests.edit.media.editMessageMediaMethod
|
|
||||||
import dev.inmo.tgbotapi.types.*
|
import dev.inmo.tgbotapi.types.*
|
||||||
import dev.inmo.tgbotapi.types.MessageEntity.*
|
import dev.inmo.tgbotapi.types.MessageEntity.*
|
||||||
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
|
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
|
||||||
@@ -55,10 +54,10 @@ data class EditInlineMessageText internal constructor(
|
|||||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||||
) : EditInlineMessage, EditTextChatMessage, EditReplyMessage, EditDisableWebPagePreviewMessage {
|
) : EditInlineMessage, EditTextChatMessage, EditReplyMessage, EditDisableWebPagePreviewMessage {
|
||||||
override val entities: List<TextSource>? by lazy {
|
override val entities: List<TextSource>? by lazy {
|
||||||
rawEntities ?.asTextParts(text ?: return@lazy null) ?.justTextSources()
|
rawEntities ?.asTextParts(text) ?.justTextSources()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun method(): String = editMessageMediaMethod
|
override fun method(): String = editMessageTextMethod
|
||||||
override val requestSerializer: SerializationStrategy<*>
|
override val requestSerializer: SerializationStrategy<*>
|
||||||
get() = serializer()
|
get() = serializer()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,11 @@ import kotlinx.serialization.*
|
|||||||
|
|
||||||
private val commonResultDeserializer: DeserializationStrategy<ContentMessage<PollContent>> = TelegramBotAPIMessageDeserializationStrategyClass()
|
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(
|
private fun checkPollInfo(
|
||||||
question: String,
|
question: String,
|
||||||
options: List<String>
|
options: List<String>
|
||||||
@@ -138,12 +143,23 @@ sealed class SendPoll : SendMessageRequest<ContentMessage<PollContent>>,
|
|||||||
abstract val options: List<String>
|
abstract val options: List<String>
|
||||||
abstract val isAnonymous: Boolean
|
abstract val isAnonymous: Boolean
|
||||||
abstract val isClosed: Boolean
|
abstract val isClosed: Boolean
|
||||||
abstract val closeInfo: ScheduledCloseInfo?
|
|
||||||
abstract val type: String
|
abstract val type: String
|
||||||
|
|
||||||
internal abstract val openPeriod: LongSeconds?
|
internal abstract val openPeriod: LongSeconds?
|
||||||
internal abstract val closeDate: 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 fun method(): String = "sendPoll"
|
||||||
override val resultDeserializer: DeserializationStrategy<ContentMessage<PollContent>>
|
override val resultDeserializer: DeserializationStrategy<ContentMessage<PollContent>>
|
||||||
get() = commonResultDeserializer
|
get() = commonResultDeserializer
|
||||||
@@ -163,8 +179,10 @@ data class SendRegularPoll(
|
|||||||
override val isClosed: Boolean = false,
|
override val isClosed: Boolean = false,
|
||||||
@SerialName(allowsMultipleAnswersField)
|
@SerialName(allowsMultipleAnswersField)
|
||||||
val allowMultipleAnswers: Boolean = false,
|
val allowMultipleAnswers: Boolean = false,
|
||||||
@Transient
|
@SerialName(openPeriodField)
|
||||||
override val closeInfo: ScheduledCloseInfo? = null,
|
override val openPeriod: LongSeconds?= null,
|
||||||
|
@SerialName(closeDateField)
|
||||||
|
override val closeDate: LongSeconds?,
|
||||||
@SerialName(disableNotificationField)
|
@SerialName(disableNotificationField)
|
||||||
override val disableNotification: Boolean = false,
|
override val disableNotification: Boolean = false,
|
||||||
@SerialName(replyToMessageIdField)
|
@SerialName(replyToMessageIdField)
|
||||||
@@ -178,20 +196,39 @@ data class SendRegularPoll(
|
|||||||
override val requestSerializer: SerializationStrategy<*>
|
override val requestSerializer: SerializationStrategy<*>
|
||||||
get() = serializer()
|
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 {
|
init {
|
||||||
checkPollInfo(question, options)
|
checkPollInfo(question, options)
|
||||||
closeInfo ?.checkSendData()
|
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(
|
fun SendQuizPoll(
|
||||||
chatId: ChatIdentifier,
|
chatId: ChatIdentifier,
|
||||||
question: String,
|
question: String,
|
||||||
@@ -253,6 +290,39 @@ fun SendQuizPoll(
|
|||||||
replyMarkup
|
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
|
@Serializable
|
||||||
data class SendQuizPoll internal constructor(
|
data class SendQuizPoll internal constructor(
|
||||||
@SerialName(chatIdField)
|
@SerialName(chatIdField)
|
||||||
@@ -273,8 +343,10 @@ data class SendQuizPoll internal constructor(
|
|||||||
override val parseMode: ParseMode? = null,
|
override val parseMode: ParseMode? = null,
|
||||||
@SerialName(explanationEntitiesField)
|
@SerialName(explanationEntitiesField)
|
||||||
private val rawEntities: List<RawMessageEntity>? = null,
|
private val rawEntities: List<RawMessageEntity>? = null,
|
||||||
@Transient
|
@SerialName(openPeriodField)
|
||||||
override val closeInfo: ScheduledCloseInfo? = null,
|
override val openPeriod: LongSeconds? = null,
|
||||||
|
@SerialName(closeDateField)
|
||||||
|
override val closeDate: LongSeconds? = null,
|
||||||
@SerialName(disableNotificationField)
|
@SerialName(disableNotificationField)
|
||||||
override val disableNotification: Boolean = false,
|
override val disableNotification: Boolean = false,
|
||||||
@SerialName(replyToMessageIdField)
|
@SerialName(replyToMessageIdField)
|
||||||
@@ -291,14 +363,6 @@ data class SendQuizPoll internal constructor(
|
|||||||
rawEntities ?.asTextParts(explanation ?: return@lazy null) ?.justTextSources()
|
rawEntities ?.asTextParts(explanation ?: return@lazy null) ?.justTextSources()
|
||||||
}
|
}
|
||||||
|
|
||||||
@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 {
|
init {
|
||||||
checkPollInfo(question, options)
|
checkPollInfo(question, options)
|
||||||
closeInfo ?.checkSendData()
|
closeInfo ?.checkSendData()
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package dev.inmo.tgbotapi.types
|
package dev.inmo.tgbotapi.types
|
||||||
|
|
||||||
|
import dev.inmo.micro_utils.common.Warning
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
import kotlinx.serialization.encoding.Decoder
|
import kotlinx.serialization.encoding.Decoder
|
||||||
import kotlinx.serialization.encoding.Encoder
|
import kotlinx.serialization.encoding.Encoder
|
||||||
@@ -17,9 +18,20 @@ data class ChatId(
|
|||||||
val chatId: Identifier
|
val chatId: Identifier
|
||||||
) : ChatIdentifier()
|
) : ChatIdentifier()
|
||||||
|
|
||||||
|
/**
|
||||||
val ChatId.link: String
|
* https://core.telegram.org/bots/api#formatting-options
|
||||||
get() = "tg://user?id=$chatId"
|
*/
|
||||||
|
@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
|
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,
|
override val canPinMessages: Boolean = false,
|
||||||
@SerialName(canPromoteMembersField)
|
@SerialName(canPromoteMembersField)
|
||||||
override val canPromoteMembers: Boolean = false,
|
override val canPromoteMembers: Boolean = false,
|
||||||
|
@SerialName(canManageVoiceChatsField)
|
||||||
|
override val canManageVoiceChats: Boolean = false,
|
||||||
|
@SerialName(canManageChatField)
|
||||||
|
override val canManageChat: Boolean = false,
|
||||||
@SerialName(isAnonymousField)
|
@SerialName(isAnonymousField)
|
||||||
override val isAnonymous: Boolean = false,
|
override val isAnonymous: Boolean = false,
|
||||||
@SerialName(customTitleField)
|
@SerialName(customTitleField)
|
||||||
|
|||||||
@@ -30,6 +30,10 @@ data class CreatorChatMember(
|
|||||||
override val canPinMessages: Boolean = true
|
override val canPinMessages: Boolean = true
|
||||||
@Transient
|
@Transient
|
||||||
override val canPromoteMembers: Boolean = true
|
override val canPromoteMembers: Boolean = true
|
||||||
|
@Transient
|
||||||
|
override val canManageVoiceChats: Boolean = true
|
||||||
|
@Transient
|
||||||
|
override val canManageChat: Boolean = true
|
||||||
@SerialName(statusField)
|
@SerialName(statusField)
|
||||||
@Required
|
@Required
|
||||||
private val type: String = "creator"
|
private val type: String = "creator"
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package dev.inmo.tgbotapi.types.ChatMember.abstracts
|
package dev.inmo.tgbotapi.types.ChatMember.abstracts
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||||
import kotlinx.serialization.encoding.Decoder
|
import kotlinx.serialization.encoding.Decoder
|
||||||
@@ -13,12 +14,15 @@ interface AdministratorChatMember : SpecialRightsChatMember {
|
|||||||
val canRemoveMessages: Boolean
|
val canRemoveMessages: Boolean
|
||||||
val canRestrictMembers: Boolean
|
val canRestrictMembers: Boolean
|
||||||
val canPromoteMembers: Boolean
|
val canPromoteMembers: Boolean
|
||||||
|
val canManageVoiceChats: Boolean
|
||||||
|
val canManageChat: Boolean
|
||||||
val isAnonymous: Boolean
|
val isAnonymous: Boolean
|
||||||
val customTitle: String?
|
val customTitle: String?
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serializer(AdministratorChatMember::class)
|
@Serializer(AdministratorChatMember::class)
|
||||||
internal object AdministratorChatMemberSerializer : KSerializer<AdministratorChatMember> {
|
@RiskFeature
|
||||||
|
object AdministratorChatMemberSerializer : KSerializer<AdministratorChatMember> {
|
||||||
override val descriptor: SerialDescriptor = ChatMemberSerializer.descriptor
|
override val descriptor: SerialDescriptor = ChatMemberSerializer.descriptor
|
||||||
|
|
||||||
override fun deserialize(decoder: Decoder): AdministratorChatMember = ChatMemberSerializer.deserialize(decoder) as AdministratorChatMember
|
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.ChatMember.*
|
||||||
import dev.inmo.tgbotapi.types.User
|
import dev.inmo.tgbotapi.types.User
|
||||||
import dev.inmo.tgbotapi.types.statusField
|
import dev.inmo.tgbotapi.types.statusField
|
||||||
|
import dev.inmo.tgbotapi.utils.RiskFeature
|
||||||
import dev.inmo.tgbotapi.utils.nonstrictJsonFormat
|
import dev.inmo.tgbotapi.utils.nonstrictJsonFormat
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||||
@@ -17,7 +18,8 @@ interface ChatMember {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Serializer(ChatMember::class)
|
@Serializer(ChatMember::class)
|
||||||
internal object ChatMemberSerializer : KSerializer<ChatMember> {
|
@RiskFeature
|
||||||
|
object ChatMemberSerializer : KSerializer<ChatMember> {
|
||||||
override val descriptor: SerialDescriptor = JsonObject.serializer().descriptor
|
override val descriptor: SerialDescriptor = JsonObject.serializer().descriptor
|
||||||
|
|
||||||
override fun deserialize(decoder: Decoder): ChatMember {
|
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 FoursquareType = String
|
||||||
typealias GooglePlaceId = String
|
typealias GooglePlaceId = String
|
||||||
typealias GooglePlaceType = String
|
typealias GooglePlaceType = String
|
||||||
|
typealias MembersLimit = Int
|
||||||
|
|
||||||
typealias Seconds = Int
|
typealias Seconds = Int
|
||||||
typealias MilliSeconds = Long
|
typealias MilliSeconds = Long
|
||||||
typealias LongSeconds = Long
|
typealias LongSeconds = Long
|
||||||
|
typealias UnixTimeStamp = LongSeconds
|
||||||
|
|
||||||
typealias Meters = Float
|
typealias Meters = Float
|
||||||
typealias Degrees = Int
|
typealias Degrees = Int
|
||||||
@@ -76,6 +78,10 @@ val explanationLimit = 0 .. 200
|
|||||||
|
|
||||||
val openPeriodPollSecondsLimit = 5 .. 600
|
val openPeriodPollSecondsLimit = 5 .. 600
|
||||||
|
|
||||||
|
val membersLimit = 1 .. 99999
|
||||||
|
|
||||||
|
const val botActionActualityTime: Seconds = 5
|
||||||
|
|
||||||
// Made as lazy for correct work in K/JS
|
// Made as lazy for correct work in K/JS
|
||||||
val telegramInlineModeGifPermittedMimeTypes by lazy {
|
val telegramInlineModeGifPermittedMimeTypes by lazy {
|
||||||
listOf(
|
listOf(
|
||||||
@@ -162,6 +168,12 @@ const val optionIdsField = "option_ids"
|
|||||||
const val ipAddressField = "ip_address"
|
const val ipAddressField = "ip_address"
|
||||||
const val linkedChatIdField = "linked_chat_id"
|
const val linkedChatIdField = "linked_chat_id"
|
||||||
const val horizontalAccuracyField = "horizontal_accuracy"
|
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 requestContactField = "request_contact"
|
||||||
const val requestLocationField = "request_location"
|
const val requestLocationField = "request_location"
|
||||||
@@ -239,8 +251,12 @@ const val canInviteUsersField = "can_invite_users"
|
|||||||
const val canRestrictMembersField = "can_restrict_members"
|
const val canRestrictMembersField = "can_restrict_members"
|
||||||
const val canPinMessagesField = "can_pin_messages"
|
const val canPinMessagesField = "can_pin_messages"
|
||||||
const val canPromoteMembersField = "can_promote_members"
|
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 pngStickerField = "png_sticker"
|
||||||
const val tgsStickerField = "tgs_sticker"
|
const val tgsStickerField = "tgs_sticker"
|
||||||
|
const val oldChatMemberField = "old_chat_member"
|
||||||
|
const val newChatMemberField = "new_chat_member"
|
||||||
|
|
||||||
const val okField = "ok"
|
const val okField = "ok"
|
||||||
const val captionField = "caption"
|
const val captionField = "caption"
|
||||||
@@ -292,6 +308,7 @@ const val payField = "pay"
|
|||||||
const val permissionsField = "permissions"
|
const val permissionsField = "permissions"
|
||||||
const val typeField = "type"
|
const val typeField = "type"
|
||||||
const val valueField = "value"
|
const val valueField = "value"
|
||||||
|
const val creatorField = "creator"
|
||||||
|
|
||||||
const val pointField = "point"
|
const val pointField = "point"
|
||||||
const val xShiftField = "x_shift"
|
const val xShiftField = "x_shift"
|
||||||
@@ -331,6 +348,7 @@ const val telegramPaymentChargeIdField = "telegram_payment_charge_id"
|
|||||||
const val providerPaymentChargeIdField = "provider_payment_charge_id"
|
const val providerPaymentChargeIdField = "provider_payment_charge_id"
|
||||||
const val providerTokenField = "provider_token"
|
const val providerTokenField = "provider_token"
|
||||||
const val providerDataField = "provider_data"
|
const val providerDataField = "provider_data"
|
||||||
|
const val usersField = "users"
|
||||||
|
|
||||||
const val requireNameField = "need_name"
|
const val requireNameField = "need_name"
|
||||||
const val requirePhoneNumberField = "need_phone_number"
|
const val requirePhoneNumberField = "need_phone_number"
|
||||||
|
|||||||
@@ -74,3 +74,15 @@ fun AudioFile.toInputMediaAudio(
|
|||||||
title,
|
title,
|
||||||
thumb ?.fileId
|
thumb ?.fileId
|
||||||
)
|
)
|
||||||
|
|
||||||
|
fun AudioFile.toInputMediaAudio(
|
||||||
|
textSources: TextSourcesList = emptyList(),
|
||||||
|
title: String? = this.title
|
||||||
|
): InputMediaAudio = InputMediaAudio(
|
||||||
|
fileId,
|
||||||
|
textSources,
|
||||||
|
duration,
|
||||||
|
performer,
|
||||||
|
title,
|
||||||
|
thumb ?.fileId
|
||||||
|
)
|
||||||
|
|||||||
@@ -70,3 +70,11 @@ fun DocumentFile.toInputMediaDocument(
|
|||||||
parseMode,
|
parseMode,
|
||||||
thumb ?.fileId
|
thumb ?.fileId
|
||||||
)
|
)
|
||||||
|
|
||||||
|
fun DocumentFile.toInputMediaDocument(
|
||||||
|
textSources: TextSourcesList = emptyList()
|
||||||
|
) = InputMediaDocument(
|
||||||
|
fileId,
|
||||||
|
textSources,
|
||||||
|
thumb ?.fileId
|
||||||
|
)
|
||||||
|
|||||||
@@ -53,3 +53,10 @@ fun PhotoSize.toInputMediaPhoto(
|
|||||||
caption,
|
caption,
|
||||||
parseMode
|
parseMode
|
||||||
)
|
)
|
||||||
|
|
||||||
|
fun PhotoSize.toInputMediaPhoto(
|
||||||
|
textSources: TextSourcesList = emptyList()
|
||||||
|
): InputMediaPhoto = InputMediaPhoto(
|
||||||
|
fileId,
|
||||||
|
textSources
|
||||||
|
)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package dev.inmo.tgbotapi.types.MessageEntity.textsources
|
package dev.inmo.tgbotapi.types.MessageEntity.textsources
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
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.RiskFeature
|
||||||
import dev.inmo.tgbotapi.utils.internal.*
|
import dev.inmo.tgbotapi.utils.internal.*
|
||||||
|
|
||||||
@@ -21,6 +21,26 @@ data class TextMentionTextSource @RiskFeature(DirectInvocationOfTextSourceConstr
|
|||||||
@Suppress("NOTHING_TO_INLINE")
|
@Suppress("NOTHING_TO_INLINE")
|
||||||
inline fun mention(parts: List<TextSource>, user: User) = TextMentionTextSource(parts.makeString(), user, parts)
|
inline fun mention(parts: List<TextSource>, user: User) = TextMentionTextSource(parts.makeString(), user, parts)
|
||||||
@Suppress("NOTHING_TO_INLINE")
|
@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)
|
inline fun mention(user: User, vararg parts: TextSource) = mention(parts.toList(), user)
|
||||||
@Suppress("NOTHING_TO_INLINE")
|
@Suppress("NOTHING_TO_INLINE")
|
||||||
inline fun mention(text: String, user: User) = mention(user, regular(text))
|
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)
|
||||||
|
|||||||
@@ -35,12 +35,21 @@ typealias Markdown = MarkdownParseMode
|
|||||||
typealias MarkdownV2 = MarkdownV2ParseMode
|
typealias MarkdownV2 = MarkdownV2ParseMode
|
||||||
typealias HTML = HTMLParseMode
|
typealias HTML = HTMLParseMode
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This variable respects to default parse mode used in places like next:
|
||||||
|
*
|
||||||
|
* * [dev.inmo.tgbotapi.types.message.content.TextContent.createResends]
|
||||||
|
* *
|
||||||
|
*/
|
||||||
|
var defaultParseMode: ParseMode = HTML
|
||||||
|
|
||||||
@Serializer(ParseMode::class)
|
@Serializer(ParseMode::class)
|
||||||
internal object ParseModeSerializerObject : KSerializer<ParseMode> {
|
internal object ParseModeSerializerObject : KSerializer<ParseMode> {
|
||||||
override fun deserialize(decoder: Decoder): ParseMode {
|
override fun deserialize(decoder: Decoder): ParseMode {
|
||||||
return when (decoder.decodeString()) {
|
return when (decoder.decodeString()) {
|
||||||
MarkdownParseMode.parseModeName -> MarkdownParseMode
|
Markdown.parseModeName -> Markdown
|
||||||
HTMLParseMode.parseModeName -> HTMLParseMode
|
MarkdownV2.parseModeName -> MarkdownV2
|
||||||
|
HTML.parseModeName -> HTML
|
||||||
else -> throw IllegalArgumentException("Unknown parse mode")
|
else -> throw IllegalArgumentException("Unknown parse mode")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ const val UPDATE_SHIPPING_QUERY = "shipping_query"
|
|||||||
const val UPDATE_PRE_CHECKOUT_QUERY = "pre_checkout_query"
|
const val UPDATE_PRE_CHECKOUT_QUERY = "pre_checkout_query"
|
||||||
const val UPDATE_POLL = "poll"
|
const val UPDATE_POLL = "poll"
|
||||||
const val UPDATE_POLL_ANSWER = "poll_answer"
|
const val UPDATE_POLL_ANSWER = "poll_answer"
|
||||||
|
const val MY_CHAT_MEMBER = "my_chat_member"
|
||||||
|
const val CHAT_MEMBER = "chat_member"
|
||||||
|
|
||||||
val ALL_UPDATES_LIST = listOf(
|
val ALL_UPDATES_LIST = listOf(
|
||||||
UPDATE_MESSAGE,
|
UPDATE_MESSAGE,
|
||||||
@@ -23,5 +25,7 @@ val ALL_UPDATES_LIST = listOf(
|
|||||||
UPDATE_SHIPPING_QUERY,
|
UPDATE_SHIPPING_QUERY,
|
||||||
UPDATE_PRE_CHECKOUT_QUERY,
|
UPDATE_PRE_CHECKOUT_QUERY,
|
||||||
UPDATE_POLL,
|
UPDATE_POLL,
|
||||||
UPDATE_POLL_ANSWER
|
UPDATE_POLL_ANSWER,
|
||||||
|
MY_CHAT_MEMBER,
|
||||||
|
CHAT_MEMBER
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -23,3 +23,25 @@ data class ChatPermissions(
|
|||||||
@SerialName(canPinMessagesField)
|
@SerialName(canPinMessagesField)
|
||||||
val canPinMessages: Boolean = false
|
val canPinMessages: Boolean = false
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val LeftRestrictionsChatPermissions = ChatPermissions(
|
||||||
|
canSendMessages = true,
|
||||||
|
canSendMediaMessages = true,
|
||||||
|
canSendPolls = true,
|
||||||
|
canSendOtherMessages = true,
|
||||||
|
canAddWebPagePreviews = true,
|
||||||
|
canChangeInfo = true,
|
||||||
|
canInviteUsers = true,
|
||||||
|
canPinMessages = true,
|
||||||
|
)
|
||||||
|
|
||||||
|
val RestrictionsChatPermissions = ChatPermissions(
|
||||||
|
canSendMessages = false,
|
||||||
|
canSendMediaMessages = false,
|
||||||
|
canSendPolls = false,
|
||||||
|
canSendOtherMessages = false,
|
||||||
|
canAddWebPagePreviews = false,
|
||||||
|
canChangeInfo = false,
|
||||||
|
canInviteUsers = false,
|
||||||
|
canPinMessages = false,
|
||||||
|
)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package dev.inmo.tgbotapi.types.files
|
package dev.inmo.tgbotapi.types.files
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.CommonAbstracts.TextSourcesList
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.FileId
|
import dev.inmo.tgbotapi.requests.abstracts.FileId
|
||||||
import dev.inmo.tgbotapi.types.*
|
import dev.inmo.tgbotapi.types.*
|
||||||
import dev.inmo.tgbotapi.types.InputMedia.InputMediaVideo
|
import dev.inmo.tgbotapi.types.InputMedia.InputMediaVideo
|
||||||
@@ -44,3 +45,15 @@ inline fun VideoFile.toInputMediaVideo(
|
|||||||
duration,
|
duration,
|
||||||
thumb ?.fileId
|
thumb ?.fileId
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Suppress("NOTHING_TO_INLINE")
|
||||||
|
inline fun VideoFile.toInputMediaVideo(
|
||||||
|
textSources: TextSourcesList
|
||||||
|
) = InputMediaVideo(
|
||||||
|
fileId,
|
||||||
|
textSources,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
duration,
|
||||||
|
thumb ?.fileId
|
||||||
|
)
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ import com.soywiz.klock.DateTime
|
|||||||
import dev.inmo.tgbotapi.types.*
|
import dev.inmo.tgbotapi.types.*
|
||||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
||||||
import dev.inmo.tgbotapi.types.chat.abstracts.ChannelChat
|
import dev.inmo.tgbotapi.types.chat.abstracts.ChannelChat
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.ChannelMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.ChannelContentMessage
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
||||||
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
||||||
|
|
||||||
data class ChannelMessageImpl<T: MessageContent>(
|
data class ChannelContentMessageImpl<T: MessageContent>(
|
||||||
override val messageId: MessageIdentifier,
|
override val messageId: MessageIdentifier,
|
||||||
override val chat: ChannelChat,
|
override val chat: ChannelChat,
|
||||||
override val content: T,
|
override val content: T,
|
||||||
@@ -19,4 +19,4 @@ data class ChannelMessageImpl<T: MessageContent>(
|
|||||||
override val replyMarkup: InlineKeyboardMarkup?,
|
override val replyMarkup: InlineKeyboardMarkup?,
|
||||||
override val senderBot: CommonBot?,
|
override val senderBot: CommonBot?,
|
||||||
override val authorSignature: AuthorSignature?
|
override val authorSignature: AuthorSignature?
|
||||||
) : ChannelMessage<T>
|
) : ChannelContentMessage<T>
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package dev.inmo.tgbotapi.types.message.ChatEvents
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.types.Seconds
|
||||||
|
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.*
|
||||||
|
import dev.inmo.tgbotapi.types.messageAutoDeleteTimeField
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
private const val seconds24Hours: Seconds = 60 * 60 * 24
|
||||||
|
private const val seconds7Days: Seconds = seconds24Hours * 7
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class MessageAutoDeleteTimerChanged(
|
||||||
|
@SerialName(messageAutoDeleteTimeField)
|
||||||
|
val newAutoDeleteTime: Seconds // TODO:: check that it is seconds
|
||||||
|
) : ChannelEvent, GroupEvent, SupergroupEvent
|
||||||
|
|
||||||
|
val MessageAutoDeleteTimerChanged.isOff
|
||||||
|
get() = newAutoDeleteTime == 0
|
||||||
|
|
||||||
|
val MessageAutoDeleteTimerChanged.is24Hours
|
||||||
|
get() = newAutoDeleteTime == seconds24Hours
|
||||||
|
|
||||||
|
val MessageAutoDeleteTimerChanged.is7Days
|
||||||
|
get() = newAutoDeleteTime == seconds7Days
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package dev.inmo.tgbotapi.types.message.ChatEvents.abstracts
|
||||||
|
|
||||||
|
interface VoiceChatEvent : SupergroupEvent
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package dev.inmo.tgbotapi.types.message.ChatEvents.voice
|
||||||
|
|
||||||
|
import com.soywiz.klock.TimeSpan
|
||||||
|
import com.soywiz.klock.seconds
|
||||||
|
import dev.inmo.tgbotapi.types.Seconds
|
||||||
|
import dev.inmo.tgbotapi.types.durationField
|
||||||
|
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.VoiceChatEvent
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class VoiceChatEnded(
|
||||||
|
@SerialName(durationField)
|
||||||
|
val duration: Seconds
|
||||||
|
) : VoiceChatEvent {
|
||||||
|
val timeSpan: TimeSpan
|
||||||
|
get() = TimeSpan(duration.seconds.milliseconds)
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package dev.inmo.tgbotapi.types.message.ChatEvents.voice
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.types.User
|
||||||
|
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.VoiceChatEvent
|
||||||
|
import dev.inmo.tgbotapi.types.usersField
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class VoiceChatParticipantsInvited(
|
||||||
|
@SerialName(usersField)
|
||||||
|
val users: List<User> = emptyList()
|
||||||
|
) : VoiceChatEvent
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package dev.inmo.tgbotapi.types.message.ChatEvents.voice
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.VoiceChatEvent
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
object VoiceChatStarted : VoiceChatEvent
|
||||||
@@ -8,7 +8,7 @@ import dev.inmo.tgbotapi.types.chat.abstracts.GroupChat
|
|||||||
import dev.inmo.tgbotapi.types.message.abstracts.*
|
import dev.inmo.tgbotapi.types.message.abstracts.*
|
||||||
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
||||||
|
|
||||||
data class FromChannelGroupMessageImpl<T : MessageContent>(
|
data class FromChannelGroupContentMessageImpl<T : MessageContent>(
|
||||||
override val chat: GroupChat,
|
override val chat: GroupChat,
|
||||||
override val channel: ChannelChat,
|
override val channel: ChannelChat,
|
||||||
override val messageId: MessageIdentifier,
|
override val messageId: MessageIdentifier,
|
||||||
@@ -20,9 +20,9 @@ data class FromChannelGroupMessageImpl<T : MessageContent>(
|
|||||||
override val content: T,
|
override val content: T,
|
||||||
override val senderBot: CommonBot?,
|
override val senderBot: CommonBot?,
|
||||||
override val authorSignature: AuthorSignature?
|
override val authorSignature: AuthorSignature?
|
||||||
) : FromChannelGroupMessage<T>
|
) : FromChannelGroupContentMessage<T>
|
||||||
|
|
||||||
data class AnonymousGroupMessageImpl<T : MessageContent>(
|
data class AnonymousGroupContentMessageImpl<T : MessageContent>(
|
||||||
override val chat: GroupChat,
|
override val chat: GroupChat,
|
||||||
override val messageId: MessageIdentifier,
|
override val messageId: MessageIdentifier,
|
||||||
override val date: DateTime,
|
override val date: DateTime,
|
||||||
@@ -33,9 +33,9 @@ data class AnonymousGroupMessageImpl<T : MessageContent>(
|
|||||||
override val content: T,
|
override val content: T,
|
||||||
override val senderBot: CommonBot?,
|
override val senderBot: CommonBot?,
|
||||||
override val authorSignature: AuthorSignature?
|
override val authorSignature: AuthorSignature?
|
||||||
) : AnonymousGroupMessage<T>
|
) : AnonymousGroupContentMessage<T>
|
||||||
|
|
||||||
data class CommonGroupMessageImpl<T : MessageContent>(
|
data class CommonGroupContentMessageImpl<T : MessageContent>(
|
||||||
override val chat: GroupChat,
|
override val chat: GroupChat,
|
||||||
override val messageId: MessageIdentifier,
|
override val messageId: MessageIdentifier,
|
||||||
override val user: User,
|
override val user: User,
|
||||||
@@ -46,4 +46,4 @@ data class CommonGroupMessageImpl<T : MessageContent>(
|
|||||||
override val replyMarkup: InlineKeyboardMarkup?,
|
override val replyMarkup: InlineKeyboardMarkup?,
|
||||||
override val content: T,
|
override val content: T,
|
||||||
override val senderBot: CommonBot?
|
override val senderBot: CommonBot?
|
||||||
) : CommonGroupMessage<T>
|
) : CommonGroupContentMessage<T>
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ import dev.inmo.tgbotapi.types.*
|
|||||||
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
|
||||||
import dev.inmo.tgbotapi.types.chat.abstracts.Chat
|
import dev.inmo.tgbotapi.types.chat.abstracts.Chat
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.PrivateMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.PrivateContentMessage
|
||||||
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
||||||
import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentInfo
|
import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentInfo
|
||||||
|
|
||||||
data class PrivateMessageImpl<T: MessageContent>(
|
data class PrivateContentMessageImpl<T: MessageContent>(
|
||||||
override val messageId: MessageIdentifier,
|
override val messageId: MessageIdentifier,
|
||||||
override val user: User,
|
override val user: User,
|
||||||
override val chat: Chat,
|
override val chat: Chat,
|
||||||
@@ -21,4 +21,4 @@ data class PrivateMessageImpl<T: MessageContent>(
|
|||||||
override val replyMarkup: InlineKeyboardMarkup?,
|
override val replyMarkup: InlineKeyboardMarkup?,
|
||||||
override val senderBot: CommonBot?,
|
override val senderBot: CommonBot?,
|
||||||
val paymentInfo: SuccessfulPaymentInfo?
|
val paymentInfo: SuccessfulPaymentInfo?
|
||||||
) : PrivateMessage<T>
|
) : PrivateContentMessage<T>
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import dev.inmo.tgbotapi.types.games.RawGame
|
|||||||
import dev.inmo.tgbotapi.types.location.Location
|
import dev.inmo.tgbotapi.types.location.Location
|
||||||
import dev.inmo.tgbotapi.types.message.ChatEvents.*
|
import dev.inmo.tgbotapi.types.message.ChatEvents.*
|
||||||
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.*
|
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.*
|
||||||
|
import dev.inmo.tgbotapi.types.message.ChatEvents.voice.*
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
import dev.inmo.tgbotapi.types.message.abstracts.Message
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.UnknownMessageType
|
import dev.inmo.tgbotapi.types.message.abstracts.UnknownMessageType
|
||||||
import dev.inmo.tgbotapi.types.message.content.*
|
import dev.inmo.tgbotapi.types.message.content.*
|
||||||
@@ -81,6 +82,14 @@ internal data class RawMessage(
|
|||||||
private val dice: Dice? = null,
|
private val dice: Dice? = null,
|
||||||
private val successful_payment: SuccessfulPayment? = null,
|
private val successful_payment: SuccessfulPayment? = null,
|
||||||
|
|
||||||
|
// Voice Chat Service Messages
|
||||||
|
private val voice_chat_started: VoiceChatStarted? = null,
|
||||||
|
private val voice_chat_ended: VoiceChatEnded? = null,
|
||||||
|
private val voice_chat_participants_invited: VoiceChatParticipantsInvited? = null,
|
||||||
|
|
||||||
|
// AutoDelete Message time changed
|
||||||
|
private val message_auto_delete_timer_changed: MessageAutoDeleteTimerChanged? = null,
|
||||||
|
|
||||||
// login property
|
// login property
|
||||||
private val connected_website: String? = null,
|
private val connected_website: String? = null,
|
||||||
|
|
||||||
@@ -172,6 +181,10 @@ internal data class RawMessage(
|
|||||||
left_chat_member != null -> LeftChatMember(left_chat_member)
|
left_chat_member != null -> LeftChatMember(left_chat_member)
|
||||||
new_chat_title != null -> NewChatTitle(new_chat_title)
|
new_chat_title != null -> NewChatTitle(new_chat_title)
|
||||||
new_chat_photo != null -> NewChatPhoto(new_chat_photo.toList())
|
new_chat_photo != null -> NewChatPhoto(new_chat_photo.toList())
|
||||||
|
voice_chat_started != null -> voice_chat_started
|
||||||
|
message_auto_delete_timer_changed != null -> message_auto_delete_timer_changed
|
||||||
|
voice_chat_ended != null -> voice_chat_ended
|
||||||
|
voice_chat_participants_invited != null -> voice_chat_participants_invited
|
||||||
delete_chat_photo -> DeleteChatPhoto()
|
delete_chat_photo -> DeleteChatPhoto()
|
||||||
group_chat_created -> GroupChatCreated(
|
group_chat_created -> GroupChatCreated(
|
||||||
migrate_to_chat_id
|
migrate_to_chat_id
|
||||||
@@ -256,7 +269,7 @@ internal data class RawMessage(
|
|||||||
}
|
}
|
||||||
} ?: when (chat) {
|
} ?: when (chat) {
|
||||||
is PublicChat -> when (chat) {
|
is PublicChat -> when (chat) {
|
||||||
is ChannelChat -> ChannelMessageImpl(
|
is ChannelChat -> ChannelContentMessageImpl(
|
||||||
messageId,
|
messageId,
|
||||||
chat,
|
chat,
|
||||||
content,
|
content,
|
||||||
@@ -269,7 +282,7 @@ internal data class RawMessage(
|
|||||||
author_signature
|
author_signature
|
||||||
)
|
)
|
||||||
is GroupChat -> when (sender_chat) {
|
is GroupChat -> when (sender_chat) {
|
||||||
is ChannelChat -> FromChannelGroupMessageImpl(
|
is ChannelChat -> FromChannelGroupContentMessageImpl(
|
||||||
chat,
|
chat,
|
||||||
sender_chat,
|
sender_chat,
|
||||||
messageId,
|
messageId,
|
||||||
@@ -282,7 +295,7 @@ internal data class RawMessage(
|
|||||||
via_bot,
|
via_bot,
|
||||||
author_signature
|
author_signature
|
||||||
)
|
)
|
||||||
is GroupChat -> AnonymousGroupMessageImpl(
|
is GroupChat -> AnonymousGroupContentMessageImpl(
|
||||||
chat,
|
chat,
|
||||||
messageId,
|
messageId,
|
||||||
date.asDate,
|
date.asDate,
|
||||||
@@ -294,7 +307,7 @@ internal data class RawMessage(
|
|||||||
via_bot,
|
via_bot,
|
||||||
author_signature
|
author_signature
|
||||||
)
|
)
|
||||||
null -> CommonGroupMessageImpl(
|
null -> CommonGroupContentMessageImpl(
|
||||||
chat,
|
chat,
|
||||||
messageId,
|
messageId,
|
||||||
from ?: error("It is expected that in messages from non anonymous users and channels user must be specified"),
|
from ?: error("It is expected that in messages from non anonymous users and channels user must be specified"),
|
||||||
@@ -310,7 +323,7 @@ internal data class RawMessage(
|
|||||||
}
|
}
|
||||||
else -> error("Unknown type of public chat: $chat")
|
else -> error("Unknown type of public chat: $chat")
|
||||||
}
|
}
|
||||||
is PrivateChat -> PrivateMessageImpl(
|
is PrivateChat -> PrivateContentMessageImpl(
|
||||||
messageId,
|
messageId,
|
||||||
from ?: error("Was detected common message, but owner (sender) of the message was not found"),
|
from ?: error("Was detected common message, but owner (sender) of the message was not found"),
|
||||||
chat,
|
chat,
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import dev.inmo.tgbotapi.types.chat.abstracts.ChannelChat
|
|||||||
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
||||||
import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage
|
import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage
|
||||||
|
|
||||||
interface ChannelMessage<T: MessageContent> : PossiblySentViaBotCommonMessage<T>, SignedMessage, WithSenderChatMessage {
|
interface ChannelContentMessage<T: MessageContent> : PossiblySentViaBotCommonMessage<T>, SignedMessage, WithSenderChatMessage {
|
||||||
override val chat: ChannelChat
|
override val chat: ChannelChat
|
||||||
override val senderChat: ChannelChat
|
override val senderChat: ChannelChat
|
||||||
get() = chat
|
get() = chat
|
||||||
|
|||||||
@@ -4,17 +4,20 @@ import dev.inmo.tgbotapi.types.chat.abstracts.ChannelChat
|
|||||||
import dev.inmo.tgbotapi.types.chat.abstracts.GroupChat
|
import dev.inmo.tgbotapi.types.chat.abstracts.GroupChat
|
||||||
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
||||||
|
|
||||||
interface GroupMessage<T : MessageContent> : PublicMessage<T> {
|
interface GroupContentMessage<T : MessageContent> : PublicContentMessage<T> {
|
||||||
override val chat: GroupChat
|
override val chat: GroupChat
|
||||||
}
|
}
|
||||||
|
|
||||||
interface FromChannelGroupMessage<T : MessageContent> : GroupMessage<T>, SignedMessage, WithSenderChatMessage {
|
|
||||||
|
interface FromChannelGroupContentMessage<T : MessageContent> : GroupContentMessage<T>, SignedMessage, WithSenderChatMessage {
|
||||||
val channel: ChannelChat
|
val channel: ChannelChat
|
||||||
override val senderChat: ChannelChat
|
override val senderChat: ChannelChat
|
||||||
get() = channel
|
get() = channel
|
||||||
}
|
}
|
||||||
interface AnonymousGroupMessage<T : MessageContent> : GroupMessage<T>, SignedMessage, WithSenderChatMessage {
|
|
||||||
|
interface AnonymousGroupContentMessage<T : MessageContent> : GroupContentMessage<T>, SignedMessage, WithSenderChatMessage {
|
||||||
override val senderChat: GroupChat
|
override val senderChat: GroupChat
|
||||||
get() = chat
|
get() = chat
|
||||||
}
|
}
|
||||||
interface CommonGroupMessage<T : MessageContent> : GroupMessage<T>, FromUserMessage
|
|
||||||
|
interface CommonGroupContentMessage<T : MessageContent> : GroupContentMessage<T>, FromUserMessage
|
||||||
|
|||||||
@@ -3,4 +3,4 @@ package dev.inmo.tgbotapi.types.message.abstracts
|
|||||||
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
||||||
import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage
|
import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage
|
||||||
|
|
||||||
interface PrivateMessage<T: MessageContent> : PossiblySentViaBotCommonMessage<T>, FromUserMessage
|
interface PrivateContentMessage<T: MessageContent> : PossiblySentViaBotCommonMessage<T>, FromUserMessage
|
||||||
|
|||||||
@@ -4,6 +4,6 @@ import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat
|
|||||||
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
||||||
import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage
|
import dev.inmo.tgbotapi.types.message.content.abstracts.PossiblySentViaBotCommonMessage
|
||||||
|
|
||||||
interface PublicMessage<T: MessageContent> : PossiblySentViaBotCommonMessage<T> {
|
interface PublicContentMessage<T: MessageContent> : PossiblySentViaBotCommonMessage<T> {
|
||||||
override val chat: PublicChat
|
override val chat: PublicChat
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
package dev.inmo.tgbotapi.types.message.content
|
package dev.inmo.tgbotapi.types.message.content
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.CommonAbstracts.TextPart
|
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||||
import dev.inmo.tgbotapi.CommonAbstracts.TextedInput
|
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.requests.send.SendTextMessage
|
import dev.inmo.tgbotapi.requests.send.SendTextMessage
|
||||||
import dev.inmo.tgbotapi.types.ChatIdentifier
|
import dev.inmo.tgbotapi.types.ChatIdentifier
|
||||||
import dev.inmo.tgbotapi.types.MessageIdentifier
|
import dev.inmo.tgbotapi.types.MessageIdentifier
|
||||||
import dev.inmo.tgbotapi.types.ParseMode.*
|
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
|
||||||
|
import dev.inmo.tgbotapi.types.ParseMode.defaultParseMode
|
||||||
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
||||||
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
|
||||||
import dev.inmo.tgbotapi.utils.internal.*
|
|
||||||
|
|
||||||
data class TextContent(
|
data class TextContent(
|
||||||
override val text: String,
|
override val text: String,
|
||||||
@@ -24,51 +23,11 @@ data class TextContent(
|
|||||||
replyMarkup: KeyboardMarkup?
|
replyMarkup: KeyboardMarkup?
|
||||||
): Request<ContentMessage<TextContent>> = SendTextMessage(
|
): Request<ContentMessage<TextContent>> = SendTextMessage(
|
||||||
chatId,
|
chatId,
|
||||||
toHtmlTexts().first(),
|
textSources,
|
||||||
HTMLParseMode,
|
|
||||||
false,
|
false,
|
||||||
disableNotification,
|
disableNotification,
|
||||||
replyToMessageId,
|
replyToMessageId,
|
||||||
allowSendingWithoutReply,
|
allowSendingWithoutReply,
|
||||||
replyMarkup
|
replyMarkup
|
||||||
)
|
)
|
||||||
|
|
||||||
override fun createResends(
|
|
||||||
chatId: ChatIdentifier,
|
|
||||||
disableNotification: Boolean,
|
|
||||||
replyToMessageId: MessageIdentifier?,
|
|
||||||
allowSendingWithoutReply: Boolean?,
|
|
||||||
replyMarkup: KeyboardMarkup?
|
|
||||||
): List<Request<ContentMessage<TextContent>>> = createResends(
|
|
||||||
chatId,
|
|
||||||
disableNotification,
|
|
||||||
replyToMessageId,
|
|
||||||
allowSendingWithoutReply,
|
|
||||||
replyMarkup,
|
|
||||||
HTMLParseMode
|
|
||||||
)
|
|
||||||
|
|
||||||
fun createResends(
|
|
||||||
chatId: ChatIdentifier,
|
|
||||||
disableNotification: Boolean,
|
|
||||||
replyToMessageId: MessageIdentifier?,
|
|
||||||
allowSendingWithoutReply: Boolean?,
|
|
||||||
replyMarkup: KeyboardMarkup?,
|
|
||||||
parseMode: ParseMode = HTMLParseMode
|
|
||||||
): List<Request<ContentMessage<TextContent>>> = when (parseMode) {
|
|
||||||
is MarkdownParseMode -> toMarkdownTexts()
|
|
||||||
is MarkdownV2ParseMode -> toMarkdownV2Texts()
|
|
||||||
is HTMLParseMode -> toHtmlTexts()
|
|
||||||
}.map {
|
|
||||||
SendTextMessage(
|
|
||||||
chatId,
|
|
||||||
it,
|
|
||||||
parseMode,
|
|
||||||
false,
|
|
||||||
disableNotification,
|
|
||||||
replyToMessageId,
|
|
||||||
allowSendingWithoutReply,
|
|
||||||
replyMarkup
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,12 +14,4 @@ interface ResendableContent {
|
|||||||
allowSendingWithoutReply: Boolean? = null,
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
replyMarkup: KeyboardMarkup? = null
|
replyMarkup: KeyboardMarkup? = null
|
||||||
): Request<out Message>
|
): Request<out Message>
|
||||||
|
|
||||||
fun createResends(
|
|
||||||
chatId: ChatIdentifier,
|
|
||||||
disableNotification: Boolean = false,
|
|
||||||
replyToMessageId: MessageIdentifier? = null,
|
|
||||||
allowSendingWithoutReply: Boolean? = null,
|
|
||||||
replyMarkup: KeyboardMarkup? = null
|
|
||||||
): List<Request<out Message>> = listOf(createResend(chatId, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup))
|
|
||||||
}
|
}
|
||||||
@@ -1,21 +1,16 @@
|
|||||||
package dev.inmo.tgbotapi.types.message.content.media
|
package dev.inmo.tgbotapi.types.message.content.media
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.CommonAbstracts.CaptionedInput
|
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||||
import dev.inmo.tgbotapi.CommonAbstracts.TextPart
|
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.requests.send.media.SendAnimation
|
import dev.inmo.tgbotapi.requests.send.media.SendAnimation
|
||||||
import dev.inmo.tgbotapi.types.ChatIdentifier
|
import dev.inmo.tgbotapi.types.ChatIdentifier
|
||||||
import dev.inmo.tgbotapi.types.InputMedia.InputMediaAnimation
|
import dev.inmo.tgbotapi.types.InputMedia.InputMediaAnimation
|
||||||
import dev.inmo.tgbotapi.types.MessageIdentifier
|
import dev.inmo.tgbotapi.types.MessageIdentifier
|
||||||
import dev.inmo.tgbotapi.types.ParseMode.HTMLParseMode
|
|
||||||
import dev.inmo.tgbotapi.types.ParseMode.MarkdownV2
|
|
||||||
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
||||||
import dev.inmo.tgbotapi.types.files.AnimationFile
|
import dev.inmo.tgbotapi.types.files.AnimationFile
|
||||||
import dev.inmo.tgbotapi.types.files.DocumentFile
|
import dev.inmo.tgbotapi.types.files.DocumentFile
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
||||||
import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent
|
import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent
|
||||||
import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions
|
|
||||||
import dev.inmo.tgbotapi.utils.internal.toMarkdownV2Captions
|
|
||||||
|
|
||||||
data class AnimationContent(
|
data class AnimationContent(
|
||||||
override val media: AnimationFile,
|
override val media: AnimationFile,
|
||||||
@@ -33,8 +28,7 @@ data class AnimationContent(
|
|||||||
chatId,
|
chatId,
|
||||||
media.fileId,
|
media.fileId,
|
||||||
media.thumb ?.fileId,
|
media.thumb ?.fileId,
|
||||||
toHtmlCaptions().firstOrNull(),
|
textSources,
|
||||||
HTMLParseMode,
|
|
||||||
media.duration,
|
media.duration,
|
||||||
media.width,
|
media.width,
|
||||||
media.height,
|
media.height,
|
||||||
@@ -46,8 +40,7 @@ data class AnimationContent(
|
|||||||
|
|
||||||
override fun asInputMedia(): InputMediaAnimation = InputMediaAnimation(
|
override fun asInputMedia(): InputMediaAnimation = InputMediaAnimation(
|
||||||
media.fileId,
|
media.fileId,
|
||||||
toMarkdownV2Captions().firstOrNull(),
|
textSources,
|
||||||
MarkdownV2,
|
|
||||||
media.width,
|
media.width,
|
||||||
media.height,
|
media.height,
|
||||||
media.duration,
|
media.duration,
|
||||||
|
|||||||
@@ -1,18 +1,17 @@
|
|||||||
package dev.inmo.tgbotapi.types.message.content.media
|
package dev.inmo.tgbotapi.types.message.content.media
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.CommonAbstracts.TextPart
|
import dev.inmo.tgbotapi.CommonAbstracts.TextPart
|
||||||
|
import dev.inmo.tgbotapi.CommonAbstracts.textSources
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.requests.send.media.SendAudio
|
import dev.inmo.tgbotapi.requests.send.media.SendAudio
|
||||||
import dev.inmo.tgbotapi.types.ChatIdentifier
|
import dev.inmo.tgbotapi.types.ChatIdentifier
|
||||||
import dev.inmo.tgbotapi.types.InputMedia.InputMediaAudio
|
import dev.inmo.tgbotapi.types.InputMedia.InputMediaAudio
|
||||||
import dev.inmo.tgbotapi.types.InputMedia.toInputMediaAudio
|
import dev.inmo.tgbotapi.types.InputMedia.toInputMediaAudio
|
||||||
import dev.inmo.tgbotapi.types.MessageIdentifier
|
import dev.inmo.tgbotapi.types.MessageIdentifier
|
||||||
import dev.inmo.tgbotapi.types.ParseMode.HTMLParseMode
|
|
||||||
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
||||||
import dev.inmo.tgbotapi.types.files.AudioFile
|
import dev.inmo.tgbotapi.types.files.AudioFile
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
||||||
import dev.inmo.tgbotapi.types.message.content.abstracts.AudioMediaGroupContent
|
import dev.inmo.tgbotapi.types.message.content.abstracts.AudioMediaGroupContent
|
||||||
import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions
|
|
||||||
|
|
||||||
data class AudioContent(
|
data class AudioContent(
|
||||||
override val media: AudioFile,
|
override val media: AudioFile,
|
||||||
@@ -29,8 +28,7 @@ data class AudioContent(
|
|||||||
chatId,
|
chatId,
|
||||||
media.fileId,
|
media.fileId,
|
||||||
media.thumb ?.fileId,
|
media.thumb ?.fileId,
|
||||||
toHtmlCaptions().firstOrNull(),
|
textSources,
|
||||||
HTMLParseMode,
|
|
||||||
media.duration,
|
media.duration,
|
||||||
media.performer,
|
media.performer,
|
||||||
media.title,
|
media.title,
|
||||||
@@ -42,8 +40,5 @@ data class AudioContent(
|
|||||||
|
|
||||||
override fun toMediaGroupMemberInputMedia(): InputMediaAudio = asInputMedia()
|
override fun toMediaGroupMemberInputMedia(): InputMediaAudio = asInputMedia()
|
||||||
|
|
||||||
override fun asInputMedia(): InputMediaAudio = media.toInputMediaAudio(
|
override fun asInputMedia(): InputMediaAudio = media.toInputMediaAudio(textSources)
|
||||||
toHtmlCaptions().firstOrNull(),
|
|
||||||
HTMLParseMode
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,18 @@
|
|||||||
package dev.inmo.tgbotapi.types.message.content.media
|
package dev.inmo.tgbotapi.types.message.content.media
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.CommonAbstracts.CaptionedInput
|
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||||
import dev.inmo.tgbotapi.CommonAbstracts.TextPart
|
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.requests.send.media.SendDocument
|
import dev.inmo.tgbotapi.requests.send.media.SendDocument
|
||||||
import dev.inmo.tgbotapi.types.ChatIdentifier
|
import dev.inmo.tgbotapi.types.ChatIdentifier
|
||||||
import dev.inmo.tgbotapi.types.InputMedia.InputMediaDocument
|
import dev.inmo.tgbotapi.types.InputMedia.InputMediaDocument
|
||||||
import dev.inmo.tgbotapi.types.InputMedia.toInputMediaDocument
|
import dev.inmo.tgbotapi.types.InputMedia.toInputMediaDocument
|
||||||
import dev.inmo.tgbotapi.types.MessageIdentifier
|
import dev.inmo.tgbotapi.types.MessageIdentifier
|
||||||
import dev.inmo.tgbotapi.types.ParseMode.HTMLParseMode
|
|
||||||
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
||||||
import dev.inmo.tgbotapi.types.files.DocumentFile
|
import dev.inmo.tgbotapi.types.files.DocumentFile
|
||||||
import dev.inmo.tgbotapi.types.files.asDocumentFile
|
import dev.inmo.tgbotapi.types.files.asDocumentFile
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
||||||
import dev.inmo.tgbotapi.types.message.content.abstracts.DocumentMediaGroupContent
|
import dev.inmo.tgbotapi.types.message.content.abstracts.DocumentMediaGroupContent
|
||||||
import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent
|
import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent
|
||||||
import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions
|
|
||||||
|
|
||||||
data class DocumentContent(
|
data class DocumentContent(
|
||||||
override val media: DocumentFile,
|
override val media: DocumentFile,
|
||||||
@@ -32,8 +29,7 @@ data class DocumentContent(
|
|||||||
chatId,
|
chatId,
|
||||||
media.fileId,
|
media.fileId,
|
||||||
media.thumb ?.fileId,
|
media.thumb ?.fileId,
|
||||||
toHtmlCaptions().firstOrNull(),
|
textSources,
|
||||||
HTMLParseMode,
|
|
||||||
disableNotification,
|
disableNotification,
|
||||||
replyToMessageId,
|
replyToMessageId,
|
||||||
allowSendingWithoutReply,
|
allowSendingWithoutReply,
|
||||||
@@ -42,10 +38,7 @@ data class DocumentContent(
|
|||||||
|
|
||||||
override fun toMediaGroupMemberInputMedia(): InputMediaDocument = asInputMedia()
|
override fun toMediaGroupMemberInputMedia(): InputMediaDocument = asInputMedia()
|
||||||
|
|
||||||
override fun asInputMedia(): InputMediaDocument = media.toInputMediaDocument(
|
override fun asInputMedia(): InputMediaDocument = media.toInputMediaDocument(textSources)
|
||||||
toHtmlCaptions().firstOrNull(),
|
|
||||||
HTMLParseMode
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("NOTHING_TO_INLINE")
|
@Suppress("NOTHING_TO_INLINE")
|
||||||
|
|||||||
@@ -1,19 +1,18 @@
|
|||||||
package dev.inmo.tgbotapi.types.message.content.media
|
package dev.inmo.tgbotapi.types.message.content.media
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.CommonAbstracts.TextPart
|
import dev.inmo.tgbotapi.CommonAbstracts.TextPart
|
||||||
|
import dev.inmo.tgbotapi.CommonAbstracts.textSources
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.requests.send.media.SendPhoto
|
import dev.inmo.tgbotapi.requests.send.media.SendPhoto
|
||||||
import dev.inmo.tgbotapi.types.ChatIdentifier
|
import dev.inmo.tgbotapi.types.ChatIdentifier
|
||||||
import dev.inmo.tgbotapi.types.InputMedia.InputMediaPhoto
|
import dev.inmo.tgbotapi.types.InputMedia.InputMediaPhoto
|
||||||
import dev.inmo.tgbotapi.types.InputMedia.toInputMediaPhoto
|
import dev.inmo.tgbotapi.types.InputMedia.toInputMediaPhoto
|
||||||
import dev.inmo.tgbotapi.types.MessageIdentifier
|
import dev.inmo.tgbotapi.types.MessageIdentifier
|
||||||
import dev.inmo.tgbotapi.types.ParseMode.HTMLParseMode
|
|
||||||
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
||||||
import dev.inmo.tgbotapi.types.files.*
|
import dev.inmo.tgbotapi.types.files.*
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
||||||
import dev.inmo.tgbotapi.types.message.content.abstracts.MediaCollectionContent
|
import dev.inmo.tgbotapi.types.message.content.abstracts.MediaCollectionContent
|
||||||
import dev.inmo.tgbotapi.types.message.content.abstracts.VisualMediaGroupContent
|
import dev.inmo.tgbotapi.types.message.content.abstracts.VisualMediaGroupContent
|
||||||
import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions
|
|
||||||
|
|
||||||
data class PhotoContent(
|
data class PhotoContent(
|
||||||
override val mediaCollection: Photo,
|
override val mediaCollection: Photo,
|
||||||
@@ -31,8 +30,7 @@ data class PhotoContent(
|
|||||||
): Request<ContentMessage<PhotoContent>> = SendPhoto(
|
): Request<ContentMessage<PhotoContent>> = SendPhoto(
|
||||||
chatId,
|
chatId,
|
||||||
media.fileId,
|
media.fileId,
|
||||||
toHtmlCaptions().firstOrNull(),
|
textSources,
|
||||||
HTMLParseMode,
|
|
||||||
disableNotification,
|
disableNotification,
|
||||||
replyToMessageId,
|
replyToMessageId,
|
||||||
allowSendingWithoutReply,
|
allowSendingWithoutReply,
|
||||||
@@ -41,8 +39,5 @@ data class PhotoContent(
|
|||||||
|
|
||||||
override fun toMediaGroupMemberInputMedia(): InputMediaPhoto = asInputMedia()
|
override fun toMediaGroupMemberInputMedia(): InputMediaPhoto = asInputMedia()
|
||||||
|
|
||||||
override fun asInputMedia(): InputMediaPhoto = media.toInputMediaPhoto(
|
override fun asInputMedia(): InputMediaPhoto = media.toInputMediaPhoto(textSources)
|
||||||
toHtmlCaptions().firstOrNull(),
|
|
||||||
HTMLParseMode
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,17 @@
|
|||||||
package dev.inmo.tgbotapi.types.message.content.media
|
package dev.inmo.tgbotapi.types.message.content.media
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.CommonAbstracts.TextPart
|
import dev.inmo.tgbotapi.CommonAbstracts.TextPart
|
||||||
|
import dev.inmo.tgbotapi.CommonAbstracts.textSources
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.requests.send.media.SendVideo
|
import dev.inmo.tgbotapi.requests.send.media.SendVideo
|
||||||
import dev.inmo.tgbotapi.types.ChatIdentifier
|
import dev.inmo.tgbotapi.types.ChatIdentifier
|
||||||
import dev.inmo.tgbotapi.types.InputMedia.InputMediaVideo
|
import dev.inmo.tgbotapi.types.InputMedia.InputMediaVideo
|
||||||
import dev.inmo.tgbotapi.types.MessageIdentifier
|
import dev.inmo.tgbotapi.types.MessageIdentifier
|
||||||
import dev.inmo.tgbotapi.types.ParseMode.HTMLParseMode
|
|
||||||
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
||||||
import dev.inmo.tgbotapi.types.files.VideoFile
|
import dev.inmo.tgbotapi.types.files.VideoFile
|
||||||
import dev.inmo.tgbotapi.types.files.toInputMediaVideo
|
import dev.inmo.tgbotapi.types.files.toInputMediaVideo
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
||||||
import dev.inmo.tgbotapi.types.message.content.abstracts.VisualMediaGroupContent
|
import dev.inmo.tgbotapi.types.message.content.abstracts.VisualMediaGroupContent
|
||||||
import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions
|
|
||||||
|
|
||||||
data class VideoContent(
|
data class VideoContent(
|
||||||
override val media: VideoFile,
|
override val media: VideoFile,
|
||||||
@@ -29,8 +28,7 @@ data class VideoContent(
|
|||||||
chatId,
|
chatId,
|
||||||
media.fileId,
|
media.fileId,
|
||||||
media.thumb ?.fileId,
|
media.thumb ?.fileId,
|
||||||
toHtmlCaptions().firstOrNull(),
|
textSources,
|
||||||
HTMLParseMode,
|
|
||||||
media.duration,
|
media.duration,
|
||||||
media.width,
|
media.width,
|
||||||
media.height,
|
media.height,
|
||||||
@@ -43,8 +41,5 @@ data class VideoContent(
|
|||||||
|
|
||||||
override fun toMediaGroupMemberInputMedia(): InputMediaVideo = asInputMedia()
|
override fun toMediaGroupMemberInputMedia(): InputMediaVideo = asInputMedia()
|
||||||
|
|
||||||
override fun asInputMedia(): InputMediaVideo = media.toInputMediaVideo(
|
override fun asInputMedia(): InputMediaVideo = media.toInputMediaVideo(textSources)
|
||||||
toHtmlCaptions().firstOrNull(),
|
|
||||||
HTMLParseMode
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,15 @@
|
|||||||
package dev.inmo.tgbotapi.types.message.content.media
|
package dev.inmo.tgbotapi.types.message.content.media
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.CommonAbstracts.CaptionedInput
|
import dev.inmo.tgbotapi.CommonAbstracts.*
|
||||||
import dev.inmo.tgbotapi.CommonAbstracts.TextPart
|
|
||||||
import dev.inmo.tgbotapi.requests.abstracts.Request
|
import dev.inmo.tgbotapi.requests.abstracts.Request
|
||||||
import dev.inmo.tgbotapi.requests.send.media.SendVoice
|
import dev.inmo.tgbotapi.requests.send.media.SendVoice
|
||||||
import dev.inmo.tgbotapi.types.ChatIdentifier
|
import dev.inmo.tgbotapi.types.ChatIdentifier
|
||||||
import dev.inmo.tgbotapi.types.InputMedia.InputMediaAudio
|
import dev.inmo.tgbotapi.types.InputMedia.InputMediaAudio
|
||||||
import dev.inmo.tgbotapi.types.MessageIdentifier
|
import dev.inmo.tgbotapi.types.MessageIdentifier
|
||||||
import dev.inmo.tgbotapi.types.ParseMode.HTMLParseMode
|
|
||||||
import dev.inmo.tgbotapi.types.ParseMode.MarkdownV2
|
|
||||||
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
|
||||||
import dev.inmo.tgbotapi.types.files.VoiceFile
|
import dev.inmo.tgbotapi.types.files.VoiceFile
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
|
||||||
import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent
|
import dev.inmo.tgbotapi.types.message.content.abstracts.MediaContent
|
||||||
import dev.inmo.tgbotapi.utils.internal.toHtmlCaptions
|
|
||||||
import dev.inmo.tgbotapi.utils.internal.toMarkdownV2Captions
|
|
||||||
|
|
||||||
data class VoiceContent(
|
data class VoiceContent(
|
||||||
override val media: VoiceFile,
|
override val media: VoiceFile,
|
||||||
@@ -30,8 +25,7 @@ data class VoiceContent(
|
|||||||
): Request<ContentMessage<VoiceContent>> = SendVoice(
|
): Request<ContentMessage<VoiceContent>> = SendVoice(
|
||||||
chatId,
|
chatId,
|
||||||
media.fileId,
|
media.fileId,
|
||||||
toHtmlCaptions().firstOrNull(),
|
textSources,
|
||||||
HTMLParseMode,
|
|
||||||
media.duration,
|
media.duration,
|
||||||
disableNotification,
|
disableNotification,
|
||||||
replyToMessageId,
|
replyToMessageId,
|
||||||
@@ -41,8 +35,7 @@ data class VoiceContent(
|
|||||||
|
|
||||||
override fun asInputMedia(): InputMediaAudio = InputMediaAudio(
|
override fun asInputMedia(): InputMediaAudio = InputMediaAudio(
|
||||||
media.fileId,
|
media.fileId,
|
||||||
toMarkdownV2Captions().firstOrNull(),
|
textSources,
|
||||||
MarkdownV2,
|
|
||||||
media.duration
|
media.duration
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,13 +4,13 @@ import dev.inmo.tgbotapi.types.dataField
|
|||||||
import dev.inmo.tgbotapi.types.passport.credentials.DataCredentials
|
import dev.inmo.tgbotapi.types.passport.credentials.DataCredentials
|
||||||
import dev.inmo.tgbotapi.types.passport.credentials.EndDataCredentials
|
import dev.inmo.tgbotapi.types.passport.credentials.EndDataCredentials
|
||||||
import dev.inmo.tgbotapi.types.passport.decrypted.abstracts.SecureValueWithData
|
import dev.inmo.tgbotapi.types.passport.decrypted.abstracts.SecureValueWithData
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.*
|
||||||
import kotlinx.serialization.Serializable
|
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class AddressSecureValue(
|
data class AddressSecureValue(
|
||||||
@SerialName(dataField)
|
@SerialName(dataField)
|
||||||
override val data: DataCredentials
|
override val data: DataCredentials
|
||||||
) : SecureValueWithData {
|
) : SecureValueWithData {
|
||||||
|
@Transient
|
||||||
override val credentials: List<EndDataCredentials> = listOf(data)
|
override val credentials: List<EndDataCredentials> = listOf(data)
|
||||||
}
|
}
|
||||||
@@ -4,13 +4,13 @@ import dev.inmo.tgbotapi.types.dataField
|
|||||||
import dev.inmo.tgbotapi.types.passport.credentials.DataCredentials
|
import dev.inmo.tgbotapi.types.passport.credentials.DataCredentials
|
||||||
import dev.inmo.tgbotapi.types.passport.credentials.EndDataCredentials
|
import dev.inmo.tgbotapi.types.passport.credentials.EndDataCredentials
|
||||||
import dev.inmo.tgbotapi.types.passport.decrypted.abstracts.SecureValueWithData
|
import dev.inmo.tgbotapi.types.passport.decrypted.abstracts.SecureValueWithData
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.*
|
||||||
import kotlinx.serialization.Serializable
|
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class PersonalDetailsSecureValue(
|
data class PersonalDetailsSecureValue(
|
||||||
@SerialName(dataField)
|
@SerialName(dataField)
|
||||||
override val data: DataCredentials
|
override val data: DataCredentials
|
||||||
) : SecureValueWithData {
|
) : SecureValueWithData {
|
||||||
|
@Transient
|
||||||
override val credentials: List<EndDataCredentials> = listOf(data)
|
override val credentials: List<EndDataCredentials> = listOf(data)
|
||||||
}
|
}
|
||||||
@@ -3,8 +3,8 @@ package dev.inmo.tgbotapi.types.passport.encrypted
|
|||||||
import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer
|
import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer
|
||||||
import dev.inmo.tgbotapi.types.emailField
|
import dev.inmo.tgbotapi.types.emailField
|
||||||
import dev.inmo.tgbotapi.types.hashField
|
import dev.inmo.tgbotapi.types.hashField
|
||||||
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.PassportElementHash
|
|
||||||
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportElementWithEmail
|
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportElementWithEmail
|
||||||
|
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.PassportElementHash
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package dev.inmo.tgbotapi.types.passport.encrypted
|
|||||||
import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer
|
import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer
|
||||||
import dev.inmo.tgbotapi.types.dataField
|
import dev.inmo.tgbotapi.types.dataField
|
||||||
import dev.inmo.tgbotapi.types.passport.credentials.EncryptedData
|
import dev.inmo.tgbotapi.types.passport.credentials.EncryptedData
|
||||||
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.PassportElementHash
|
|
||||||
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportElementWithData
|
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportElementWithData
|
||||||
|
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.PassportElementHash
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package dev.inmo.tgbotapi.types.passport.encrypted
|
|||||||
import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer
|
import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer
|
||||||
import dev.inmo.tgbotapi.types.dataField
|
import dev.inmo.tgbotapi.types.dataField
|
||||||
import dev.inmo.tgbotapi.types.passport.credentials.EncryptedData
|
import dev.inmo.tgbotapi.types.passport.credentials.EncryptedData
|
||||||
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.PassportElementHash
|
|
||||||
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportElementWithData
|
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportElementWithData
|
||||||
|
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.PassportElementHash
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ package dev.inmo.tgbotapi.types.passport.encrypted
|
|||||||
|
|
||||||
import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer
|
import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer
|
||||||
import dev.inmo.tgbotapi.types.hashField
|
import dev.inmo.tgbotapi.types.hashField
|
||||||
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.PassportElementHash
|
|
||||||
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportElementWithPhoneNumber
|
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportElementWithPhoneNumber
|
||||||
|
import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.PassportElementHash
|
||||||
import dev.inmo.tgbotapi.types.phoneNumberField
|
import dev.inmo.tgbotapi.types.phoneNumberField
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|||||||
@@ -33,6 +33,9 @@ val LongSeconds.asApproximateScheduledCloseInfo
|
|||||||
get() = ApproximateScheduledCloseInfo(
|
get() = ApproximateScheduledCloseInfo(
|
||||||
TimeSpan(this * 1000.0)
|
TimeSpan(this * 1000.0)
|
||||||
)
|
)
|
||||||
|
fun LongSeconds.asApproximateScheduledCloseInfo(startPoint: DateTime) = ApproximateScheduledCloseInfo(
|
||||||
|
TimeSpan(this * 1000.0), startPoint
|
||||||
|
)
|
||||||
val LongSeconds.asExactScheduledCloseInfo
|
val LongSeconds.asExactScheduledCloseInfo
|
||||||
get() = ExactScheduledCloseInfo(
|
get() = ExactScheduledCloseInfo(
|
||||||
DateTime(unixMillis = this * 1000.0)
|
DateTime(unixMillis = this * 1000.0)
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package dev.inmo.tgbotapi.types.update
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.types.ChatMemberUpdated
|
||||||
|
import dev.inmo.tgbotapi.types.UpdateIdentifier
|
||||||
|
import dev.inmo.tgbotapi.types.update.abstracts.ChatMemberUpdatedUpdate
|
||||||
|
|
||||||
|
data class CommonChatMemberUpdatedUpdate(
|
||||||
|
override val updateId: UpdateIdentifier,
|
||||||
|
override val data: ChatMemberUpdated
|
||||||
|
) : ChatMemberUpdatedUpdate
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package dev.inmo.tgbotapi.types.update
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.types.ChatMemberUpdated
|
||||||
|
import dev.inmo.tgbotapi.types.UpdateIdentifier
|
||||||
|
import dev.inmo.tgbotapi.types.update.abstracts.ChatMemberUpdatedUpdate
|
||||||
|
|
||||||
|
data class MyChatMemberUpdatedUpdate(
|
||||||
|
override val updateId: UpdateIdentifier,
|
||||||
|
override val data: ChatMemberUpdated
|
||||||
|
) : ChatMemberUpdatedUpdate
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
package dev.inmo.tgbotapi.types.update
|
package dev.inmo.tgbotapi.types.update
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.types.*
|
||||||
import dev.inmo.tgbotapi.types.CallbackQuery.RawCallbackQuery
|
import dev.inmo.tgbotapi.types.CallbackQuery.RawCallbackQuery
|
||||||
import dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult.RawChosenInlineResult
|
import dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult.RawChosenInlineResult
|
||||||
import dev.inmo.tgbotapi.types.InlineQueries.query.RawInlineQuery
|
import dev.inmo.tgbotapi.types.InlineQueries.query.RawInlineQuery
|
||||||
import dev.inmo.tgbotapi.types.UpdateIdentifier
|
|
||||||
import dev.inmo.tgbotapi.types.message.abstracts.*
|
import dev.inmo.tgbotapi.types.message.abstracts.*
|
||||||
import dev.inmo.tgbotapi.types.payments.PreCheckoutQuery
|
import dev.inmo.tgbotapi.types.payments.PreCheckoutQuery
|
||||||
import dev.inmo.tgbotapi.types.payments.ShippingQuery
|
import dev.inmo.tgbotapi.types.payments.ShippingQuery
|
||||||
@@ -11,7 +11,6 @@ import dev.inmo.tgbotapi.types.polls.Poll
|
|||||||
import dev.inmo.tgbotapi.types.polls.PollAnswer
|
import dev.inmo.tgbotapi.types.polls.PollAnswer
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.UnknownUpdate
|
import dev.inmo.tgbotapi.types.update.abstracts.UnknownUpdate
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||||
import dev.inmo.tgbotapi.types.updateIdField
|
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
import kotlinx.serialization.json.JsonElement
|
import kotlinx.serialization.json.JsonElement
|
||||||
import kotlinx.serialization.json.jsonObject
|
import kotlinx.serialization.json.jsonObject
|
||||||
@@ -34,7 +33,9 @@ internal data class RawUpdate constructor(
|
|||||||
private val shipping_query: ShippingQuery? = null,
|
private val shipping_query: ShippingQuery? = null,
|
||||||
private val pre_checkout_query: PreCheckoutQuery? = null,
|
private val pre_checkout_query: PreCheckoutQuery? = null,
|
||||||
private val poll: Poll? = null,
|
private val poll: Poll? = null,
|
||||||
private val poll_answer: PollAnswer? = null
|
private val poll_answer: PollAnswer? = null,
|
||||||
|
private val my_chat_member: ChatMemberUpdated? = null,
|
||||||
|
private val chat_member: ChatMemberUpdated? = null
|
||||||
) {
|
) {
|
||||||
private var initedUpdate: Update? = null
|
private var initedUpdate: Update? = null
|
||||||
/**
|
/**
|
||||||
@@ -58,6 +59,8 @@ internal data class RawUpdate constructor(
|
|||||||
pre_checkout_query != null -> PreCheckoutQueryUpdate(updateId, pre_checkout_query)
|
pre_checkout_query != null -> PreCheckoutQueryUpdate(updateId, pre_checkout_query)
|
||||||
poll != null -> PollUpdate(updateId, poll)
|
poll != null -> PollUpdate(updateId, poll)
|
||||||
poll_answer != null -> PollAnswerUpdate(updateId, poll_answer)
|
poll_answer != null -> PollAnswerUpdate(updateId, poll_answer)
|
||||||
|
my_chat_member != null -> MyChatMemberUpdatedUpdate(updateId, my_chat_member)
|
||||||
|
chat_member != null -> CommonChatMemberUpdatedUpdate(updateId, chat_member)
|
||||||
else -> UnknownUpdate(
|
else -> UnknownUpdate(
|
||||||
updateId,
|
updateId,
|
||||||
raw.toString(),
|
raw.toString(),
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package dev.inmo.tgbotapi.types.update.abstracts
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.types.ChatMemberUpdated
|
||||||
|
|
||||||
|
interface ChatMemberUpdatedUpdate : Update {
|
||||||
|
override val data: ChatMemberUpdated
|
||||||
|
}
|
||||||
@@ -28,6 +28,8 @@ interface FlowsUpdatesFilter : UpdatesFilter {
|
|||||||
val preCheckoutQueryFlow: Flow<PreCheckoutQueryUpdate>
|
val preCheckoutQueryFlow: Flow<PreCheckoutQueryUpdate>
|
||||||
val pollFlow: Flow<PollUpdate>
|
val pollFlow: Flow<PollUpdate>
|
||||||
val pollAnswerFlow: Flow<PollAnswerUpdate>
|
val pollAnswerFlow: Flow<PollAnswerUpdate>
|
||||||
|
val chatMemberUpdatedFlow: Flow<CommonChatMemberUpdatedUpdate>
|
||||||
|
val myChatMemberUpdatedFlow: Flow<MyChatMemberUpdatedUpdate>
|
||||||
val unknownUpdateTypeFlow: Flow<UnknownUpdate>
|
val unknownUpdateTypeFlow: Flow<UnknownUpdate>
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,5 +76,7 @@ class DefaultFlowsUpdatesFilter(
|
|||||||
override val preCheckoutQueryFlow: Flow<PreCheckoutQueryUpdate> = allUpdatesFlow.filterIsInstance()
|
override val preCheckoutQueryFlow: Flow<PreCheckoutQueryUpdate> = allUpdatesFlow.filterIsInstance()
|
||||||
override val pollFlow: Flow<PollUpdate> = allUpdatesFlow.filterIsInstance()
|
override val pollFlow: Flow<PollUpdate> = allUpdatesFlow.filterIsInstance()
|
||||||
override val pollAnswerFlow: Flow<PollAnswerUpdate> = allUpdatesFlow.filterIsInstance()
|
override val pollAnswerFlow: Flow<PollAnswerUpdate> = allUpdatesFlow.filterIsInstance()
|
||||||
|
override val chatMemberUpdatedFlow: Flow<CommonChatMemberUpdatedUpdate> = allUpdatesFlow.filterIsInstance()
|
||||||
|
override val myChatMemberUpdatedFlow: Flow<MyChatMemberUpdatedUpdate> = allUpdatesFlow.filterIsInstance()
|
||||||
override val unknownUpdateTypeFlow: Flow<UnknownUpdate> = allUpdatesFlow.filterIsInstance()
|
override val unknownUpdateTypeFlow: Flow<UnknownUpdate> = allUpdatesFlow.filterIsInstance()
|
||||||
}
|
}
|
||||||
@@ -35,4 +35,4 @@ const val lowLevelRiskFeatureMessage = "This method is low-level and not recomme
|
|||||||
AnnotationTarget.TYPEALIAS,
|
AnnotationTarget.TYPEALIAS,
|
||||||
AnnotationTarget.TYPE_PARAMETER
|
AnnotationTarget.TYPE_PARAMETER
|
||||||
)
|
)
|
||||||
annotation class RiskFeature(val message: String)
|
annotation class RiskFeature(val message: String = lowLevelRiskFeatureMessage)
|
||||||
|
|||||||
@@ -37,8 +37,6 @@ data class StorageFile(
|
|||||||
) {
|
) {
|
||||||
val input: Input
|
val input: Input
|
||||||
get() = inputSource()
|
get() = inputSource()
|
||||||
@Deprecated("This method will be fully replaced with input property", ReplaceWith("input"))
|
|
||||||
fun asInput() = input
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("NOTHING_TO_INLINE")
|
@Suppress("NOTHING_TO_INLINE")
|
||||||
|
|||||||
@@ -1,97 +0,0 @@
|
|||||||
package dev.inmo.tgbotapi.utils.internal
|
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.CommonAbstracts.*
|
|
||||||
import dev.inmo.tgbotapi.types.ParseMode.*
|
|
||||||
import dev.inmo.tgbotapi.types.captionLength
|
|
||||||
import dev.inmo.tgbotapi.types.message.content.TextContent
|
|
||||||
import dev.inmo.tgbotapi.types.textLength
|
|
||||||
|
|
||||||
internal fun createFormattedText(
|
|
||||||
entities: TextSourcesList,
|
|
||||||
partLength: Int = textLength.last,
|
|
||||||
mode: ParseMode = MarkdownParseMode
|
|
||||||
): List<String> {
|
|
||||||
val texts = mutableListOf<String>()
|
|
||||||
val textBuilder = StringBuilder(partLength)
|
|
||||||
for (entity in entities) {
|
|
||||||
val string = when (mode) {
|
|
||||||
is MarkdownParseMode -> entity.markdown
|
|
||||||
is MarkdownV2ParseMode -> entity.markdownV2
|
|
||||||
is HTMLParseMode -> entity.html
|
|
||||||
}
|
|
||||||
if (textBuilder.length + string.length > partLength) {
|
|
||||||
if (textBuilder.isNotEmpty()) {
|
|
||||||
texts.add(textBuilder.toString())
|
|
||||||
textBuilder.clear()
|
|
||||||
}
|
|
||||||
val chunked = string.chunked(partLength)
|
|
||||||
val last = chunked.last()
|
|
||||||
textBuilder.append(last)
|
|
||||||
val listToAdd = if (chunked.size > 1) {
|
|
||||||
chunked.subList(0, chunked.size - 1)
|
|
||||||
} else {
|
|
||||||
emptyList()
|
|
||||||
}
|
|
||||||
listToAdd.forEach {
|
|
||||||
texts.add(it)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
textBuilder.append(string)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (textBuilder.isNotEmpty()) {
|
|
||||||
texts.add(textBuilder.toString())
|
|
||||||
textBuilder.clear()
|
|
||||||
}
|
|
||||||
return texts
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
internal fun createMarkdownText(
|
|
||||||
entities: TextSourcesList,
|
|
||||||
partLength: Int = textLength.last
|
|
||||||
): List<String> = createFormattedText(entities, partLength, MarkdownParseMode)
|
|
||||||
|
|
||||||
internal fun TextSourcesList.toMarkdownTexts(): List<String> = createMarkdownText(
|
|
||||||
this,
|
|
||||||
textLength.last
|
|
||||||
)
|
|
||||||
internal fun TextContent.toMarkdownTexts(): List<String> = textSources.toMarkdownTexts()
|
|
||||||
|
|
||||||
|
|
||||||
internal fun createMarkdownV2Text(
|
|
||||||
entities: TextSourcesList,
|
|
||||||
partLength: Int = textLength.last
|
|
||||||
): List<String> = createFormattedText(entities, partLength, MarkdownV2ParseMode)
|
|
||||||
|
|
||||||
internal fun TextSourcesList.toMarkdownV2Captions(): List<String> = createMarkdownV2Text(
|
|
||||||
this,
|
|
||||||
captionLength.last
|
|
||||||
)
|
|
||||||
internal fun CaptionedInput.toMarkdownV2Captions(): List<String> = textSources.toMarkdownV2Captions()
|
|
||||||
|
|
||||||
internal fun TextSourcesList.toMarkdownV2Texts(): List<String> = createMarkdownV2Text(
|
|
||||||
this,
|
|
||||||
textLength.last
|
|
||||||
)
|
|
||||||
internal fun TextContent.toMarkdownV2Texts(): List<String> = textSources.toMarkdownV2Texts()
|
|
||||||
|
|
||||||
|
|
||||||
internal fun createHtmlText(
|
|
||||||
entities: TextSourcesList,
|
|
||||||
partLength: Int = textLength.last
|
|
||||||
): List<String> = createFormattedText(entities, partLength, HTMLParseMode)
|
|
||||||
|
|
||||||
internal fun TextSourcesList.toHtmlCaptions(): List<String> = createHtmlText(
|
|
||||||
this,
|
|
||||||
captionLength.last
|
|
||||||
)
|
|
||||||
internal fun CaptionedInput.toHtmlCaptions(): List<String> = textSources.toHtmlCaptions()
|
|
||||||
|
|
||||||
internal fun TextSourcesList.toHtmlTexts(): List<String> = createHtmlText(
|
|
||||||
this,
|
|
||||||
textLength.last
|
|
||||||
)
|
|
||||||
internal fun TextContent.toHtmlTexts(): List<String> = textSources.toHtmlTexts()
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,14 +1,7 @@
|
|||||||
package dev.inmo.tgbotapi.utils.passport
|
package dev.inmo.tgbotapi.utils.passport
|
||||||
|
|
||||||
import dev.inmo.micro_utils.crypto.SourceBytes
|
import dev.inmo.micro_utils.crypto.SourceBytes
|
||||||
import dev.inmo.tgbotapi.bot.TelegramBot
|
|
||||||
import dev.inmo.tgbotapi.requests.DownloadFile
|
|
||||||
import dev.inmo.tgbotapi.requests.get.GetFile
|
|
||||||
import dev.inmo.tgbotapi.types.passport.credentials.EncryptedCredentials
|
|
||||||
import dev.inmo.tgbotapi.types.passport.credentials.EncryptedData
|
import dev.inmo.tgbotapi.types.passport.credentials.EncryptedData
|
||||||
import dev.inmo.tgbotapi.types.passport.encrypted.PassportFile
|
|
||||||
import dev.inmo.tgbotapi.utils.nonstrictJsonFormat
|
|
||||||
import kotlinx.serialization.json.JsonObject
|
|
||||||
|
|
||||||
interface Decryptor {
|
interface Decryptor {
|
||||||
fun decrypt(data: EncryptedData): SourceBytes
|
fun decrypt(data: EncryptedData): SourceBytes
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ package dev.inmo.tgbotapi.types.MessageEntity
|
|||||||
|
|
||||||
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
|
import dev.inmo.tgbotapi.CommonAbstracts.TextSource
|
||||||
import dev.inmo.tgbotapi.CommonAbstracts.plus
|
import dev.inmo.tgbotapi.CommonAbstracts.plus
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.formatting.*
|
||||||
import dev.inmo.tgbotapi.types.MessageEntity.textsources.*
|
import dev.inmo.tgbotapi.types.MessageEntity.textsources.*
|
||||||
import dev.inmo.tgbotapi.utils.internal.*
|
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package dev.inmo.tgbotapi.types.MessageEntity
|
package dev.inmo.tgbotapi.types.MessageEntity
|
||||||
|
|
||||||
import dev.inmo.tgbotapi.CommonAbstracts.justTextSources
|
import dev.inmo.tgbotapi.CommonAbstracts.justTextSources
|
||||||
import dev.inmo.tgbotapi.utils.internal.toHtmlTexts
|
import dev.inmo.tgbotapi.extensions.utils.formatting.toHtmlTexts
|
||||||
import dev.inmo.tgbotapi.utils.internal.toMarkdownV2Texts
|
import dev.inmo.tgbotapi.extensions.utils.formatting.toMarkdownV2Texts
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
|||||||
@@ -4,11 +4,10 @@ import dev.inmo.micro_utils.crypto.decodeBase64
|
|||||||
import dev.inmo.tgbotapi.types.passport.credentials.DecryptedCredentials
|
import dev.inmo.tgbotapi.types.passport.credentials.DecryptedCredentials
|
||||||
import dev.inmo.tgbotapi.types.passport.credentials.EncryptedCredentials
|
import dev.inmo.tgbotapi.types.passport.credentials.EncryptedCredentials
|
||||||
import dev.inmo.tgbotapi.utils.nonstrictJsonFormat
|
import dev.inmo.tgbotapi.utils.nonstrictJsonFormat
|
||||||
import java.security.*
|
import java.security.KeyFactory
|
||||||
|
import java.security.PrivateKey
|
||||||
import java.security.spec.PKCS8EncodedKeySpec
|
import java.security.spec.PKCS8EncodedKeySpec
|
||||||
import javax.crypto.Cipher
|
import javax.crypto.Cipher
|
||||||
import javax.crypto.spec.IvParameterSpec
|
|
||||||
import javax.crypto.spec.SecretKeySpec
|
|
||||||
|
|
||||||
private val regexToRemoveFromKey = Regex("(-----(BEGIN|END) ((?:.*? KEY)|CERTIFICATE)-----|[\\s])")
|
private val regexToRemoveFromKey = Regex("(-----(BEGIN|END) ((?:.*? KEY)|CERTIFICATE)-----|[\\s])")
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,9 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
kotlin {
|
kotlin {
|
||||||
jvm()
|
jvm {
|
||||||
|
compilations.main.kotlinOptions.useIR = true
|
||||||
|
}
|
||||||
js(BOTH) {
|
js(BOTH) {
|
||||||
browser()
|
browser()
|
||||||
nodejs()
|
nodejs()
|
||||||
|
|||||||
@@ -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 Extensions for API","description":"API extensions which provide work with RequestsExecutor of TelegramBotAPI almost like it is described in original Telegram Bot API reference","url":"https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI-extensions-api","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 Extensions for API","description":"API extensions which provide work with RequestsExecutor of TelegramBotAPI almost like it is described in original Telegram Bot API reference","url":"https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI-extensions-api","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) {
|
task javadocsJar(type: Jar) {
|
||||||
classifier = 'javadoc'
|
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 {
|
publishing {
|
||||||
publications.all {
|
publications.all {
|
||||||
@@ -54,22 +38,32 @@ publishing {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
maven {
|
if ((project.hasProperty('GITHUBPACKAGES_USER') || System.getenv('GITHUBPACKAGES_USER') != null) && (project.hasProperty('GITHUBPACKAGES_PASSWORD') || System.getenv('GITHUBPACKAGES_PASSWORD') != null)) {
|
||||||
name = "bintray"
|
maven {
|
||||||
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")
|
name = "GithubPackages"
|
||||||
credentials {
|
url = uri("https://maven.pkg.github.com/InsanusMokrassar/TelegramBotAPI")
|
||||||
username = project.hasProperty('BINTRAY_USER') ? project.property('BINTRAY_USER') : System.getenv('BINTRAY_USER')
|
credentials {
|
||||||
password = project.hasProperty('BINTRAY_KEY') ? project.property('BINTRAY_KEY') : System.getenv('BINTRAY_KEY')
|
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 {
|
signing {
|
||||||
useGpgCmd()
|
useGpgCmd()
|
||||||
publishing.publications.forEach { sign it }
|
sign publishing.publications
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package dev.inmo.tgbotapi.extensions.api.chat.invite_links
|
||||||
|
|
||||||
|
import com.soywiz.klock.DateTime
|
||||||
|
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||||
|
import dev.inmo.tgbotapi.requests.chat.invite_links.CreateChatInviteLink
|
||||||
|
import dev.inmo.tgbotapi.types.*
|
||||||
|
import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat
|
||||||
|
|
||||||
|
suspend fun TelegramBot.createChatInviteLink(
|
||||||
|
chatId: ChatIdentifier,
|
||||||
|
expiration: TelegramDate? = null,
|
||||||
|
membersLimit: MembersLimit? = null
|
||||||
|
) = execute(CreateChatInviteLink(chatId, expiration, membersLimit))
|
||||||
|
|
||||||
|
suspend fun TelegramBot.createChatInviteLink(
|
||||||
|
chat: PublicChat,
|
||||||
|
expiration: TelegramDate? = null,
|
||||||
|
membersLimit: MembersLimit? = null
|
||||||
|
) = createChatInviteLink(chat.id, expiration, membersLimit)
|
||||||
|
|
||||||
|
suspend fun TelegramBot.createChatInviteLink(
|
||||||
|
chatId: ChatIdentifier,
|
||||||
|
expiration: DateTime,
|
||||||
|
membersLimit: MembersLimit? = null
|
||||||
|
) = createChatInviteLink(chatId, expiration.toTelegramDate(), membersLimit)
|
||||||
|
|
||||||
|
suspend fun TelegramBot.createChatInviteLink(
|
||||||
|
chat: PublicChat,
|
||||||
|
expiration: DateTime,
|
||||||
|
membersLimit: MembersLimit? = null
|
||||||
|
) = createChatInviteLink(chat.id, expiration.toTelegramDate(), membersLimit)
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
package dev.inmo.tgbotapi.extensions.api.chat.invite_links
|
||||||
|
|
||||||
|
import com.soywiz.klock.DateTime
|
||||||
|
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||||
|
import dev.inmo.tgbotapi.requests.chat.invite_links.EditChatInviteLink
|
||||||
|
import dev.inmo.tgbotapi.types.*
|
||||||
|
import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat
|
||||||
|
|
||||||
|
suspend fun TelegramBot.editChatInviteLink(
|
||||||
|
chatId: ChatIdentifier,
|
||||||
|
previousLink: String,
|
||||||
|
expiration: TelegramDate? = null,
|
||||||
|
membersLimit: MembersLimit? = null
|
||||||
|
) = execute(EditChatInviteLink(chatId, previousLink, expiration, membersLimit))
|
||||||
|
|
||||||
|
suspend fun TelegramBot.editChatInviteLink(
|
||||||
|
chat: PublicChat,
|
||||||
|
previousLink: String,
|
||||||
|
expiration: TelegramDate? = null,
|
||||||
|
membersLimit: MembersLimit? = null
|
||||||
|
) = editChatInviteLink(chat.id, previousLink, expiration, membersLimit)
|
||||||
|
|
||||||
|
suspend fun TelegramBot.editChatInviteLink(
|
||||||
|
chatId: ChatIdentifier,
|
||||||
|
previousLink: String,
|
||||||
|
expiration: DateTime,
|
||||||
|
membersLimit: MembersLimit? = null
|
||||||
|
) = editChatInviteLink(chatId, previousLink, expiration.toTelegramDate(), membersLimit)
|
||||||
|
|
||||||
|
suspend fun TelegramBot.editChatInviteLink(
|
||||||
|
chat: PublicChat,
|
||||||
|
previousLink: String,
|
||||||
|
expiration: DateTime,
|
||||||
|
membersLimit: MembersLimit? = null
|
||||||
|
) = editChatInviteLink(chat.id, previousLink, expiration.toTelegramDate(), membersLimit)
|
||||||
|
|
||||||
|
suspend fun TelegramBot.editChatInviteLink(
|
||||||
|
chat: ChatIdentifier,
|
||||||
|
previousLink: ChatInviteLink,
|
||||||
|
expiration: TelegramDate? = previousLink.expirationDateTime ?.toTelegramDate(),
|
||||||
|
membersLimit: MembersLimit? = previousLink.membersLimit
|
||||||
|
) = editChatInviteLink(chat, previousLink.inviteLink, expiration, membersLimit)
|
||||||
|
|
||||||
|
suspend fun TelegramBot.editChatInviteLink(
|
||||||
|
chat: ChatIdentifier,
|
||||||
|
previousLink: ChatInviteLink,
|
||||||
|
expiration: DateTime,
|
||||||
|
membersLimit: MembersLimit? = previousLink.membersLimit
|
||||||
|
) = editChatInviteLink(chat, previousLink.inviteLink, expiration, membersLimit)
|
||||||
|
|
||||||
|
suspend fun TelegramBot.editChatInviteLink(
|
||||||
|
chat: PublicChat,
|
||||||
|
previousLink: ChatInviteLink,
|
||||||
|
expiration: TelegramDate? = previousLink.expirationDateTime ?.toTelegramDate(),
|
||||||
|
membersLimit: MembersLimit? = previousLink.membersLimit
|
||||||
|
) = editChatInviteLink(chat, previousLink.inviteLink, expiration, membersLimit)
|
||||||
|
|
||||||
|
suspend fun TelegramBot.editChatInviteLink(
|
||||||
|
chat: PublicChat,
|
||||||
|
previousLink: ChatInviteLink,
|
||||||
|
expiration: DateTime,
|
||||||
|
membersLimit: MembersLimit? = previousLink.membersLimit
|
||||||
|
) = editChatInviteLink(chat, previousLink.inviteLink, expiration, membersLimit)
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package dev.inmo.tgbotapi.extensions.api.chat.invite_links
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||||
|
import dev.inmo.tgbotapi.requests.chat.invite_links.RevokeChatInviteLink
|
||||||
|
import dev.inmo.tgbotapi.types.ChatIdentifier
|
||||||
|
import dev.inmo.tgbotapi.types.ChatInviteLink
|
||||||
|
import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat
|
||||||
|
|
||||||
|
suspend fun TelegramBot.revokeChatInviteLink(
|
||||||
|
chatId: ChatIdentifier,
|
||||||
|
previousLink: String
|
||||||
|
) = execute(RevokeChatInviteLink(chatId, previousLink))
|
||||||
|
|
||||||
|
suspend fun TelegramBot.revokeChatInviteLink(
|
||||||
|
chat: PublicChat,
|
||||||
|
previousLink: String
|
||||||
|
) = revokeChatInviteLink(chat.id, previousLink)
|
||||||
|
|
||||||
|
suspend fun TelegramBot.revokeChatInviteLink(
|
||||||
|
chatId: ChatIdentifier,
|
||||||
|
previousLink: ChatInviteLink
|
||||||
|
) = revokeChatInviteLink(chatId, previousLink.inviteLink)
|
||||||
|
|
||||||
|
suspend fun TelegramBot.revokeChatInviteLink(
|
||||||
|
chat: PublicChat,
|
||||||
|
previousLink: ChatInviteLink
|
||||||
|
) = revokeChatInviteLink(chat, previousLink.inviteLink)
|
||||||
@@ -8,23 +8,27 @@ import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat
|
|||||||
suspend fun TelegramBot.kickChatMember(
|
suspend fun TelegramBot.kickChatMember(
|
||||||
chatId: ChatIdentifier,
|
chatId: ChatIdentifier,
|
||||||
userId: UserId,
|
userId: UserId,
|
||||||
untilDate: TelegramDate? = null
|
untilDate: TelegramDate? = null,
|
||||||
) = execute(KickChatMember(chatId, userId, untilDate))
|
revokeMessages: Boolean? = null
|
||||||
|
) = execute(KickChatMember(chatId, userId, untilDate, revokeMessages))
|
||||||
|
|
||||||
suspend fun TelegramBot.kickChatMember(
|
suspend fun TelegramBot.kickChatMember(
|
||||||
chat: PublicChat,
|
chat: PublicChat,
|
||||||
userId: UserId,
|
userId: UserId,
|
||||||
untilDate: TelegramDate? = null
|
untilDate: TelegramDate? = null,
|
||||||
) = kickChatMember(chat.id, userId, untilDate)
|
revokeMessages: Boolean? = null
|
||||||
|
) = kickChatMember(chat.id, userId, untilDate, revokeMessages)
|
||||||
|
|
||||||
suspend fun TelegramBot.kickChatMember(
|
suspend fun TelegramBot.kickChatMember(
|
||||||
chatId: ChatId,
|
chatId: ChatId,
|
||||||
user: User,
|
user: User,
|
||||||
untilDate: TelegramDate? = null
|
untilDate: TelegramDate? = null,
|
||||||
) = kickChatMember(chatId, user.id, untilDate)
|
revokeMessages: Boolean? = null
|
||||||
|
) = kickChatMember(chatId, user.id, untilDate, revokeMessages)
|
||||||
|
|
||||||
suspend fun TelegramBot.kickChatMember(
|
suspend fun TelegramBot.kickChatMember(
|
||||||
chat: PublicChat,
|
chat: PublicChat,
|
||||||
user: User,
|
user: User,
|
||||||
untilDate: TelegramDate? = null
|
untilDate: TelegramDate? = null,
|
||||||
) = kickChatMember(chat.id, user.id, untilDate)
|
revokeMessages: Boolean? = null
|
||||||
|
) = kickChatMember(chat.id, user.id, untilDate, revokeMessages)
|
||||||
|
|||||||
@@ -17,7 +17,9 @@ suspend fun TelegramBot.promoteChatMember(
|
|||||||
canInviteUsers: Boolean? = null,
|
canInviteUsers: Boolean? = null,
|
||||||
canRestrictMembers: Boolean? = null,
|
canRestrictMembers: Boolean? = null,
|
||||||
canPinMessages: Boolean? = null,
|
canPinMessages: Boolean? = null,
|
||||||
canPromoteMembers: Boolean? = null
|
canPromoteMembers: Boolean? = null,
|
||||||
|
canManageVoiceChats: Boolean? = null,
|
||||||
|
canManageChat: Boolean?
|
||||||
) = execute(
|
) = execute(
|
||||||
PromoteChatMember(
|
PromoteChatMember(
|
||||||
chatId,
|
chatId,
|
||||||
@@ -31,7 +33,9 @@ suspend fun TelegramBot.promoteChatMember(
|
|||||||
canInviteUsers,
|
canInviteUsers,
|
||||||
canRestrictMembers,
|
canRestrictMembers,
|
||||||
canPinMessages,
|
canPinMessages,
|
||||||
canPromoteMembers
|
canPromoteMembers,
|
||||||
|
canManageVoiceChats,
|
||||||
|
canManageChat
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -47,7 +51,9 @@ suspend fun TelegramBot.promoteChatMember(
|
|||||||
canInviteUsers: Boolean? = null,
|
canInviteUsers: Boolean? = null,
|
||||||
canRestrictMembers: Boolean? = null,
|
canRestrictMembers: Boolean? = null,
|
||||||
canPinMessages: Boolean? = null,
|
canPinMessages: Boolean? = null,
|
||||||
canPromoteMembers: Boolean? = null
|
canPromoteMembers: Boolean? = null,
|
||||||
|
canManageVoiceChats: Boolean? = null,
|
||||||
|
canManageChat: Boolean? = null
|
||||||
) = promoteChatMember(
|
) = promoteChatMember(
|
||||||
chat.id,
|
chat.id,
|
||||||
userId,
|
userId,
|
||||||
@@ -60,7 +66,9 @@ suspend fun TelegramBot.promoteChatMember(
|
|||||||
canInviteUsers,
|
canInviteUsers,
|
||||||
canRestrictMembers,
|
canRestrictMembers,
|
||||||
canPinMessages,
|
canPinMessages,
|
||||||
canPromoteMembers
|
canPromoteMembers,
|
||||||
|
canManageVoiceChats,
|
||||||
|
canManageChat
|
||||||
)
|
)
|
||||||
|
|
||||||
suspend fun TelegramBot.promoteChatMember(
|
suspend fun TelegramBot.promoteChatMember(
|
||||||
@@ -75,7 +83,9 @@ suspend fun TelegramBot.promoteChatMember(
|
|||||||
canInviteUsers: Boolean? = null,
|
canInviteUsers: Boolean? = null,
|
||||||
canRestrictMembers: Boolean? = null,
|
canRestrictMembers: Boolean? = null,
|
||||||
canPinMessages: Boolean? = null,
|
canPinMessages: Boolean? = null,
|
||||||
canPromoteMembers: Boolean? = null
|
canPromoteMembers: Boolean? = null,
|
||||||
|
canManageVoiceChats: Boolean? = null,
|
||||||
|
canManageChat: Boolean? = null
|
||||||
) = promoteChatMember(
|
) = promoteChatMember(
|
||||||
chatId,
|
chatId,
|
||||||
user.id,
|
user.id,
|
||||||
@@ -88,7 +98,9 @@ suspend fun TelegramBot.promoteChatMember(
|
|||||||
canInviteUsers,
|
canInviteUsers,
|
||||||
canRestrictMembers,
|
canRestrictMembers,
|
||||||
canPinMessages,
|
canPinMessages,
|
||||||
canPromoteMembers
|
canPromoteMembers,
|
||||||
|
canManageVoiceChats,
|
||||||
|
canManageChat
|
||||||
)
|
)
|
||||||
|
|
||||||
suspend fun TelegramBot.promoteChatMember(
|
suspend fun TelegramBot.promoteChatMember(
|
||||||
@@ -103,7 +115,9 @@ suspend fun TelegramBot.promoteChatMember(
|
|||||||
canInviteUsers: Boolean? = null,
|
canInviteUsers: Boolean? = null,
|
||||||
canRestrictMembers: Boolean? = null,
|
canRestrictMembers: Boolean? = null,
|
||||||
canPinMessages: Boolean? = null,
|
canPinMessages: Boolean? = null,
|
||||||
canPromoteMembers: Boolean? = null
|
canPromoteMembers: Boolean? = null,
|
||||||
|
canManageVoiceChats: Boolean? = null,
|
||||||
|
canManageChat: Boolean? = null
|
||||||
) = promoteChatMember(
|
) = promoteChatMember(
|
||||||
chat.id,
|
chat.id,
|
||||||
user.id,
|
user.id,
|
||||||
@@ -116,5 +130,7 @@ suspend fun TelegramBot.promoteChatMember(
|
|||||||
canInviteUsers,
|
canInviteUsers,
|
||||||
canRestrictMembers,
|
canRestrictMembers,
|
||||||
canPinMessages,
|
canPinMessages,
|
||||||
canPromoteMembers
|
canPromoteMembers,
|
||||||
|
canManageVoiceChats,
|
||||||
|
canManageChat
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package dev.inmo.tgbotapi.extensions.api.send
|
||||||
|
|
||||||
|
import dev.inmo.micro_utils.coroutines.safely
|
||||||
|
import dev.inmo.micro_utils.coroutines.safelyWithoutExceptions
|
||||||
|
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||||
|
import dev.inmo.tgbotapi.requests.send.SendAction
|
||||||
|
import dev.inmo.tgbotapi.types.*
|
||||||
|
import dev.inmo.tgbotapi.types.actions.*
|
||||||
|
import dev.inmo.tgbotapi.types.chat.abstracts.Chat
|
||||||
|
import kotlinx.coroutines.*
|
||||||
|
|
||||||
|
private const val refreshTime: MilliSeconds = (botActionActualityTime - 1) * 1000L
|
||||||
|
typealias TelegramBotActionCallback<T> = suspend TelegramBot.() -> T
|
||||||
|
|
||||||
|
suspend fun <T> TelegramBot.withAction(
|
||||||
|
actionRequest: SendAction,
|
||||||
|
block: TelegramBotActionCallback<T>
|
||||||
|
): T {
|
||||||
|
val botActionJob = supervisorScope {
|
||||||
|
launch {
|
||||||
|
while (isActive) {
|
||||||
|
delay(refreshTime)
|
||||||
|
safelyWithoutExceptions {
|
||||||
|
execute(actionRequest)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return try {
|
||||||
|
safely { block() }
|
||||||
|
} finally {
|
||||||
|
botActionJob.cancel()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun <T> TelegramBot.withAction(
|
||||||
|
chatId: ChatId,
|
||||||
|
action: BotAction,
|
||||||
|
block: TelegramBotActionCallback<T>
|
||||||
|
) = withAction(
|
||||||
|
SendAction(chatId, action),
|
||||||
|
block
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun <T> TelegramBot.withAction(
|
||||||
|
chat: Chat,
|
||||||
|
action: BotAction,
|
||||||
|
block: TelegramBotActionCallback<T>
|
||||||
|
) = withAction(
|
||||||
|
chat.id,
|
||||||
|
action,
|
||||||
|
block
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun <T> TelegramBot.withTypingAction(chatId: ChatId, block: TelegramBotActionCallback<T>) = withAction(chatId, TypingAction, block)
|
||||||
|
suspend fun <T> TelegramBot.withUploadPhotoAction(chatId: ChatId, block: TelegramBotActionCallback<T>) = withAction(chatId, UploadPhotoAction, block)
|
||||||
|
suspend fun <T> TelegramBot.withRecordVideoAction(chatId: ChatId, block: TelegramBotActionCallback<T>) = withAction(chatId, RecordVideoAction, block)
|
||||||
|
suspend fun <T> TelegramBot.withUploadVideoAction(chatId: ChatId, block: TelegramBotActionCallback<T>) = withAction(chatId, UploadVideoAction, block)
|
||||||
|
suspend fun <T> TelegramBot.withRecordAudioAction(chatId: ChatId, block: TelegramBotActionCallback<T>) = withAction(chatId, RecordAudioAction, block)
|
||||||
|
suspend fun <T> TelegramBot.withUploadAudioAction(chatId: ChatId, block: TelegramBotActionCallback<T>) = withAction(chatId, UploadAudioAction, block)
|
||||||
|
suspend fun <T> TelegramBot.withUploadDocumentAction(chatId: ChatId, block: TelegramBotActionCallback<T>) = withAction(chatId, UploadDocumentAction, block)
|
||||||
|
suspend fun <T> TelegramBot.withFindLocationAction(chatId: ChatId, block: TelegramBotActionCallback<T>) = withAction(chatId, FindLocationAction, block)
|
||||||
|
suspend fun <T> TelegramBot.withRecordVideoNoteAction(chatId: ChatId, block: TelegramBotActionCallback<T>) = withAction(chatId, RecordVideoNoteAction, block)
|
||||||
|
suspend fun <T> TelegramBot.withUploadVideoNoteAction(chatId: ChatId, block: TelegramBotActionCallback<T>) = withAction(chatId, UploadVideoNoteAction, block)
|
||||||
|
|
||||||
|
|
||||||
|
suspend fun <T> TelegramBot.withTypingAction(chat: Chat, block: TelegramBotActionCallback<T>) = withAction(chat, TypingAction, block)
|
||||||
|
suspend fun <T> TelegramBot.withUploadPhotoAction(chat: Chat, block: TelegramBotActionCallback<T>) = withAction(chat, UploadPhotoAction, block)
|
||||||
|
suspend fun <T> TelegramBot.withRecordVideoAction(chat: Chat, block: TelegramBotActionCallback<T>) = withAction(chat, RecordVideoAction, block)
|
||||||
|
suspend fun <T> TelegramBot.withUploadVideoAction(chat: Chat, block: TelegramBotActionCallback<T>) = withAction(chat, UploadVideoAction, block)
|
||||||
|
suspend fun <T> TelegramBot.withRecordAudioAction(chat: Chat, block: TelegramBotActionCallback<T>) = withAction(chat, RecordAudioAction, block)
|
||||||
|
suspend fun <T> TelegramBot.withUploadAudioAction(chat: Chat, block: TelegramBotActionCallback<T>) = withAction(chat, UploadAudioAction, block)
|
||||||
|
suspend fun <T> TelegramBot.withUploadDocumentAction(chat: Chat, block: TelegramBotActionCallback<T>) = withAction(chat, UploadDocumentAction, block)
|
||||||
|
suspend fun <T> TelegramBot.withFindLocationAction(chat: Chat, block: TelegramBotActionCallback<T>) = withAction(chat, FindLocationAction, block)
|
||||||
|
suspend fun <T> TelegramBot.withRecordVideoNoteAction(chat: Chat, block: TelegramBotActionCallback<T>) = withAction(chat, RecordVideoNoteAction, block)
|
||||||
|
suspend fun <T> TelegramBot.withUploadVideoNoteAction(chat: Chat, block: TelegramBotActionCallback<T>) = withAction(chat, UploadVideoNoteAction, block)
|
||||||
@@ -29,10 +29,18 @@ suspend fun TelegramBot.sendDice(
|
|||||||
replyMarkup: KeyboardMarkup? = null
|
replyMarkup: KeyboardMarkup? = null
|
||||||
) = sendDice(chat.id, animationType, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup)
|
) = sendDice(chat.id, animationType, disableNotification, replyToMessageId, allowSendingWithoutReply, replyMarkup)
|
||||||
|
|
||||||
suspend inline fun TelegramBot.reply(
|
suspend inline fun TelegramBot.replyWithDice(
|
||||||
to: Message,
|
to: Message,
|
||||||
animationType: DiceAnimationType? = null,
|
animationType: DiceAnimationType? = null,
|
||||||
disableNotification: Boolean = false,
|
disableNotification: Boolean = false,
|
||||||
allowSendingWithoutReply: Boolean? = null,
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
replyMarkup: KeyboardMarkup? = null
|
replyMarkup: KeyboardMarkup? = null
|
||||||
) = sendDice(to.chat, animationType, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup)
|
) = sendDice(to.chat, animationType, disableNotification, to.messageId, allowSendingWithoutReply, replyMarkup)
|
||||||
|
|
||||||
|
suspend inline fun TelegramBot.reply(
|
||||||
|
to: Message,
|
||||||
|
animationType: DiceAnimationType? = null,
|
||||||
|
disableNotification: Boolean = false,
|
||||||
|
allowSendingWithoutReply: Boolean? = null,
|
||||||
|
replyMarkup: KeyboardMarkup? = null
|
||||||
|
) = replyWithDice(to, animationType, disableNotification, allowSendingWithoutReply, replyMarkup)
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user