1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2026-01-09 23:09:24 +00:00

Compare commits

..

92 Commits

Author SHA1 Message Date
602f15c206 Update README.md 2022-04-01 00:01:25 +06:00
c2f40534e6 Update README.md 2022-03-31 23:55:34 +06:00
5693d4d808 Merge pull request #548 from InsanusMokrassar/0.38.11
0.38.11
2022-03-29 23:40:04 +06:00
9fe55aa6ef Update CHANGELOG.md 2022-03-29 12:42:02 +06:00
8f817f1492 reply with any media file 2022-03-29 12:37:54 +06:00
0fd146655d old matrix and row deprecation 2022-03-29 12:27:03 +06:00
94e5f74a90 reply with content 2022-03-29 12:20:52 +06:00
b9bffbb71b update dependencies 2022-03-27 13:47:38 +06:00
5ec5c3bdfd Fixes in "TextSourcesList" creating in from "RawMessageEntities" 2022-03-27 13:44:41 +06:00
a5ed2a82bb start 0.38.11 2022-03-27 13:36:21 +06:00
1b7dd11e75 Merge pull request #545 from InsanusMokrassar/0.38.10
0.38.10
2022-03-25 10:36:21 +06:00
8d0307fb7f update github building yml 2022-03-24 16:49:08 +06:00
c500f0a281 update reply and sendPhoto with PhotoSize 2022-03-24 16:47:07 +06:00
b3abeaa5ae Update packages_publishing.yml 2022-03-23 17:03:08 +06:00
8930a66134 with*Action block called once 2022-03-23 11:48:20 +06:00
76a2a2ca74 start 0.38.10 2022-03-23 05:06:48 +06:00
7dff8af460 Update gradle.properties 2022-03-23 05:01:09 +06:00
5261ab1cf0 start 0.38.10 2022-03-23 05:00:28 +06:00
f45c653fca Merge pull request #544 from InsanusMokrassar/0.38.9
0.38.9
2022-03-22 19:06:29 +06:00
5e03098ca8 fill changelog 2022-03-22 19:06:02 +06:00
2a3d8e6e73 publication scripts update 2022-03-22 16:26:18 +06:00
8c3dac7932 signature clashes fixes 2022-03-21 23:23:19 +06:00
83fb7f7bcb add opportunity to use several bots in one to serve bots requests 2022-03-21 23:06:23 +06:00
459414e7dd add RistFeature to SerializationModule 2022-03-21 17:03:37 +06:00
508d51f5a9 reply with copyMessage 2022-03-20 12:14:26 +06:00
36f22579b2 add MessageContent.Companion#serializationModule 2022-03-20 11:52:29 +06:00
d3d5f7f2e6 start 0.38.9 2022-03-20 11:50:52 +06:00
1369680419 Merge pull request #543 from InsanusMokrassar/0.38.8
0.38.8
2022-03-19 21:15:03 +06:00
f6e819be62 simpleFilter to list wrapper 2022-03-19 12:49:14 +06:00
553da0a3ee update dependencies and fill changelog 2022-03-19 12:27:46 +06:00
bace2724da a little bit refactor MediaGroupTriggers.kt 2022-03-19 10:15:44 +06:00
be710612b5 Update MediaGroupTriggers.kt 2022-03-19 09:55:48 +06:00
ea19c10f41 start 0.38.8 2022-03-18 19:18:34 +06:00
1b88881c62 Update README.md 2022-03-14 02:50:38 +06:00
be62c4fe37 Merge pull request #540 from InsanusMokrassar/0.38.7
0.38.7
2022-03-12 14:32:20 +06:00
d3499cdde1 update microutils and fill changelog 2022-03-12 13:41:49 +06:00
01d04f9d2b Update gradle-wrapper.properties 2022-03-11 22:31:19 +06:00
d290992e40 Update gradle.properties 2022-03-11 22:30:52 +06:00
867bdb8bd7 Update CHANGELOG.md 2022-03-08 00:18:25 +06:00
5f0a67187f add default votes in SimplePollOption 2022-03-08 00:15:29 +06:00
d9638849e2 update dependencies 2022-03-07 12:44:55 +06:00
5568720b5b start 0.38.7 2022-03-07 12:44:08 +06:00
c0c591fe08 Merge pull request #535 from InsanusMokrassar/0.38.6
0.38.6
2022-02-27 22:22:04 +06:00
3c1f8421c9 Update CHANGELOG.md 2022-02-27 10:04:28 +06:00
35b20d102c Update gradle.properties 2022-02-26 22:01:41 +06:00
70e6dc8fc9 update dependencies 2022-02-19 23:07:30 +06:00
4f0de376ab MentionTextSource#username 2022-02-19 23:02:58 +06:00
10c52c695c start 0.38.6 2022-02-19 22:54:41 +06:00
2d2c745527 Merge pull request #532 from InsanusMokrassar/0.38.5
0.38.5
2022-02-08 16:53:27 +06:00
1238843bde update dependencies 2022-02-08 16:50:38 +06:00
1ebaa1c387 deeplinking fixes and additions 2022-02-07 18:08:06 +06:00
b2bc47ec04 start 0.38.5 2022-02-07 18:00:13 +06:00
514620b2bd Merge pull request #530 from InsanusMokrassar/0.38.4
0.38.4
2022-02-02 10:05:11 +06:00
054f06e18b Update gradle.properties 2022-02-01 23:39:07 +06:00
00d467d091 classcasts and raw fields updates 2022-02-01 23:25:22 +06:00
6426ed6571 fixes 2022-02-01 23:05:47 +06:00
fba6707f44 fixes in create sticker set methods 2022-02-01 17:59:23 +06:00
0c2fe6bce7 support of Telegram Bot API 5.7 2022-02-01 16:23:26 +06:00
eee9fe439f fix of #529 2022-01-31 17:52:01 +06:00
3547c09383 start 0.38.4 2022-01-31 17:48:10 +06:00
956f02d26d Merge pull request #526 from InsanusMokrassar/0.38.3
0.38.3
2022-01-14 16:47:49 +06:00
468fc0a49b Update CHANGELOG.md 2022-01-14 16:31:57 +06:00
441f3cee3d Update gradle.properties 2022-01-14 16:31:19 +06:00
1ea79b9f7f update changelog 2022-01-13 19:01:17 +06:00
094f88867d Update gradle.properties 2022-01-13 13:52:49 +06:00
85a8a8eedc update dokka version 2022-01-12 13:02:23 +06:00
28fce0b4c1 New extensions "TelegramBot#send*" for media groups with contents 2022-01-12 11:39:35 +06:00
2f5fdcdca0 start 0.38.3 2022-01-12 11:37:34 +06:00
21799d7e4a add exceptions handling readme 2022-01-11 21:22:10 +06:00
ca409db0ee Merge pull request #525 from InsanusMokrassar/0.38.2
0.38.2
2022-01-10 23:08:50 +06:00
33c8ee0803 remove redundant copyMessage 2022-01-10 13:48:00 +06:00
0c0ec22348 update microutils dependency 2022-01-10 13:16:50 +06:00
24bffbbd97 addopportunity to copy messages using just content 2022-01-10 13:15:10 +06:00
a615d1c4fd copyMessages for media groups 2022-01-10 13:06:18 +06:00
a76b7977b3 start 0.38.2 2022-01-10 12:38:48 +06:00
6004879aef Merge pull request #524 from InsanusMokrassar/0.38.1
0.38.1
2022-01-07 13:37:06 +06:00
98ff2558e9 remove redundant dependency in utils 2022-01-07 13:32:34 +06:00
61c00b38b1 Update core publish scripts 2022-01-07 13:29:53 +06:00
2096671147 upfill raw extensions 2022-01-07 12:56:42 +06:00
094d58f59f upfill of changelog 2022-01-06 17:13:37 +06:00
578a66b758 fill changelog 2022-01-06 17:00:56 +06:00
b5bb40576b optimize imports of utils 2022-01-06 16:59:15 +06:00
953638ddf5 add raw fields for CallbackQuery 2022-01-06 16:57:51 +06:00
1c9ca7a493 add raw fields for ChosenInlineResult 2022-01-06 16:52:28 +06:00
c220412b02 add raw fields for InlineQuery 2022-01-06 16:45:50 +06:00
41852dde7c add raw fields for polls 2022-01-06 16:42:19 +06:00
3150cd6a37 fix build 2022-01-06 14:55:07 +06:00
07de18efd8 update changelog 2022-01-06 14:50:14 +06:00
9552550198 UserLoggedIn, additions in ClassCasts and partial fix of #511 2022-01-06 14:49:11 +06:00
e1c94f772d MessageCallbackQuery#message now is ContentMessage<MessageContent> 2022-01-06 13:54:22 +06:00
fbed81a1b3 start 0.38.1 2022-01-06 13:49:03 +06:00
b61912d99a Merge pull request #522 from InsanusMokrassar/0.38.0
0.38.0
2022-01-02 03:34:45 +06:00
105 changed files with 2535 additions and 813 deletions

View File

@@ -10,7 +10,7 @@ jobs:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: actions/setup-java@v1 - uses: actions/setup-java@v1
with: with:
java-version: 1.8 java-version: 11
- name: Build - name: Build
run: ./gradlew dokkaHtml run: ./gradlew dokkaHtml
- name: Publish KDocs - name: Publish KDocs

View File

@@ -7,10 +7,7 @@ jobs:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: actions/setup-java@v1 - uses: actions/setup-java@v1
with: with:
java-version: 1.8 java-version: 11
- name: Fix android 31.0.0 dx
continue-on-error: true
run: cd /usr/local/lib/android/sdk/build-tools/31.0.0/ && mv d8 dx && cd lib && mv d8.jar dx.jar
- name: Rewrite version - name: Rewrite version
run: | run: |
branch="`echo "${{ github.ref }}" | grep -o "[^/]*$"`" branch="`echo "${{ github.ref }}" | grep -o "[^/]*$"`"
@@ -21,7 +18,7 @@ jobs:
run: ./gradlew build run: ./gradlew build
- name: Publish - name: Publish
continue-on-error: true continue-on-error: true
run: ./gradlew publishAllPublicationsToGithubPackagesRepository --no-parallel -x signJsPublication -x signJvmPublication -x signKotlinMultiplatformPublication run: ./gradlew publishAllPublicationsToGithubPackagesRepository --no-parallel
env: env:
GITHUBPACKAGES_USER: ${{ github.actor }} GITHUBPACKAGES_USER: ${{ github.actor }}
GITHUBPACKAGES_PASSWORD: ${{ secrets.GITHUB_TOKEN }} GITHUBPACKAGES_PASSWORD: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -1,5 +1,126 @@
# TelegramBotAPI changelog # TelegramBotAPI changelog
## 0.38.11
* `Common`:
* `Version`:
* `MicroUtils`: `0.9.16` -> `0.9.17`
* `Klock`: `2.6.3` -> `2.7.0`
* `Core`:
* Fixes in `TextSourcesList` creating in from `RawMessageEntities`
* Old ways to create keyboards (`matrix` and `row`) have been deprecated
* `API`:
* Add ability to `reply` with `Poll`
* Add ability to `reply` with any `MessageContent`
* Add ability to `reply` with any `TelegramMediaFile`
## 0.38.10
* `API`:
* All `with*Action` extensions got a contracts which declare that `block` will be called once
* Add several extensions `TelegramBot#sendPhoto` with `PhotoSize`
* Add several extensions `TelegramBot#reply` with `PhotoSize`
## 0.38.9
* `Core`:
* New function `MessageContent.Companion#serializationModule`
* Now it is possible to create `TelegramBot` (`RequestsExecutor`) with several bots under the hood and opportunity
for bots requests load balancing or fault-fix via sending of the requests via another bot
* `API`:
* Add replies which will use another message as a source for reply (`copyMessage`)
## 0.38.8
* `Common`:
* `Version`:
* `MicroUtils`: `0.9.12` -> `0.9.16`
* `Klock`: `2.6.2` -> `2.6.3`
* `Ktor`: `1.6.7` -> `1.6.8`
* `BehaviourBuilder`:
* Fixes in `onMediaGroup` and dependent functions
* Add several new extensions for `SimpleFilter`:
* `SimpleFilter#listAll`
* `SimpleFilter#listAny`
* `SimpleFilter#listNone`
## 0.38.7
* `Common`:
* `Version`:
* `MicroUtils`: `0.9.9` -> `0.9.12`
* `Klock`: `2.5.2` -> `2.6.2`
* `Core`:
* `SimplePollOption#votes` now is `0` by default
* New function `PollOption.Companion#simple`
## 0.38.6
* `Common`:
* `Version`:
* `MicroUtils`: `0.9.6` -> `0.9.9`
* `Klock`: `2.4.13` -> `2.5.2`
* `Core`:
* New member of `MentionTextSource` - `username`
## 0.38.5
* `Common`:
* `Version`:
* `MicroUtils`: `0.9.5` -> `0.9.6`
* `Core`:
* `Username` got new property `usernameWithoutAt` which will return `username` without leading `@`
* `Utils`:
* Several new functions for working with deep links:
* `makeUsernameDeepLinkPrefix`
* `makeTelegramDeepLink`
* `makeDeepLink`
## 0.38.4
__This update contains including of [Telegram Bot API 5.7](https://core.telegram.org/bots/api-changelog#january-31-2022)__
* `Core`:
* Support of new fields `Sticker`
* Support of new fields `StickerSet`
* Support of new fields in creating of sticker set and sticker
* `Utils`:
* Rename `PathedFile` to avoid clash with core file (fix of [#529](https://github.com/InsanusMokrassar/TelegramBotAPI/issues/529))
## 0.38.3
* `Common`:
* `Version`:
* `MicroUtils`: `0.9.1` -> `0.9.2`
* `Klock`: `2.4.10` -> `2.4.12`
* `UUID`: `0.3.1` -> `0.4.0`
* `API`
* New extensions `TelegramBot#send*` for media groups with contents
## 0.38.2
* `Common`:
* `Version`:
* `MicroUtils`: `0.9.0` -> `0.9.1`
* `API`
* New extensions `TelegramBot#copyMessages` for media groups
## 0.38.1
* `Core`:
* `MessageCallbackQuery` (and all implementers as well) has changed the type of `message`: now it is `ContentMessage<MessageContent>` instead of `Message`
* New type `ForwardFromPublicChatInfo` as extender of `ForwardInfo`:
* `ForwardFromChannelInfo` now extends `ForwardFromPublicChatInfo`
* `ForwardFromSupergroupInfo` now extends `ForwardFromPublicChatInfo`
* New type of events: `UserLoggedIn`
* `Utils`:
* ([#511](https://github.com/InsanusMokrassar/TelegramBotAPI/issues/511)) New extensions properties (raw fields as in original API) for several types have been added:
* `Message`
* `CallbackQuery`
* `ChosenInlineResult`
* `InlineQuery`
* `Poll`
## 0.38.0 ## 0.38.0
_This update contains [Telegram Bot API 5.6](https://core.telegram.org/bots/api-changelog#december-30-2021) implementation_ _This update contains [Telegram Bot API 5.6](https://core.telegram.org/bots/api-changelog#december-30-2021) implementation_

View File

@@ -1,8 +1,8 @@
# TelegramBotAPI [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi) [![Supported version](https://img.shields.io/badge/Telegram%20Bot%20API-5.6-blue)](https://core.telegram.org/bots/api-changelog#december-30-2021) # TelegramBotAPI [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi) [![Supported version](https://img.shields.io/badge/Telegram%20Bot%20API-5.7-blue)](https://core.telegram.org/bots/api-changelog#january-31-2022)
| [![Awesome Kotlin Badge](https://kotlin.link/awesome-kotlin.svg)](https://github.com/KotlinBy/awesome-kotlin) [![Build Status](https://github.com/InsanusMokrassar/TelegramBotAPI/workflows/Build/badge.svg)](https://github.com/InsanusMokrassar/TelegramBotAPI/actions) [![Small survey](https://img.shields.io/static/v1?label=Google&message=Survey&color=blue)](https://forms.gle/2Hex2ynbHWHhi1KY7) [![Chat in Telegram](https://img.shields.io/static/v1?label=Telegram&message=Chat&color=blue)](https://t.me/InMoTelegramBotAPI) | | [![Awesome Kotlin Badge](https://kotlin.link/awesome-kotlin.svg)](https://github.com/KotlinBy/awesome-kotlin) [![Build Status](https://github.com/InsanusMokrassar/TelegramBotAPI/workflows/Build/badge.svg)](https://github.com/InsanusMokrassar/TelegramBotAPI/actions) [![Small survey](https://img.shields.io/static/v1?label=Google&message=Survey&color=blue&logo=google-sheets)](https://docs.google.com/forms/d/e/1FAIpQLSctdJHT_aEniyYT0-IUAEfo1hsIlezX2owlkEAYX4KPl2V2_A/viewform?usp=sf_link) [![Chat in Telegram](https://img.shields.io/static/v1?label=Telegram&message=Chat&color=blue&logo=telegram)](https://t.me/InMoTelegramBotAPI) |
|:---:| |:---:|
| [![Create bot](https://img.shields.io/static/v1?label=Github&message=Template&color=blue)](https://github.com/InsanusMokrassar/TelegramBotAPI-bot_template/generate) [![Examples](https://img.shields.io/static/v1?label=Github&message=Examples&color=blue)](https://github.com/InsanusMokrassar/TelegramBotAPI-examples/) [![KDocs](https://img.shields.io/static/v1?label=Dokka&message=KDocs&color=blue)](https://tgbotapi.inmo.dev/index.html) [![Mini tutorial](https://img.shields.io/static/v1?label=Bookstack&message=Tutorial&color=blue)](https://bookstack.inmo.dev/books/telegrambotapi/chapter/introduction-tutorial) | | [![Create bot](https://img.shields.io/static/v1?label=Github&message=Template&color=blue&logo=github)](https://github.com/InsanusMokrassar/TelegramBotAPI-bot_template/generate) [![Examples](https://img.shields.io/static/v1?label=Github&message=Examples&color=blue&logo=github)](https://github.com/InsanusMokrassar/TelegramBotAPI-examples/) [![KDocs](https://img.shields.io/static/v1?label=Dokka&message=KDocs&color=blue&logo=kotlin)](https://tgbotapi.inmo.dev/index.html) [![Mini tutorial](https://img.shields.io/static/v1?label=Bookstack&message=Tutorial&color=blue&logo=bookstack)](https://bookstack.inmo.dev/books/telegrambotapi/chapter/introduction-tutorial) |
Hello! This is a set of libraries for working with Telegram Bot API. Hello! This is a set of libraries for working with Telegram Bot API.
@@ -28,7 +28,7 @@ Other configuration examples:
suspend fun main() { suspend fun main() {
val bot = telegramBot(TOKEN) val bot = telegramBot(TOKEN)
bot.buildBehaviour { bot.buildBehaviourWithLongPolling {
println(getMe()) println(getMe())
onCommand("start") { onCommand("start") {
@@ -69,7 +69,7 @@ and maybe some updates it got after launch)
suspend fun main() { suspend fun main() {
val bot = telegramBot(TOKEN) val bot = telegramBot(TOKEN)
bot.buildBehaviour { bot.buildBehaviourWithLongPolling {
println(getMe()) println(getMe())
val nameReplyMarkup = ReplyKeyboardMarkup( val nameReplyMarkup = ReplyKeyboardMarkup(

View File

@@ -1,3 +1 @@
dokka_version=1.6.0
org.gradle.jvmargs=-Xmx1024m org.gradle.jvmargs=-Xmx1024m

View File

@@ -8,16 +8,18 @@ kotlin.incremental.js=true
kotlin_version=1.6.10 kotlin_version=1.6.10
kotlin_coroutines_version=1.6.0 kotlin_coroutines_version=1.6.0
kotlin_serialisation_runtime_version=1.3.2 kotlin_serialisation_runtime_version=1.3.2
klock_version=2.4.10 klock_version=2.7.0
uuid_version=0.3.1 uuid_version=0.4.0
ktor_version=1.6.7 ktor_version=1.6.8
micro_utils_version=0.9.17
micro_utils_version=0.9.0
javax_activation_version=1.1.1 javax_activation_version=1.1.1
dokka_version=1.6.10
library_group=dev.inmo library_group=dev.inmo
library_version=0.38.0 library_version=0.38.11
github_release_plugin_version=2.2.12 github_release_plugin_version=2.2.12

View File

@@ -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-7.3.3-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.1-bin.zip

View File

@@ -1,5 +1,4 @@
apply plugin: 'maven-publish' apply plugin: 'maven-publish'
apply plugin: 'signing'
task javadocsJar(type: Jar) { task javadocsJar(type: Jar) {
classifier = 'javadoc' classifier = 'javadoc'
@@ -10,8 +9,8 @@ publishing {
artifact javadocsJar artifact javadocsJar
pom { pom {
description = "This project just include all subproject of TelegramBotAPI" description = "${project.description}"
name = "Telegram Bot API" name = "${project.name}"
url = "https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI" url = "https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI"
scm { scm {
@@ -63,7 +62,18 @@ publishing {
} }
} }
signing { if (project.hasProperty("signing.gnupg.keyName")) {
useGpgCmd() apply plugin: 'signing'
sign publishing.publications
signing {
useGpgCmd()
sign publishing.publications
}
task signAll {
tasks.withType(Sign).forEach {
dependsOn(it)
}
}
} }

1
publish.kpsb Normal file
View File

@@ -0,0 +1 @@
{"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"}],"mavenConfig":{"name":"${project.name}","description":"${project.description}","url":"https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI","vcsUrl":"https://github.com/insanusmokrassar/TelegramBotAPI.git","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/"}],"gpgSigning":{"type":"dev.inmo.kmppscriptbuilder.core.models.GpgSigning.Optional"}}}

View File

@@ -0,0 +1,97 @@
# Exceptions handling
Unfortunatelly, exceptions handling in this library is a bit difficult in some places, but that have at least two reasons: flexibility and usability.
## "In place" handling
In case you know, where exceptions are happening, you may use several tools for exceptions catching:
* Catching with result
* Catching with callback
### Catching with result
If you prefer to receive `Result` objects instead of some weird callbacks, you may use the next syntax:
```kotlin
safelyWithResult {
// do something
}.onSuccess { // will be called if everything is right
// handle success
}.onFailure { // will be called if something went wrong
// handle error
it.printStackTrace()
}.getOrThrow() // will return value or throw exception
```
### Catching with callback
Also there is more simple (in some cases) way to handle exceptions with callbacks:
```kotlin
safely(
{
// handle error
it.printStackTrace()
null // return value
}
) {
// do something
}
```
### Bonus: different types of handling
There are two types of handling:
* Just safely - when you are using something to obviously retrieve value or throw exception. When handling callback has been skipped, it will throw exception by default. For example:
```kotlin
safely(
{
it.printStackTrace()
"error"
}
) {
error("Hi :)") // emulate exception throwing
"ok"
} // result will be with type String
```
* Safely without exceptions - almost the same as `safely`, but this type by default allow to return nullable value (when exception was thrown) instead of just throwing (as with `safely`):
```kotlin
safelyWithouExceptions {
// do something
} // will returns nullable result type
```
## Global exceptions handling
The most simple way to configure exceptions handling is to change `CoroutineContext` when you are creating your `CoroutineScope` for bot processing:
```kotlin
val bot = telegramBot("TOKEN")
bot.buildBehaviour (
scope = scope,
defaultExceptionsHandler = {
it.printStackTrace()
}
) {
// ...
}
```
OR
```kotlin
val bot = telegramBotWithBehaviour (
"TOKEN",
scope = scope,
defaultExceptionsHandler = {
it.printStackTrace()
}
) {
// ...
}
```
Here we have used `ContextSafelyExceptionHandler` class. It will pass default handling of exceptions and will call the block in most cases when something inside of your bot logic has thrown exception.

View File

@@ -17,8 +17,9 @@ plugins {
project.version = "$library_version" project.version = "$library_version"
project.group = "$library_group" project.group = "$library_group"
project.description = "API extensions with \"Telegram Bot API\"-like extensions for TelegramBot and RequestsExecutor"
apply from: "publish.gradle" apply from: "../publish.gradle"
repositories { repositories {
mavenLocal() mavenLocal()

View File

@@ -1 +0,0 @@
{"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/"}]}}

View File

@@ -1,69 +0,0 @@
apply plugin: 'maven-publish'
apply plugin: 'signing'
task javadocsJar(type: Jar) {
classifier = 'javadoc'
}
publishing {
publications.all {
artifact javadocsJar
pom {
description = "API extensions which provide work with RequestsExecutor of TelegramBotAPI almost like it is described in original Telegram Bot API reference"
name = "Telegram Bot API Extensions for API"
url = "https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI-extensions-api"
scm {
developerConnection = "scm:git:[fetch=]https://github.com/insanusmokrassar/TelegramBotAPI.git[push=]https://github.com/insanusmokrassar/TelegramBotAPI.git"
url = "https://github.com/insanusmokrassar/TelegramBotAPI.git"
}
developers {
developer {
id = "InsanusMokrassar"
name = "Ovsiannikov Aleksei"
email = "ovsyannikov.alexey95@gmail.com"
}
}
licenses {
license {
name = "Apache Software License 2.0"
url = "https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"
}
}
}
repositories {
if ((project.hasProperty('GITHUBPACKAGES_USER') || System.getenv('GITHUBPACKAGES_USER') != null) && (project.hasProperty('GITHUBPACKAGES_PASSWORD') || System.getenv('GITHUBPACKAGES_PASSWORD') != null)) {
maven {
name = "GithubPackages"
url = uri("https://maven.pkg.github.com/InsanusMokrassar/TelegramBotAPI")
credentials {
username = project.hasProperty('GITHUBPACKAGES_USER') ? project.property('GITHUBPACKAGES_USER') : System.getenv('GITHUBPACKAGES_USER')
password = project.hasProperty('GITHUBPACKAGES_PASSWORD') ? project.property('GITHUBPACKAGES_PASSWORD') : System.getenv('GITHUBPACKAGES_PASSWORD')
}
}
}
if ((project.hasProperty('SONATYPE_USER') || System.getenv('SONATYPE_USER') != null) && (project.hasProperty('SONATYPE_PASSWORD') || System.getenv('SONATYPE_PASSWORD') != null)) {
maven {
name = "sonatype"
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials {
username = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : System.getenv('SONATYPE_USER')
password = project.hasProperty('SONATYPE_PASSWORD') ? project.property('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD')
}
}
}
}
}
}
signing {
useGpgCmd()
sign publishing.publications
}

View File

@@ -2,7 +2,7 @@ package dev.inmo.tgbotapi.extensions.api.get
import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.get.GetStickerSet import dev.inmo.tgbotapi.requests.get.GetStickerSet
import dev.inmo.tgbotapi.types.files.Sticker import dev.inmo.tgbotapi.types.files.sticker.Sticker
suspend fun TelegramBot.getStickerSet( suspend fun TelegramBot.getStickerSet(
name: String name: String

View File

@@ -0,0 +1,177 @@
package dev.inmo.tgbotapi.extensions.api.send
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.extensions.api.send.media.sendMediaGroup
import dev.inmo.tgbotapi.requests.send.CopyMessage
import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.InputMedia.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList
import dev.inmo.tgbotapi.types.MessageIdentifier
import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
import dev.inmo.tgbotapi.types.chat.abstracts.Chat
import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage
import dev.inmo.tgbotapi.types.message.abstracts.Message
import dev.inmo.tgbotapi.types.message.content.abstracts.MediaGroupContent
import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.MediaGroupUpdate
import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.SentMediaGroupUpdate
/**
* Send media group via [sendMediaGroup] extension with edited [entities] of first [messages] element. Other elements
* will be copied as they are
*/
suspend inline fun TelegramBot.copyMessages(
toChatId: ChatIdentifier,
messages: List<MediaGroupMessage<MediaGroupContent>>,
text: String? = null,
parseMode: ParseMode? = null,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null
): List<MediaGroupMessage<MediaGroupContent>> {
val first = messages.first().content.toMediaGroupMemberInputMedia().let {
if (text != null) {
when (it) {
is InputMediaAudio -> it.copy(text = text, parseMode = parseMode)
is InputMediaDocument -> it.copy(text = text, parseMode = parseMode)
is InputMediaPhoto -> it.copy(text = text, parseMode = parseMode)
is InputMediaVideo -> it.copy(text = text, parseMode = parseMode)
}
} else {
it
}
}
return sendMediaGroup(
toChatId,
listOf(first) + messages.drop(1).map {
it.content.toMediaGroupMemberInputMedia()
},
disableNotification,
protectContent,
replyToMessageId,
allowSendingWithoutReply
)
}
/**
* Send media group via [sendMediaGroup] extension with edited [entities] of first [messages] element. Other elements
* will be copied as they are
*/
suspend inline fun TelegramBot.copyMessages(
toChat: Chat,
messages: List<MediaGroupMessage<MediaGroupContent>>,
text: String? = null,
parseMode: ParseMode? = null,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null
) = copyMessages(toChat.id, messages, text, parseMode, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply)
/**
* Send media group via [sendMediaGroup] extension with edited [entities] of first [messages] element. Other elements
* will be copied as they are
*/
suspend inline fun TelegramBot.copyMessages(
toChat: ChatIdentifier,
update: SentMediaGroupUpdate,
text: String? = null,
parseMode: ParseMode? = null,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null
) = copyMessages(toChat, update.data, text, parseMode, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply)
/**
* Send media group via [sendMediaGroup] extension with edited [entities] of first [messages] element. Other elements
* will be copied as they are
*/
suspend inline fun TelegramBot.copyMessages(
toChat: Chat,
update: SentMediaGroupUpdate,
text: String? = null,
parseMode: ParseMode? = null,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null
) = copyMessages(toChat.id, update, text, parseMode, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply)
/**
* Send media group via [sendMediaGroup] extension with edited [entities] of first [messages] element. Other elements
* will be copied as they are
*/
suspend inline fun TelegramBot.copyMessages(
toChatId: ChatIdentifier,
messages: List<MediaGroupMessage<MediaGroupContent>>,
entities: TextSourcesList,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null
): List<MediaGroupMessage<MediaGroupContent>> {
val first = messages.first().content.toMediaGroupMemberInputMedia().let {
when (it) {
is InputMediaAudio -> InputMediaAudio(it.file, entities, it.duration, it.performer, it.title, it.thumb)
is InputMediaDocument -> InputMediaDocument(it.file, entities, it.thumb, it.disableContentTypeDetection)
is InputMediaPhoto -> InputMediaPhoto(it.file, entities)
is InputMediaVideo -> InputMediaVideo(it.file, entities, it.width, it.height, it.duration, it.thumb)
}
}
return sendMediaGroup(
toChatId,
listOf(first) + messages.drop(1).map {
it.content.toMediaGroupMemberInputMedia()
},
disableNotification,
protectContent,
replyToMessageId,
allowSendingWithoutReply
)
}
/**
* Send media group via [sendMediaGroup] extension with edited [entities] of first [messages] element. Other elements
* will be copied as they are
*/
suspend inline fun TelegramBot.copyMessages(
toChat: Chat,
messages: List<MediaGroupMessage<MediaGroupContent>>,
entities: TextSourcesList,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null
) = copyMessages(toChat.id, messages, entities, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply)
/**
* Send media group via [sendMediaGroup] extension with edited [entities] of first [messages] element. Other elements
* will be copied as they are
*/
suspend inline fun TelegramBot.copyMessages(
toChat: ChatIdentifier,
update: SentMediaGroupUpdate,
entities: TextSourcesList,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null
) = copyMessages(toChat, update.data, entities, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply)
/**
* Send media group via [sendMediaGroup] extension with edited [entities] of first [messages] element. Other elements
* will be copied as they are
*/
suspend inline fun TelegramBot.copyMessages(
toChat: Chat,
update: SentMediaGroupUpdate,
entities: TextSourcesList,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null
) = copyMessages(toChat.id, update, entities, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply)

View File

@@ -14,11 +14,17 @@ import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList
import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
import dev.inmo.tgbotapi.types.chat.abstracts.Chat
import dev.inmo.tgbotapi.types.dice.DiceAnimationType import dev.inmo.tgbotapi.types.dice.DiceAnimationType
import dev.inmo.tgbotapi.types.files.* import dev.inmo.tgbotapi.types.files.*
import dev.inmo.tgbotapi.types.files.abstracts.TelegramMediaFile
import dev.inmo.tgbotapi.types.files.sticker.Sticker
import dev.inmo.tgbotapi.types.games.Game import dev.inmo.tgbotapi.types.games.Game
import dev.inmo.tgbotapi.types.location.StaticLocation import dev.inmo.tgbotapi.types.location.*
import dev.inmo.tgbotapi.types.message.abstracts.Message import dev.inmo.tgbotapi.types.message.abstracts.Message
import dev.inmo.tgbotapi.types.message.content.*
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
import dev.inmo.tgbotapi.types.passport.encrypted.PassportFile
import dev.inmo.tgbotapi.types.payments.LabeledPrice import dev.inmo.tgbotapi.types.payments.LabeledPrice
import dev.inmo.tgbotapi.types.payments.abstracts.Currency import dev.inmo.tgbotapi.types.payments.abstracts.Currency
import dev.inmo.tgbotapi.types.polls.* import dev.inmo.tgbotapi.types.polls.*
@@ -116,6 +122,7 @@ suspend inline fun TelegramBot.reply(
longitude: Double, longitude: Double,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendLocation( ) = sendLocation(
to.chat, to.chat,
@@ -123,6 +130,7 @@ suspend inline fun TelegramBot.reply(
longitude, longitude,
disableNotification, disableNotification,
protectContent, protectContent,
allowSendingWithoutReply,
to.messageId, to.messageId,
replyMarkup replyMarkup
) )
@@ -136,12 +144,14 @@ suspend inline fun TelegramBot.reply(
location: StaticLocation, location: StaticLocation,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendLocation( ) = sendLocation(
to.chat, to.chat,
location, location,
disableNotification, disableNotification,
protectContent, protectContent,
allowSendingWithoutReply,
to.messageId, to.messageId,
replyMarkup replyMarkup
) )
@@ -569,6 +579,17 @@ suspend inline fun TelegramBot.reply(
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendPhoto(to.chat, photo, text, parseMode, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) ) = sendPhoto(to.chat, photo, text, parseMode, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup)
suspend inline fun TelegramBot.reply(
to: Message,
photoSize: PhotoSize,
text: String? = null,
parseMode: ParseMode? = null,
disableNotification: Boolean = false,
protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null
) = sendPhoto(to.chat, photoSize, text, parseMode, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup)
suspend inline fun TelegramBot.replyWithPhoto( suspend inline fun TelegramBot.replyWithPhoto(
to: Message, to: Message,
@@ -590,6 +611,16 @@ suspend inline fun TelegramBot.reply(
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendPhoto(to.chat, photo, entities, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) ) = sendPhoto(to.chat, photo, entities, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup)
suspend inline fun TelegramBot.reply(
to: Message,
photoSize: PhotoSize,
entities: TextSourcesList,
disableNotification: Boolean = false,
protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null
) = sendPhoto(to.chat, photoSize, entities, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup)
// Sticker // Sticker
@@ -863,3 +894,180 @@ suspend inline fun TelegramBot.reply(
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendQuizPoll(to.chat, isClosed, quizPoll, question, options, correctOptionId, isAnonymous, entities, closeInfo, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup) ) = sendQuizPoll(to.chat, isClosed, quizPoll, question, options, correctOptionId, isAnonymous, entities, closeInfo, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup)
suspend inline fun TelegramBot.reply(
to: Message,
poll: Poll,
isClosed: Boolean = false,
question: String = poll.question,
options: List<String> = poll.options.map { it.text },
isAnonymous: Boolean = poll.isAnonymous,
closeInfo: ScheduledCloseInfo? = null,
disableNotification: Boolean = false,
protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null
) = when (poll) {
is RegularPoll -> reply(
to = to,
poll = poll,
isClosed = isClosed,
question = question,
options = options,
isAnonymous = isAnonymous,
allowMultipleAnswers = isAnonymous,
closeInfo = closeInfo,
disableNotification = disableNotification,
protectContent = protectContent,
allowSendingWithoutReply = allowSendingWithoutReply,
replyMarkup = replyMarkup
)
is UnknownPollType -> error("Unable to send poll with unknown type ($poll)")
is QuizPoll -> reply(
to = to,
quizPoll = poll,
entities = poll.textSources,
isClosed = isClosed,
question = question,
options = options,
isAnonymous = isAnonymous,
closeInfo = closeInfo,
disableNotification = disableNotification,
protectContent = protectContent,
allowSendingWithoutReply = allowSendingWithoutReply,
replyMarkup = replyMarkup
)
}
suspend inline fun TelegramBot.reply(
to: Message,
fromChatId: ChatIdentifier,
messageId: MessageIdentifier,
text: String? = null,
parseMode: ParseMode? = null,
disableNotification: Boolean = false,
protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null
) = copyMessage(fromChatId, to.chat.id, messageId, text, parseMode, disableNotification, protectContent, to.messageId, allowSendingWithoutReply, replyMarkup)
suspend inline fun TelegramBot.reply(
to: Message,
fromChat: Chat,
messageId: MessageIdentifier,
text: String? = null,
parseMode: ParseMode? = null,
disableNotification: Boolean = false,
protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null
) = reply(to, fromChat.id, messageId, text, parseMode, disableNotification, protectContent, allowSendingWithoutReply, replyMarkup)
suspend inline fun TelegramBot.reply(
to: Message,
copy: Message,
text: String? = null,
parseMode: ParseMode? = null,
disableNotification: Boolean = false,
protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null
) = reply(to, copy.chat.id, copy.messageId, text, parseMode, disableNotification, protectContent, allowSendingWithoutReply, replyMarkup)
suspend fun TelegramBot.reply(
to: Message,
content: MessageContent,
disableNotification: Boolean = false,
protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null
) {
execute(
content.createResend(
to.chat.id,
disableNotification,
protectContent,
to.messageId,
allowSendingWithoutReply,
replyMarkup
)
)
}
suspend fun TelegramBot.reply(
to: Message,
mediaFile: TelegramMediaFile,
disableNotification: Boolean = false,
protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null
) {
when (mediaFile) {
is AudioFile -> reply(
to = to,
audio = mediaFile,
disableNotification = disableNotification,
protectContent = protectContent,
allowSendingWithoutReply = allowSendingWithoutReply,
replyMarkup = replyMarkup
)
is AnimationFile -> reply(
to = to,
animation = mediaFile,
disableNotification = disableNotification,
protectContent = protectContent,
allowSendingWithoutReply = allowSendingWithoutReply,
replyMarkup = replyMarkup
)
is VoiceFile -> reply(
to = to,
voice = mediaFile,
disableNotification = disableNotification,
protectContent = protectContent,
allowSendingWithoutReply = allowSendingWithoutReply,
replyMarkup = replyMarkup
)
is VideoFile -> reply(
to = to,
video = mediaFile,
disableNotification = disableNotification,
protectContent = protectContent,
allowSendingWithoutReply = allowSendingWithoutReply,
replyMarkup = replyMarkup
)
is VideoNoteFile -> reply(
to = to,
videoNote = mediaFile,
disableNotification = disableNotification,
protectContent = protectContent,
allowSendingWithoutReply = allowSendingWithoutReply,
replyMarkup = replyMarkup
)
is DocumentFile -> reply(
to = to,
document = mediaFile,
disableNotification = disableNotification,
protectContent = protectContent,
allowSendingWithoutReply = allowSendingWithoutReply,
replyMarkup = replyMarkup
)
is Sticker -> reply(
to = to,
sticker = mediaFile,
disableNotification = disableNotification,
protectContent = protectContent,
allowSendingWithoutReply = allowSendingWithoutReply,
replyMarkup = replyMarkup
)
else -> reply(
to = to,
document = mediaFile.asDocumentFile(),
disableNotification = disableNotification,
protectContent = protectContent,
allowSendingWithoutReply = allowSendingWithoutReply,
replyMarkup = replyMarkup
)
}
}

View File

@@ -8,15 +8,20 @@ import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.actions.* import dev.inmo.tgbotapi.types.actions.*
import dev.inmo.tgbotapi.types.chat.abstracts.Chat import dev.inmo.tgbotapi.types.chat.abstracts.Chat
import kotlinx.coroutines.* import kotlinx.coroutines.*
import kotlin.contracts.*
import kotlin.coroutines.coroutineContext import kotlin.coroutines.coroutineContext
private const val refreshTime: MilliSeconds = (botActionActualityTime - 1) * 1000L private const val refreshTime: MilliSeconds = (botActionActualityTime - 1) * 1000L
typealias TelegramBotActionCallback<T> = suspend TelegramBot.() -> T typealias TelegramBotActionCallback<T> = suspend TelegramBot.() -> T
@OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withAction( suspend fun <T> TelegramBot.withAction(
actionRequest: SendAction, actionRequest: SendAction,
block: TelegramBotActionCallback<T> block: TelegramBotActionCallback<T>
): T { ): T {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
val botActionJob = CoroutineScope(coroutineContext).launch { val botActionJob = CoroutineScope(coroutineContext).launch {
while (isActive) { while (isActive) {
delay(refreshTime) delay(refreshTime)
@@ -30,46 +35,190 @@ suspend fun <T> TelegramBot.withAction(
return result.getOrThrow() return result.getOrThrow()
} }
@OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withAction( suspend fun <T> TelegramBot.withAction(
chatId: ChatId, chatId: ChatId,
action: BotAction, action: BotAction,
block: TelegramBotActionCallback<T> block: TelegramBotActionCallback<T>
) = withAction( ): T {
SendAction(chatId, action), contract {
block callsInPlace(block, InvocationKind.EXACTLY_ONCE)
) }
return withAction(
SendAction(chatId, action),
block
)
}
@OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withAction( suspend fun <T> TelegramBot.withAction(
chat: Chat, chat: Chat,
action: BotAction, action: BotAction,
block: TelegramBotActionCallback<T> block: TelegramBotActionCallback<T>
) = withAction( ): T {
chat.id, contract {
action, callsInPlace(block, InvocationKind.EXACTLY_ONCE)
block }
) return withAction(
chat.id,
action,
block
)
}
suspend fun <T> TelegramBot.withTypingAction(chatId: ChatId, block: TelegramBotActionCallback<T>) = withAction(chatId, TypingAction, block) @OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withUploadPhotoAction(chatId: ChatId, block: TelegramBotActionCallback<T>) = withAction(chatId, UploadPhotoAction, block) suspend fun <T> TelegramBot.withTypingAction(chatId: ChatId, block: TelegramBotActionCallback<T>) : T {
suspend fun <T> TelegramBot.withRecordVideoAction(chatId: ChatId, block: TelegramBotActionCallback<T>) = withAction(chatId, RecordVideoAction, block) contract {
suspend fun <T> TelegramBot.withUploadVideoAction(chatId: ChatId, block: TelegramBotActionCallback<T>) = withAction(chatId, UploadVideoAction, block) callsInPlace(block, InvocationKind.EXACTLY_ONCE)
suspend fun <T> TelegramBot.withRecordVoiceAction(chatId: ChatId, block: TelegramBotActionCallback<T>) = withAction(chatId, RecordVoiceAction, block) }
suspend fun <T> TelegramBot.withUploadVoiceAction(chatId: ChatId, block: TelegramBotActionCallback<T>) = withAction(chatId, UploadVoiceAction, block) return withAction(chatId, TypingAction, 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) @OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withRecordVideoNoteAction(chatId: ChatId, block: TelegramBotActionCallback<T>) = withAction(chatId, RecordVideoNoteAction, block) suspend fun <T> TelegramBot.withUploadPhotoAction(chatId: ChatId, block: TelegramBotActionCallback<T>) : T {
suspend fun <T> TelegramBot.withUploadVideoNoteAction(chatId: ChatId, block: TelegramBotActionCallback<T>) = withAction(chatId, UploadVideoNoteAction, block) contract {
suspend fun <T> TelegramBot.withChooseStickerAction(chatId: ChatId, block: TelegramBotActionCallback<T>) = withAction(chatId, ChooseStickerAction, block) callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
return withAction(chatId, UploadPhotoAction, block)
}
@OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withRecordVideoAction(chatId: ChatId, block: TelegramBotActionCallback<T>) : T {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
return withAction(chatId, RecordVideoAction, block)
}
@OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withUploadVideoAction(chatId: ChatId, block: TelegramBotActionCallback<T>) : T {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
return withAction(chatId, UploadVideoAction, block)
}
@OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withRecordVoiceAction(chatId: ChatId, block: TelegramBotActionCallback<T>) : T {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
return withAction(chatId, RecordVoiceAction, block)
}
@OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withUploadVoiceAction(chatId: ChatId, block: TelegramBotActionCallback<T>) : T {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
return withAction(chatId, UploadVoiceAction, block)
}
@OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withUploadDocumentAction(chatId: ChatId, block: TelegramBotActionCallback<T>) : T {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
return withAction(chatId, UploadDocumentAction, block)
}
@OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withFindLocationAction(chatId: ChatId, block: TelegramBotActionCallback<T>) : T {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
return withAction(chatId, FindLocationAction, block)
}
@OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withRecordVideoNoteAction(chatId: ChatId, block: TelegramBotActionCallback<T>) : T {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
return withAction(chatId, RecordVideoNoteAction, block)
}
@OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withUploadVideoNoteAction(chatId: ChatId, block: TelegramBotActionCallback<T>) : T {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
return withAction(chatId, UploadVideoNoteAction, block)
}
@OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withChooseStickerAction(chatId: ChatId, block: TelegramBotActionCallback<T>) : T {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
return withAction(chatId, ChooseStickerAction, block)
}
suspend fun <T> TelegramBot.withTypingAction(chat: Chat, block: TelegramBotActionCallback<T>) = withAction(chat, TypingAction, block) @OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withUploadPhotoAction(chat: Chat, block: TelegramBotActionCallback<T>) = withAction(chat, UploadPhotoAction, block) suspend fun <T> TelegramBot.withTypingAction(chat: Chat, block: TelegramBotActionCallback<T>) : T {
suspend fun <T> TelegramBot.withRecordVideoAction(chat: Chat, block: TelegramBotActionCallback<T>) = withAction(chat, RecordVideoAction, block) contract {
suspend fun <T> TelegramBot.withUploadVideoAction(chat: Chat, block: TelegramBotActionCallback<T>) = withAction(chat, UploadVideoAction, block) callsInPlace(block, InvocationKind.EXACTLY_ONCE)
suspend fun <T> TelegramBot.withRecordVoiceAction(chat: Chat, block: TelegramBotActionCallback<T>) = withAction(chat, RecordVoiceAction, block) }
suspend fun <T> TelegramBot.withUploadVoiceAction(chat: Chat, block: TelegramBotActionCallback<T>) = withAction(chat, UploadVoiceAction, block) return withAction(chat, TypingAction, 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) @OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withRecordVideoNoteAction(chat: Chat, block: TelegramBotActionCallback<T>) = withAction(chat, RecordVideoNoteAction, block) suspend fun <T> TelegramBot.withUploadPhotoAction(chat: Chat, block: TelegramBotActionCallback<T>) : T {
suspend fun <T> TelegramBot.withUploadVideoNoteAction(chat: Chat, block: TelegramBotActionCallback<T>) = withAction(chat, UploadVideoNoteAction, block) contract {
suspend fun <T> TelegramBot.withChooseStickerAction(chat: Chat, block: TelegramBotActionCallback<T>) = withAction(chat, ChooseStickerAction, block) callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
return withAction(chat, UploadPhotoAction, block)
}
@OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withRecordVideoAction(chat: Chat, block: TelegramBotActionCallback<T>) : T {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
return withAction(chat, RecordVideoAction, block)
}
@OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withUploadVideoAction(chat: Chat, block: TelegramBotActionCallback<T>) : T {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
return withAction(chat, UploadVideoAction, block)
}
@OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withRecordVoiceAction(chat: Chat, block: TelegramBotActionCallback<T>) : T {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
return withAction(chat, RecordVoiceAction, block)
}
@OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withUploadVoiceAction(chat: Chat, block: TelegramBotActionCallback<T>) : T {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
return withAction(chat, UploadVoiceAction, block)
}
@OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withUploadDocumentAction(chat: Chat, block: TelegramBotActionCallback<T>) : T {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
return withAction(chat, UploadDocumentAction, block)
}
@OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withFindLocationAction(chat: Chat, block: TelegramBotActionCallback<T>) : T {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
return withAction(chat, FindLocationAction, block)
}
@OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withRecordVideoNoteAction(chat: Chat, block: TelegramBotActionCallback<T>) : T {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
return withAction(chat, RecordVideoNoteAction, block)
}
@OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withUploadVideoNoteAction(chat: Chat, block: TelegramBotActionCallback<T>) : T {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
return withAction(chat, UploadVideoNoteAction, block)
}
@OptIn(ExperimentalContracts::class)
suspend fun <T> TelegramBot.withChooseStickerAction(chat: Chat, block: TelegramBotActionCallback<T>) : T {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
return withAction(chat, ChooseStickerAction, block)
}

View File

@@ -18,6 +18,7 @@ suspend fun TelegramBot.sendLocation(
longitude: Double, longitude: Double,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null,
replyToMessageId: MessageIdentifier? = null, replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = execute( ) = execute(
@@ -27,6 +28,7 @@ suspend fun TelegramBot.sendLocation(
longitude, longitude,
disableNotification = disableNotification, disableNotification = disableNotification,
protectContent = protectContent, protectContent = protectContent,
allowSendingWithoutReply = allowSendingWithoutReply,
replyToMessageId = replyToMessageId, replyToMessageId = replyToMessageId,
replyMarkup = replyMarkup replyMarkup = replyMarkup
) )
@@ -41,6 +43,7 @@ suspend fun TelegramBot.sendLocation(
location: StaticLocation, location: StaticLocation,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null,
replyToMessageId: MessageIdentifier? = null, replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendLocation( ) = sendLocation(
@@ -49,6 +52,7 @@ suspend fun TelegramBot.sendLocation(
location.longitude, location.longitude,
disableNotification, disableNotification,
protectContent, protectContent,
allowSendingWithoutReply,
replyToMessageId, replyToMessageId,
replyMarkup replyMarkup
) )
@@ -63,6 +67,7 @@ suspend fun TelegramBot.sendLocation(
longitude: Double, longitude: Double,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null,
replyToMessageId: MessageIdentifier? = null, replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendLocation( ) = sendLocation(
@@ -71,6 +76,7 @@ suspend fun TelegramBot.sendLocation(
longitude, longitude,
disableNotification, disableNotification,
protectContent, protectContent,
allowSendingWithoutReply,
replyToMessageId, replyToMessageId,
replyMarkup replyMarkup
) )
@@ -84,6 +90,7 @@ suspend fun TelegramBot.sendLocation(
location: StaticLocation, location: StaticLocation,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null,
replyToMessageId: MessageIdentifier? = null, replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendLocation( ) = sendLocation(
@@ -92,6 +99,7 @@ suspend fun TelegramBot.sendLocation(
location.longitude, location.longitude,
disableNotification, disableNotification,
protectContent, protectContent,
allowSendingWithoutReply,
replyToMessageId, replyToMessageId,
replyMarkup replyMarkup
) )
@@ -106,9 +114,10 @@ suspend fun TelegramBot.sendStaticLocation(
longitude: Double, longitude: Double,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null,
replyToMessageId: MessageIdentifier? = null, replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendLocation(chatId, latitude, longitude, disableNotification, protectContent, replyToMessageId, replyMarkup) ) = sendLocation(chatId, latitude, longitude, disableNotification, protectContent, allowSendingWithoutReply, replyToMessageId, replyMarkup)
/** /**
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
@@ -119,9 +128,10 @@ suspend fun TelegramBot.sendStaticLocation(
location: StaticLocation, location: StaticLocation,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null,
replyToMessageId: MessageIdentifier? = null, replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendLocation(chatId, location.latitude, location.longitude, disableNotification, protectContent, replyToMessageId, replyMarkup) ) = sendLocation(chatId, location.latitude, location.longitude, disableNotification, protectContent, allowSendingWithoutReply, replyToMessageId, replyMarkup)
/** /**
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
@@ -133,9 +143,10 @@ suspend fun TelegramBot.sendStaticLocation(
longitude: Double, longitude: Double,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null,
replyToMessageId: MessageIdentifier? = null, replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendLocation(chat.id, latitude, longitude, disableNotification, protectContent, replyToMessageId, replyMarkup) ) = sendLocation(chat.id, latitude, longitude, disableNotification, protectContent, allowSendingWithoutReply, replyToMessageId, replyMarkup)
/** /**
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
@@ -146,6 +157,7 @@ suspend fun TelegramBot.sendStaticLocation(
location: StaticLocation, location: StaticLocation,
disableNotification: Boolean = false, disableNotification: Boolean = false,
protectContent: Boolean = false, protectContent: Boolean = false,
allowSendingWithoutReply: Boolean? = null,
replyToMessageId: MessageIdentifier? = null, replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendLocation(chat.id, location.latitude, location.longitude, disableNotification, protectContent, replyToMessageId, replyMarkup) ) = sendLocation(chat.id, location.latitude, location.longitude, disableNotification, protectContent, allowSendingWithoutReply, replyToMessageId, replyMarkup)

View File

@@ -7,7 +7,11 @@ import dev.inmo.tgbotapi.types.InputMedia.*
import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.MessageIdentifier
import dev.inmo.tgbotapi.types.chat.abstracts.Chat import dev.inmo.tgbotapi.types.chat.abstracts.Chat
import dev.inmo.tgbotapi.types.message.content.abstracts.MediaGroupContent import dev.inmo.tgbotapi.types.message.content.abstracts.MediaGroupContent
import dev.inmo.tgbotapi.types.message.content.abstracts.VisualMediaGroupContent
import dev.inmo.tgbotapi.types.message.content.media.AudioContent
import dev.inmo.tgbotapi.types.message.content.media.DocumentContent
import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.RiskFeature
import kotlin.jvm.JvmName
/** /**
* @see SendMediaGroup * @see SendMediaGroup
@@ -41,6 +45,38 @@ suspend fun TelegramBot.sendMediaGroup(
chat.id, media, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply chat.id, media, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply
) )
/**
* @see SendMediaGroup
*/
@RiskFeature(rawSendingMediaGroupsWarning)
@JvmName("sendMedaGroupByContent")
suspend fun TelegramBot.sendMediaGroup(
chatId: ChatIdentifier,
media: List<MediaGroupContent>,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null
) = sendMediaGroup(
chatId, media.map { it.toMediaGroupMemberInputMedia() }, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply
)
/**
* @see SendMediaGroup
*/
@RiskFeature(rawSendingMediaGroupsWarning)
@JvmName("sendMedaGroupByContent")
suspend fun TelegramBot.sendMediaGroup(
chat: Chat,
media: List<MediaGroupContent>,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null
) = sendMediaGroup(
chat.id, media, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply
)
/** /**
* @see SendPlaylist * @see SendPlaylist
*/ */
@@ -71,6 +107,36 @@ suspend fun TelegramBot.sendPlaylist(
chat.id, media, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply chat.id, media, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply
) )
/**
* @see SendPlaylist
*/
@JvmName("sendPlaylistByContent")
suspend fun TelegramBot.sendPlaylist(
chatId: ChatIdentifier,
media: List<AudioContent>,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null
) = sendPlaylist(
chatId, media.map { it.toMediaGroupMemberInputMedia() }, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply
)
/**
* @see SendPlaylist
*/
@JvmName("sendPlaylistByContent")
suspend fun TelegramBot.sendPlaylist(
chat: Chat,
media: List<AudioContent>,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null
) = sendPlaylist(
chat.id, media, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply
)
/** /**
* @see SendDocumentsGroup * @see SendDocumentsGroup
*/ */
@@ -101,6 +167,36 @@ suspend fun TelegramBot.sendDocumentsGroup(
chat.id, media, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply chat.id, media, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply
) )
/**
* @see SendDocumentsGroup
*/
@JvmName("sendDocumentsByContent")
suspend fun TelegramBot.sendDocumentsGroup(
chatId: ChatIdentifier,
media: List<DocumentContent>,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null
) = sendDocumentsGroup(
chatId, media.map { it.toMediaGroupMemberInputMedia() }, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply
)
/**
* @see SendDocumentsGroup
*/
@JvmName("sendDocumentsByContent")
suspend fun TelegramBot.sendDocumentsGroup(
chat: Chat,
media: List<DocumentContent>,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null
) = sendDocumentsGroup(
chat.id, media, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply
)
/** /**
* @see SendVisualMediaGroup * @see SendVisualMediaGroup
*/ */
@@ -130,3 +226,33 @@ suspend fun TelegramBot.sendVisualMediaGroup(
) = sendVisualMediaGroup( ) = sendVisualMediaGroup(
chat.id, media, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply chat.id, media, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply
) )
/**
* @see SendVisualMediaGroup
*/
@JvmName("sendVisualMediaGroupByContent")
suspend fun TelegramBot.sendVisualMediaGroup(
chatId: ChatIdentifier,
media: List<VisualMediaGroupContent>,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null
) = sendVisualMediaGroup(
chatId, media.map { it.toMediaGroupMemberInputMedia() }, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply
)
/**
* @see SendVisualMediaGroup
*/
@JvmName("sendVisualMediaGroupByContent")
suspend fun TelegramBot.sendVisualMediaGroup(
chat: Chat,
media: List<VisualMediaGroupContent>,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null
) = sendVisualMediaGroup(
chat.id, media, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply
)

View File

@@ -9,8 +9,7 @@ import dev.inmo.tgbotapi.types.MessageIdentifier
import dev.inmo.tgbotapi.types.ParseMode.ParseMode import dev.inmo.tgbotapi.types.ParseMode.ParseMode
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
import dev.inmo.tgbotapi.types.chat.abstracts.Chat import dev.inmo.tgbotapi.types.chat.abstracts.Chat
import dev.inmo.tgbotapi.types.files.Photo import dev.inmo.tgbotapi.types.files.*
import dev.inmo.tgbotapi.types.files.biggest
/** /**
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
@@ -88,6 +87,38 @@ suspend fun TelegramBot.sendPhoto(
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendPhoto(chat.id, photo, text, parseMode, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendPhoto(chat.id, photo, text, parseMode, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
/**
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
* [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param
*/
suspend fun TelegramBot.sendPhoto(
chatId: ChatIdentifier,
photoSize: PhotoSize,
text: String? = null,
parseMode: ParseMode? = null,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null
) = sendPhoto(chatId, photoSize.fileId, text, parseMode, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
/**
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
* [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param
*/
suspend fun TelegramBot.sendPhoto(
chat: Chat,
photoSize: PhotoSize,
text: String? = null,
parseMode: ParseMode? = null,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null
) = sendPhoto(chat.id, photoSize, text, parseMode, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
/** /**
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
@@ -159,3 +190,33 @@ suspend inline fun TelegramBot.sendPhoto(
allowSendingWithoutReply: Boolean? = null, allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
) = sendPhoto(chat.id, photo, entities, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup) ) = sendPhoto(chat.id, photo, entities, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
/**
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
* [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param
*/
suspend inline fun TelegramBot.sendPhoto(
chatId: ChatIdentifier,
photoSize: PhotoSize,
entities: TextSourcesList,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null
) = sendPhoto(chatId, photoSize.fileId, entities, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)
/**
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or
* [dev.inmo.tgbotapi.extensions.utils.types.buttons.inlineKeyboard] as a builders for that param
*/
suspend inline fun TelegramBot.sendPhoto(
chat: Chat,
photoSize: PhotoSize,
entities: TextSourcesList,
disableNotification: Boolean = false,
protectContent: Boolean = false,
replyToMessageId: MessageIdentifier? = null,
allowSendingWithoutReply: Boolean? = null,
replyMarkup: KeyboardMarkup? = null
) = sendPhoto(chat.id, photoSize, entities, disableNotification, protectContent, replyToMessageId, allowSendingWithoutReply, replyMarkup)

View File

@@ -7,7 +7,7 @@ import dev.inmo.tgbotapi.types.ChatIdentifier
import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.MessageIdentifier
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
import dev.inmo.tgbotapi.types.chat.abstracts.Chat import dev.inmo.tgbotapi.types.chat.abstracts.Chat
import dev.inmo.tgbotapi.types.files.Sticker import dev.inmo.tgbotapi.types.files.sticker.Sticker
/** /**
* @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or * @param replyMarkup Some of [KeyboardMarkup]. See [dev.inmo.tgbotapi.extensions.utils.types.buttons.replyKeyboard] or

View File

@@ -0,0 +1,90 @@
package dev.inmo.tgbotapi.extensions.api.stickers
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.abstracts.FileId
import dev.inmo.tgbotapi.requests.abstracts.MultipartFile
import dev.inmo.tgbotapi.requests.stickers.AddVideoStickerToSet
import dev.inmo.tgbotapi.types.CommonUser
import dev.inmo.tgbotapi.types.UserId
import dev.inmo.tgbotapi.types.stickers.MaskPosition
import dev.inmo.tgbotapi.types.stickers.StickerSet
suspend fun TelegramBot.addVideoStickerToSet(
userId: UserId,
stickerSetName: String,
sticker: FileId,
emojis: String,
maskPosition: MaskPosition? = null
) = execute(
AddVideoStickerToSet(userId, stickerSetName, sticker, emojis, maskPosition)
)
suspend fun TelegramBot.addVideoStickerToSet(
userId: UserId,
stickerSetName: String,
sticker: MultipartFile,
emojis: String,
maskPosition: MaskPosition? = null
) = execute(
AddVideoStickerToSet(userId, stickerSetName, sticker, emojis, maskPosition)
)
suspend fun TelegramBot.addVideoStickerToSet(
user: CommonUser,
stickerSetName: String,
sticker: FileId,
emojis: String,
maskPosition: MaskPosition? = null
) = addVideoStickerToSet(
user.id, stickerSetName, sticker, emojis, maskPosition
)
suspend fun TelegramBot.addVideoStickerToSet(
user: CommonUser,
stickerSetName: String,
sticker: MultipartFile,
emojis: String,
maskPosition: MaskPosition? = null
) = addVideoStickerToSet(
user.id, stickerSetName, sticker, emojis, maskPosition
)
suspend fun TelegramBot.addVideoStickerToSet(
userId: UserId,
stickerSet: StickerSet,
sticker: FileId,
emojis: String,
maskPosition: MaskPosition? = null
) = addVideoStickerToSet(
userId, stickerSet.name, sticker, emojis, maskPosition
)
suspend fun TelegramBot.addVideoStickerToSet(
userId: UserId,
stickerSet: StickerSet,
sticker: MultipartFile,
emojis: String,
maskPosition: MaskPosition? = null
) = addVideoStickerToSet(
userId, stickerSet.name, sticker, emojis, maskPosition
)
suspend fun TelegramBot.addVideoStickerToSet(
user: CommonUser,
stickerSet: StickerSet,
sticker: FileId,
emojis: String,
maskPosition: MaskPosition? = null
) = addVideoStickerToSet(
user.id, stickerSet.name, sticker, emojis, maskPosition
)
suspend fun TelegramBot.addVideoStickerToSet(
user: CommonUser,
stickerSet: StickerSet,
sticker: MultipartFile,
emojis: String,
maskPosition: MaskPosition? = null
) = addVideoStickerToSet(
user.id, stickerSet.name, sticker, emojis, maskPosition
)

View File

@@ -11,44 +11,48 @@ import dev.inmo.tgbotapi.types.stickers.MaskPosition
suspend fun TelegramBot.createNewAnimatedStickerSet( suspend fun TelegramBot.createNewAnimatedStickerSet(
userId: UserId, userId: UserId,
name: String, name: String,
title: String,
sticker: FileId, sticker: FileId,
emojis: String, emojis: String,
containsMasks: Boolean? = null, containsMasks: Boolean? = null,
maskPosition: MaskPosition? = null maskPosition: MaskPosition? = null
) = execute( ) = execute(
CreateNewAnimatedStickerSet(userId, name, sticker, emojis, containsMasks, maskPosition) CreateNewAnimatedStickerSet(userId, name, title, sticker, emojis, containsMasks, maskPosition)
) )
suspend fun TelegramBot.createNewAnimatedStickerSet( suspend fun TelegramBot.createNewAnimatedStickerSet(
userId: UserId, userId: UserId,
name: String, name: String,
title: String,
sticker: MultipartFile, sticker: MultipartFile,
emojis: String, emojis: String,
containsMasks: Boolean? = null, containsMasks: Boolean? = null,
maskPosition: MaskPosition? = null maskPosition: MaskPosition? = null
) = execute( ) = execute(
CreateNewAnimatedStickerSet(userId, name, sticker, emojis, containsMasks, maskPosition) CreateNewAnimatedStickerSet(userId, name, title, sticker, emojis, containsMasks, maskPosition)
) )
suspend fun TelegramBot.createNewAnimatedStickerSet( suspend fun TelegramBot.createNewAnimatedStickerSet(
user: CommonUser, user: CommonUser,
name: String, name: String,
title: String,
sticker: FileId, sticker: FileId,
emojis: String, emojis: String,
containsMasks: Boolean? = null, containsMasks: Boolean? = null,
maskPosition: MaskPosition? = null maskPosition: MaskPosition? = null
) = createNewAnimatedStickerSet( ) = createNewAnimatedStickerSet(
user.id, name, sticker, emojis, containsMasks, maskPosition user.id, name, title, sticker, emojis, containsMasks, maskPosition
) )
suspend fun TelegramBot.createNewAnimatedStickerSet( suspend fun TelegramBot.createNewAnimatedStickerSet(
user: CommonUser, user: CommonUser,
name: String, name: String,
title: String,
sticker: MultipartFile, sticker: MultipartFile,
emojis: String, emojis: String,
containsMasks: Boolean? = null, containsMasks: Boolean? = null,
maskPosition: MaskPosition? = null maskPosition: MaskPosition? = null
) = createNewAnimatedStickerSet( ) = createNewAnimatedStickerSet(
user.id, name, sticker, emojis, containsMasks, maskPosition user.id, name, title, sticker, emojis, containsMasks, maskPosition
) )

View File

@@ -11,44 +11,48 @@ import dev.inmo.tgbotapi.types.stickers.MaskPosition
suspend fun TelegramBot.createNewStaticStickerSet( suspend fun TelegramBot.createNewStaticStickerSet(
userId: UserId, userId: UserId,
name: String, name: String,
title: String,
sticker: FileId, sticker: FileId,
emojis: String, emojis: String,
containsMasks: Boolean? = null, containsMasks: Boolean? = null,
maskPosition: MaskPosition? = null maskPosition: MaskPosition? = null
) = execute( ) = execute(
CreateNewStaticStickerSet(userId, name, sticker, emojis, containsMasks, maskPosition) CreateNewStaticStickerSet(userId, name, title, sticker, emojis, containsMasks, maskPosition)
) )
suspend fun TelegramBot.createNewStaticStickerSet( suspend fun TelegramBot.createNewStaticStickerSet(
userId: UserId, userId: UserId,
name: String, name: String,
title: String,
sticker: MultipartFile, sticker: MultipartFile,
emojis: String, emojis: String,
containsMasks: Boolean? = null, containsMasks: Boolean? = null,
maskPosition: MaskPosition? = null maskPosition: MaskPosition? = null
) = execute( ) = execute(
CreateNewStaticStickerSet(userId, name, sticker, emojis, containsMasks, maskPosition) CreateNewStaticStickerSet(userId, name, title, sticker, emojis, containsMasks, maskPosition)
) )
suspend fun TelegramBot.createNewStaticStickerSet( suspend fun TelegramBot.createNewStaticStickerSet(
user: CommonUser, user: CommonUser,
name: String, name: String,
title: String,
sticker: FileId, sticker: FileId,
emojis: String, emojis: String,
containsMasks: Boolean? = null, containsMasks: Boolean? = null,
maskPosition: MaskPosition? = null maskPosition: MaskPosition? = null
) = createNewStaticStickerSet( ) = createNewStaticStickerSet(
user.id, name, sticker, emojis, containsMasks, maskPosition user.id, name, title, sticker, emojis, containsMasks, maskPosition
) )
suspend fun TelegramBot.createNewStaticStickerSet( suspend fun TelegramBot.createNewStaticStickerSet(
user: CommonUser, user: CommonUser,
name: String, name: String,
title: String,
sticker: MultipartFile, sticker: MultipartFile,
emojis: String, emojis: String,
containsMasks: Boolean? = null, containsMasks: Boolean? = null,
maskPosition: MaskPosition? = null maskPosition: MaskPosition? = null
) = createNewStaticStickerSet( ) = createNewStaticStickerSet(
user.id, name, sticker, emojis, containsMasks, maskPosition user.id, name, title, sticker, emojis, containsMasks, maskPosition
) )

View File

@@ -0,0 +1,58 @@
package dev.inmo.tgbotapi.extensions.api.stickers
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.abstracts.FileId
import dev.inmo.tgbotapi.requests.abstracts.MultipartFile
import dev.inmo.tgbotapi.requests.stickers.CreateNewVideoStickerSet
import dev.inmo.tgbotapi.types.CommonUser
import dev.inmo.tgbotapi.types.UserId
import dev.inmo.tgbotapi.types.stickers.MaskPosition
suspend fun TelegramBot.createNewVideoStickerSet(
userId: UserId,
name: String,
title: String,
sticker: FileId,
emojis: String,
containsMasks: Boolean? = null,
maskPosition: MaskPosition? = null
) = execute(
CreateNewVideoStickerSet(userId, name, title, sticker, emojis, containsMasks, maskPosition)
)
suspend fun TelegramBot.createNewVideoStickerSet(
userId: UserId,
name: String,
title: String,
sticker: MultipartFile,
emojis: String,
containsMasks: Boolean? = null,
maskPosition: MaskPosition? = null
) = execute(
CreateNewVideoStickerSet(userId, name, title, sticker, emojis, containsMasks, maskPosition)
)
suspend fun TelegramBot.createNewVideoStickerSet(
user: CommonUser,
name: String,
title: String,
sticker: FileId,
emojis: String,
containsMasks: Boolean? = null,
maskPosition: MaskPosition? = null
) = createNewVideoStickerSet(
user.id, name, title, sticker, emojis, containsMasks, maskPosition
)
suspend fun TelegramBot.createNewVideoStickerSet(
user: CommonUser,
name: String,
title: String,
sticker: MultipartFile,
emojis: String,
containsMasks: Boolean? = null,
maskPosition: MaskPosition? = null
) = createNewVideoStickerSet(
user.id, name, title, sticker, emojis, containsMasks, maskPosition
)

View File

@@ -3,7 +3,7 @@ package dev.inmo.tgbotapi.extensions.api.stickers
import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.requests.abstracts.FileId
import dev.inmo.tgbotapi.requests.stickers.DeleteStickerFromSet import dev.inmo.tgbotapi.requests.stickers.DeleteStickerFromSet
import dev.inmo.tgbotapi.types.files.Sticker import dev.inmo.tgbotapi.types.files.sticker.Sticker
suspend fun TelegramBot.deleteStickerFromSet( suspend fun TelegramBot.deleteStickerFromSet(
sticker: FileId sticker: FileId

View File

@@ -3,7 +3,7 @@ package dev.inmo.tgbotapi.extensions.api.stickers
import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.requests.abstracts.FileId
import dev.inmo.tgbotapi.requests.stickers.SetStickerPositionInSet import dev.inmo.tgbotapi.requests.stickers.SetStickerPositionInSet
import dev.inmo.tgbotapi.types.files.Sticker import dev.inmo.tgbotapi.types.files.sticker.Sticker
suspend fun TelegramBot.setStickerPositionInSet( suspend fun TelegramBot.setStickerPositionInSet(
sticker: FileId, sticker: FileId,

View File

@@ -17,8 +17,9 @@ plugins {
project.version = "$library_version" project.version = "$library_version"
project.group = "$library_group" project.group = "$library_group"
project.description = "Behaviour Builder extension with built-in FSM"
apply from: "publish.gradle" apply from: "../publish.gradle"
repositories { repositories {
mavenLocal() mavenLocal()

View File

@@ -1 +0,0 @@
{"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"}],"mavenConfig":{"name":"Telegram Bot Behaviour Builder FSM Extensions","description":"FSM extension for dev.inmo:tgbotapi.extensions.behaviour_builder.fsm","url":"https://insanusmokrassar.github.io/TelegramBotAPI/tgbotapi.extensions.behaviour_builder","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/"}]}}

View File

@@ -1,69 +0,0 @@
apply plugin: 'maven-publish'
apply plugin: 'signing'
task javadocsJar(type: Jar) {
classifier = 'javadoc'
}
publishing {
publications.all {
artifact javadocsJar
pom {
description = "FSM extension for dev.inmo:tgbotapi.extensions.behaviour_builder.fsm"
name = "Telegram Bot Behaviour Builder FSM Extensions"
url = "https://insanusmokrassar.github.io/TelegramBotAPI/tgbotapi.extensions.behaviour_builder"
scm {
developerConnection = "scm:git:[fetch=]https://github.com/insanusmokrassar/TelegramBotAPI.git[push=]https://github.com/insanusmokrassar/TelegramBotAPI.git"
url = "https://github.com/insanusmokrassar/TelegramBotAPI.git"
}
developers {
developer {
id = "InsanusMokrassar"
name = "Ovsiannikov Aleksei"
email = "ovsyannikov.alexey95@gmail.com"
}
}
licenses {
license {
name = "Apache Software License 2.0"
url = "https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"
}
}
}
repositories {
if ((project.hasProperty('GITHUBPACKAGES_USER') || System.getenv('GITHUBPACKAGES_USER') != null) && (project.hasProperty('GITHUBPACKAGES_PASSWORD') || System.getenv('GITHUBPACKAGES_PASSWORD') != null)) {
maven {
name = "GithubPackages"
url = uri("https://maven.pkg.github.com/InsanusMokrassar/TelegramBotAPI")
credentials {
username = project.hasProperty('GITHUBPACKAGES_USER') ? project.property('GITHUBPACKAGES_USER') : System.getenv('GITHUBPACKAGES_USER')
password = project.hasProperty('GITHUBPACKAGES_PASSWORD') ? project.property('GITHUBPACKAGES_PASSWORD') : System.getenv('GITHUBPACKAGES_PASSWORD')
}
}
}
if ((project.hasProperty('SONATYPE_USER') || System.getenv('SONATYPE_USER') != null) && (project.hasProperty('SONATYPE_PASSWORD') || System.getenv('SONATYPE_PASSWORD') != null)) {
maven {
name = "sonatype"
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials {
username = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : System.getenv('SONATYPE_USER')
password = project.hasProperty('SONATYPE_PASSWORD') ? project.property('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD')
}
}
}
}
}
}
signing {
useGpgCmd()
sign publishing.publications
}

View File

@@ -17,8 +17,9 @@ plugins {
project.version = "$library_version" project.version = "$library_version"
project.group = "$library_group" project.group = "$library_group"
project.description = "Behaviour Builder DSL"
apply from: "publish.gradle" apply from: "../publish.gradle"
repositories { repositories {
mavenLocal() mavenLocal()

View File

@@ -1 +0,0 @@
{"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 Steps Extensions","description":"This extensions project contains tools for simple interaction with chats","url":"https://insanusmokrassar.github.io/TelegramBotAPI/tgbotapi.extensions.steps","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/"}]}}

View File

@@ -1,69 +0,0 @@
apply plugin: 'maven-publish'
apply plugin: 'signing'
task javadocsJar(type: Jar) {
classifier = 'javadoc'
}
publishing {
publications.all {
artifact javadocsJar
pom {
description = "This extensions project contains tools for simple interaction with chats"
name = "Telegram Bot API Steps Extensions"
url = "https://insanusmokrassar.github.io/TelegramBotAPI/tgbotapi.extensions.steps"
scm {
developerConnection = "scm:git:[fetch=]https://github.com/insanusmokrassar/TelegramBotAPI.git[push=]https://github.com/insanusmokrassar/TelegramBotAPI.git"
url = "https://github.com/insanusmokrassar/TelegramBotAPI.git"
}
developers {
developer {
id = "InsanusMokrassar"
name = "Ovsiannikov Aleksei"
email = "ovsyannikov.alexey95@gmail.com"
}
}
licenses {
license {
name = "Apache Software License 2.0"
url = "https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"
}
}
}
repositories {
if ((project.hasProperty('GITHUBPACKAGES_USER') || System.getenv('GITHUBPACKAGES_USER') != null) && (project.hasProperty('GITHUBPACKAGES_PASSWORD') || System.getenv('GITHUBPACKAGES_PASSWORD') != null)) {
maven {
name = "GithubPackages"
url = uri("https://maven.pkg.github.com/InsanusMokrassar/TelegramBotAPI")
credentials {
username = project.hasProperty('GITHUBPACKAGES_USER') ? project.property('GITHUBPACKAGES_USER') : System.getenv('GITHUBPACKAGES_USER')
password = project.hasProperty('GITHUBPACKAGES_PASSWORD') ? project.property('GITHUBPACKAGES_PASSWORD') : System.getenv('GITHUBPACKAGES_PASSWORD')
}
}
}
if ((project.hasProperty('SONATYPE_USER') || System.getenv('SONATYPE_USER') != null) && (project.hasProperty('SONATYPE_PASSWORD') || System.getenv('SONATYPE_PASSWORD') != null)) {
maven {
name = "sonatype"
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials {
username = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : System.getenv('SONATYPE_USER')
password = project.hasProperty('SONATYPE_PASSWORD') ? project.property('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD')
}
}
}
}
}
}
signing {
useGpgCmd()
sign publishing.publications
}

View File

@@ -234,3 +234,10 @@ suspend fun BehaviourContext.waitSuccessfulPaymentEvents(
filter: SimpleFilter<ChatEventMessage<SuccessfulPaymentEvent>>? = null, filter: SimpleFilter<ChatEventMessage<SuccessfulPaymentEvent>>? = null,
mapper: EventMessageToEventMapper<SuccessfulPaymentEvent>? = null mapper: EventMessageToEventMapper<SuccessfulPaymentEvent>? = null
) = waitEvents(count, initRequest, errorFactory, filter, mapper) ) = waitEvents(count, initRequest, errorFactory, filter, mapper)
suspend fun BehaviourContext.waitUserLoggedInEvents(
initRequest: Request<*>? = null,
errorFactory: NullableRequestBuilder<*> = { null },
count: Int = 1,
filter: SimpleFilter<ChatEventMessage<UserLoggedIn>>? = null,
mapper: EventMessageToEventMapper<UserLoggedIn>? = null
) = waitEvents(count, initRequest, errorFactory, filter, mapper)

View File

@@ -464,3 +464,22 @@ suspend fun <BC : BehaviourContext> BC.onSuccessfulPayment(
markerFactory: MarkerFactory<in ChatEventMessage<SuccessfulPaymentEvent>, Any> = ByChatMessageMarkerFactory, markerFactory: MarkerFactory<in ChatEventMessage<SuccessfulPaymentEvent>, Any> = ByChatMessageMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<SuccessfulPaymentEvent>> scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<SuccessfulPaymentEvent>>
) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver) ) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)
/**
* @param initialFilter This filter will be called to remove unnecessary data BEFORE [scenarioReceiver] call
* @param subcontextUpdatesFilter This filter will be applied to each update inside of [scenarioReceiver]. For example,
* this filter will be used if you will call [dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.waitContentMessage].
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTwoTypesReceiver] function to create your own.
* Use [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.plus] or [dev.inmo.tgbotapi.extensions.behaviour_builder.utils.times]
* to combinate several filters
* @param markerFactory Will be used to identify different "stream". [scenarioReceiver] will be called synchronously
* in one "stream". Output of [markerFactory] will be used as a key for "stream"
* @param scenarioReceiver Main callback which will be used to handle incoming data if [initialFilter] will pass that
* data
*/
suspend fun <BC : BehaviourContext> BC.onUserLoggedIn(
initialFilter: SimpleFilter<ChatEventMessage<UserLoggedIn>>? = null,
subcontextUpdatesFilter: CustomBehaviourContextAndTwoTypesReceiver<BC, Boolean, ChatEventMessage<UserLoggedIn>, Update>? = MessageFilterByChat,
markerFactory: MarkerFactory<in ChatEventMessage<UserLoggedIn>, Any> = ByChatMessageMarkerFactory,
scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, ChatEventMessage<UserLoggedIn>>
) = onEvent(initialFilter, subcontextUpdatesFilter, markerFactory, scenarioReceiver)

View File

@@ -22,7 +22,11 @@ internal suspend inline fun <BC : BehaviourContext, reified T : MediaGroupConten
markerFactory: MarkerFactory<in List<MediaGroupMessage<T>>, Any> = ByChatMediaGroupMarkerFactory, markerFactory: MarkerFactory<in List<MediaGroupMessage<T>>, Any> = ByChatMediaGroupMarkerFactory,
noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, List<MediaGroupMessage<T>>> noinline scenarioReceiver: CustomBehaviourContextAndTypeReceiver<BC, Unit, List<MediaGroupMessage<T>>>
) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) { ) = on(markerFactory, initialFilter, subcontextUpdatesFilter, scenarioReceiver) {
(it.asSentMediaGroupUpdate() ?.data ?.takeIf { it.all { it is T } } as? List<MediaGroupMessage<T>>) ?.let(::listOfNotNull) (it.asSentMediaGroupUpdate() ?.data ?.takeIf { messages ->
messages.all { message ->
message.content is T
}
} as? List<MediaGroupMessage<T>>) ?.let(::listOfNotNull)
} }
/** /**

View File

@@ -4,6 +4,27 @@ typealias SimpleFilter<T> = suspend (T) -> Boolean
inline fun <T> SimpleFilter(noinline block: SimpleFilter<T>) = block inline fun <T> SimpleFilter(noinline block: SimpleFilter<T>) = block
/**
* @return [SimpleFilter] which will return true in case when all the items in incoming data passed [this] filter
*/
fun <T> SimpleFilter<T>.listAll() = SimpleFilter<Iterable<T>> {
it.all { this@listAll(it) }
}
/**
* @return [SimpleFilter] which will return true in case when there is any item in incoming data passed [this] filter
*/
fun <T> SimpleFilter<T>.listAny() = SimpleFilter<Iterable<T>> {
it.any { this@listAny(it) }
}
/**
* @return [SimpleFilter] which will return true in case when there is no any item in incoming data passed [this] filter
*/
fun <T> SimpleFilter<T>.listNone() = SimpleFilter<Iterable<T>> {
it.none { this@listNone(it) }
}
/** /**
* Makes an AND (&&) operation between [this] and [other] * Makes an AND (&&) operation between [this] and [other]
*/ */

View File

@@ -17,8 +17,9 @@ plugins {
project.version = "$library_version" project.version = "$library_version"
project.group = "$library_group" project.group = "$library_group"
project.description = "Core part of tgbotapi with all (and only) required functionality for working with Telegram Bot API"
apply from: "publish.gradle" apply from: "../publish.gradle"
repositories { repositories {
mavenLocal() mavenLocal()

View File

@@ -1 +0,0 @@
{"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/"}]}}

View File

@@ -1,69 +0,0 @@
apply plugin: 'maven-publish'
apply plugin: 'signing'
task javadocsJar(type: Jar) {
classifier = 'javadoc'
}
publishing {
publications.all {
artifact javadocsJar
pom {
description = "Library for Object-Oriented and type-safe work with Telegram Bot API"
name = "Telegram Bot API Core"
url = "https://insanusmokrassar.github.io/TelegramBotAPI"
scm {
developerConnection = "scm:git:[fetch=]https://github.com/insanusmokrassar/TelegramBotAPI.git[push=]https://github.com/insanusmokrassar/TelegramBotAPI.git"
url = "https://github.com/insanusmokrassar/TelegramBotAPI.git"
}
developers {
developer {
id = "InsanusMokrassar"
name = "Ovsiannikov Aleksei"
email = "ovsyannikov.alexey95@gmail.com"
}
}
licenses {
license {
name = "Apache Software License 2.0"
url = "https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"
}
}
}
repositories {
if ((project.hasProperty('GITHUBPACKAGES_USER') || System.getenv('GITHUBPACKAGES_USER') != null) && (project.hasProperty('GITHUBPACKAGES_PASSWORD') || System.getenv('GITHUBPACKAGES_PASSWORD') != null)) {
maven {
name = "GithubPackages"
url = uri("https://maven.pkg.github.com/InsanusMokrassar/TelegramBotAPI")
credentials {
username = project.hasProperty('GITHUBPACKAGES_USER') ? project.property('GITHUBPACKAGES_USER') : System.getenv('GITHUBPACKAGES_USER')
password = project.hasProperty('GITHUBPACKAGES_PASSWORD') ? project.property('GITHUBPACKAGES_PASSWORD') : System.getenv('GITHUBPACKAGES_PASSWORD')
}
}
}
if ((project.hasProperty('SONATYPE_USER') || System.getenv('SONATYPE_USER') != null) && (project.hasProperty('SONATYPE_PASSWORD') || System.getenv('SONATYPE_PASSWORD') != null)) {
maven {
name = "sonatype"
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials {
username = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : System.getenv('SONATYPE_USER')
password = project.hasProperty('SONATYPE_PASSWORD') ? project.property('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD')
}
}
}
}
}
}
signing {
useGpgCmd()
sign publishing.publications
}

View File

@@ -0,0 +1,224 @@
package dev.inmo.tgbotapi.bot.multiserver
import dev.inmo.tgbotapi.bot.Ktor.KtorRequestsExecutorBuilder
import dev.inmo.tgbotapi.bot.Ktor.telegramBot
import dev.inmo.tgbotapi.bot.RequestsExecutor
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.abstracts.Request
import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper
import dev.inmo.tgbotapi.utils.telegramBotAPIDefaultUrl
import kotlinx.coroutines.*
import kotlin.js.JsName
import kotlin.jvm.JvmName
/**
* This type of [RequestsExecutor] (aka [TelegramBot]) has been created to aggregate several bots under the hood and make
* requests, for example, with changing of api url
*
* @param bots Bots which will be used to [execute] [Request]s
* @param botSelector It is strategy by which the bot is selected for the execution. This lambda will receive **-1**
* when request execution just started and this call is first in context of one [execute]. By default, will select next
* [TelegramBot] when called (or first when current index is last or -1)
* @param onClose This method will be called inside of [close] method. By default, will close all [bots]
*/
class SimpleMultiServerRequestsExecutor(
private val bots: List<TelegramBot>,
private val botSelector: suspend List<TelegramBot>.(currentBotIndex: Int, t: Throwable?) -> TelegramBot = { i, _ ->
getOrElse(i + 1) { first() }
},
private val onClose: () -> Unit = {
bots.forEach(TelegramBot::close)
}
) : RequestsExecutor {
override suspend fun <T : Any> execute(request: Request<T>): T {
var currentBot = bots.botSelector(-1, null)
while (currentCoroutineContext().isActive) {
val i = bots.indexOf(currentBot)
runCatching {
currentBot.execute(request)
}.onSuccess {
return it
}.onFailure {
currentBot = bots.botSelector(i, it)
}
}
error("Coroutine has been terminated")
}
override fun close() {
onClose()
}
companion object {
/**
* @param keepers Will be used to create result [bots]
* @param builder Will be called with each item from [keepers] in process of bots creation
* @param botSelector It is strategy by which the bot is selected for the execution. This lambda will receive **-1**
* when request execution just started and this call is first in context of one [execute]. By default, will select next
* [TelegramBot] when called (or first when current index is last or -1)
* @param onClose This method will be called inside of [close] method. By default, will close all [bots]
*/
@JvmName("createByUrlsKeepers")
@JsName("createByUrlsKeepers")
inline operator fun invoke(
keepers: Iterable<TelegramAPIUrlsKeeper>,
crossinline builder: KtorRequestsExecutorBuilder.(TelegramAPIUrlsKeeper) -> Unit = {},
noinline botSelector: suspend List<TelegramBot>.(currentBotIndex: Int, t: Throwable?) -> TelegramBot = { i, _ ->
getOrElse(i + 1) { first() }
},
noinline onClose: ((List<TelegramBot>) -> Unit)? = null
): SimpleMultiServerRequestsExecutor {
val bots = keepers.map { telegramBot(it) { builder(it) } }
return if (onClose == null) {
SimpleMultiServerRequestsExecutor(bots, botSelector)
} else {
SimpleMultiServerRequestsExecutor(bots, botSelector) {
onClose(bots)
}
}
}
/**
* @param tokens Will be used to create result [bots]
* @param builder Will be called with each item from [tokens] in process of bots creation
* @param botSelector It is strategy by which the bot is selected for the execution. This lambda will receive **-1**
* when request execution just started and this call is first in context of one [execute]. By default, will select next
* [TelegramBot] when called (or first when current index is last or -1)
* @param onClose This method will be called inside of [close] method. By default, will close all [bots]
*/
@JvmName("createByTokens")
@JsName("createByTokens")
inline operator fun invoke(
tokens: Iterable<String>,
crossinline builder: KtorRequestsExecutorBuilder.(String) -> Unit = {},
noinline botSelector: suspend List<TelegramBot>.(currentBotIndex: Int, t: Throwable?) -> TelegramBot = { i, _ ->
getOrElse(i + 1) { first() }
},
noinline onClose: ((List<TelegramBot>) -> Unit)? = null
): SimpleMultiServerRequestsExecutor {
val bots = tokens.map { telegramBot(it) { builder(it) } }
return if (onClose == null) {
SimpleMultiServerRequestsExecutor(bots, botSelector)
} else {
SimpleMultiServerRequestsExecutor(bots, botSelector) {
onClose(bots)
}
}
}
/**
* @param tokens [Pair]s with first parameter as a token and second parameter api url. Will be used to create
* result [bots]
* @param builder Will be called with each item from [tokens] in process of bots creation
* @param botSelector It is strategy by which the bot is selected for the execution. This lambda will receive **-1**
* when request execution just started and this call is first in context of one [execute]. By default, will select next
* [TelegramBot] when called (or first when current index is last or -1)
* @param onClose This method will be called inside of [close] method. By default, will close all [bots]
*/
@JvmName("createByTokensAndApiUrls")
@JsName("createByTokensAndApiUrls")
inline operator fun invoke(
tokens: Iterable<Pair<String, String>>,
crossinline builder: KtorRequestsExecutorBuilder.(Pair<String, String>) -> Unit = {},
noinline botSelector: suspend List<TelegramBot>.(currentBotIndex: Int, t: Throwable?) -> TelegramBot = { i, _ ->
getOrElse(i + 1) { first() }
},
noinline onClose: ((List<TelegramBot>) -> Unit)? = null
): SimpleMultiServerRequestsExecutor {
val bots = tokens.map { telegramBot(it.first, it.second) { builder(it) } }
return if (onClose == null) {
SimpleMultiServerRequestsExecutor(bots, botSelector)
} else {
SimpleMultiServerRequestsExecutor(bots, botSelector) {
onClose(bots)
}
}
}
}
}
/**
* Creates [SimpleMultiServerRequestsExecutor]
*
* @param bots Bots which will be used to [SimpleMultiServerRequestsExecutor.execute] [Request]s
* @param botSelector It is strategy by which the bot is selected for the execution. This lambda will receive **-1**
* when request execution just started and this call is first in context of one
* [SimpleMultiServerRequestsExecutor.execute]. By default, will select next [TelegramBot] when called (or first when
* current index is last or -1)
* @param onClose This method will be called inside of [SimpleMultiServerRequestsExecutor.close] method. By default, will close all [bots]
*/
@Suppress("NOTHING_TO_INLINE")
inline fun telegramBot(
bots: List<TelegramBot>,
noinline botSelector: suspend List<TelegramBot>.(currentBotIndex: Int, t: Throwable?) -> TelegramBot = { i, _ ->
getOrElse(i + 1) { first() }
},
noinline onClose: () -> Unit = {
bots.forEach(TelegramBot::close)
}
): TelegramBot = SimpleMultiServerRequestsExecutor(bots, botSelector, onClose)
/**
* @param keepers Will be used to create result [SimpleMultiServerRequestsExecutor.bots]
* @param builder Will be called with each item from [keepers] in process of bots creation
* @param botSelector It is strategy by which the bot is selected for the execution. This lambda will receive **-1**
* when request execution just started and this call is first in context of one
* [SimpleMultiServerRequestsExecutor.execute]. By default, will select next [TelegramBot] when called (or first when
* current index is last or -1)
* @param onClose This method will be called inside of [SimpleMultiServerRequestsExecutor.close] method. By default,
* will close all [SimpleMultiServerRequestsExecutor.bots]
*/
@JvmName("telegramBotByApiUrlsKeepers")
@JsName("telegramBotByApiUrlsKeepers")
inline fun telegramBot(
keepers: Iterable<TelegramAPIUrlsKeeper>,
crossinline builder: KtorRequestsExecutorBuilder.(TelegramAPIUrlsKeeper) -> Unit = {},
noinline botSelector: suspend List<TelegramBot>.(currentBotIndex: Int, t: Throwable?) -> TelegramBot = { i, _ ->
getOrElse(i + 1) { first() }
},
noinline onClose: ((List<TelegramBot>) -> Unit)? = null
): TelegramBot = SimpleMultiServerRequestsExecutor(keepers, builder, botSelector, onClose)
/**
* @param tokens Will be used to create result [SimpleMultiServerRequestsExecutor.bots]
* @param builder Will be called with each item from [tokens] in process of bots creation
* @param botSelector It is strategy by which the bot is selected for the execution. This lambda will receive **-1**
* when request execution just started and this call is first in context of one
* [SimpleMultiServerRequestsExecutor.execute]. By default, will select next [TelegramBot] when called (or first when
* current index is last or -1)
* @param onClose This method will be called inside of [SimpleMultiServerRequestsExecutor.close] method. By default,
* will close all [SimpleMultiServerRequestsExecutor.bots]
*/
@JvmName("telegramBotByTokens")
@JsName("telegramBotByTokens")
inline fun telegramBot(
tokens: Iterable<String>,
crossinline builder: KtorRequestsExecutorBuilder.(String) -> Unit = {},
noinline botSelector: suspend List<TelegramBot>.(currentBotIndex: Int, t: Throwable?) -> TelegramBot = { i, _ ->
getOrElse(i + 1) { first() }
},
noinline onClose: ((List<TelegramBot>) -> Unit)? = null
): TelegramBot = SimpleMultiServerRequestsExecutor(tokens, builder, botSelector, onClose)
/**
* @param tokens [Pair]s with first parameter as a token and second parameter api url. Will be used to create
* result [SimpleMultiServerRequestsExecutor.bots]
* @param builder Will be called with each item from [tokens] in process of bots creation
* @param botSelector It is strategy by which the bot is selected for the execution. This lambda will receive **-1**
* when request execution just started and this call is first in context of one
* [SimpleMultiServerRequestsExecutor.execute]. By default, will select next
* [TelegramBot] when called (or first when current index is last or -1)
* @param onClose This method will be called inside of [SimpleMultiServerRequestsExecutor.close] method. By default,
* will close all [SimpleMultiServerRequestsExecutor.bots]
*/
@JvmName("telegramBotByTokensAndApiUrls")
@JsName("telegramBotByTokensAndApiUrls")
inline fun telegramBot(
tokens: Iterable<Pair<String, String>>,
crossinline builder: KtorRequestsExecutorBuilder.(Pair<String, String>) -> Unit = {},
noinline botSelector: suspend List<TelegramBot>.(currentBotIndex: Int, t: Throwable?) -> TelegramBot = { i, _ ->
getOrElse(i + 1) { first() }
},
noinline onClose: ((List<TelegramBot>) -> Unit)? = null
): TelegramBot = SimpleMultiServerRequestsExecutor(tokens, builder, botSelector, onClose)

View File

@@ -18,7 +18,7 @@ fun AddAnimatedStickerToSet(
return when (sticker) { return when (sticker) {
is MultipartFile -> CommonMultipartFileRequest( is MultipartFile -> CommonMultipartFileRequest(
data, data,
mapOf(pngStickerField to sticker) mapOf(tgsStickerField to sticker)
) )
is FileId -> data is FileId -> data
} }

View File

@@ -0,0 +1,50 @@
package dev.inmo.tgbotapi.requests.stickers
import dev.inmo.tgbotapi.requests.abstracts.*
import dev.inmo.tgbotapi.requests.common.CommonMultipartFileRequest
import dev.inmo.tgbotapi.requests.stickers.abstracts.StandardStickerSetAction
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.stickers.MaskPosition
import kotlinx.serialization.*
fun AddVideoStickerToSet(
userId: UserId,
stickerSetName: String,
sticker: InputFile,
emojis: String,
maskPosition: MaskPosition? = null
): Request<Boolean> {
val data = AddVideoStickerToSet(userId, stickerSetName, emojis, sticker as? FileId, maskPosition)
return when (sticker) {
is MultipartFile -> CommonMultipartFileRequest(
data,
mapOf(webmStickerField to sticker)
)
is FileId -> data
}
}
@Serializable
data class AddVideoStickerToSet internal constructor(
@SerialName(userIdField)
override val userId: UserId,
@SerialName(nameField)
override val name: String,
@SerialName(emojisField)
override val emojis: String,
@SerialName(webmStickerField)
val sticker: FileId? = null,
@SerialName(maskPositionField)
override val maskPosition: MaskPosition? = null
) : StandardStickerSetAction {
init {
if(emojis.isEmpty()) {
throw IllegalArgumentException("Emojis must not be empty")
}
}
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
override fun method(): String = "addStickerToSet"
}

View File

@@ -2,6 +2,7 @@ package dev.inmo.tgbotapi.requests.stickers
import dev.inmo.tgbotapi.requests.abstracts.* import dev.inmo.tgbotapi.requests.abstracts.*
import dev.inmo.tgbotapi.requests.common.CommonMultipartFileRequest import dev.inmo.tgbotapi.requests.common.CommonMultipartFileRequest
import dev.inmo.tgbotapi.requests.stickers.abstracts.CreateStickerSetAction
import dev.inmo.tgbotapi.requests.stickers.abstracts.StandardStickerSetAction import dev.inmo.tgbotapi.requests.stickers.abstracts.StandardStickerSetAction
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.stickers.MaskPosition import dev.inmo.tgbotapi.types.stickers.MaskPosition
@@ -10,16 +11,17 @@ import kotlinx.serialization.*
fun CreateNewAnimatedStickerSet( fun CreateNewAnimatedStickerSet(
userId: UserId, userId: UserId,
name: String, name: String,
title: String,
sticker: InputFile, sticker: InputFile,
emojis: String, emojis: String,
containsMasks: Boolean? = null, containsMasks: Boolean? = null,
maskPosition: MaskPosition? = null maskPosition: MaskPosition? = null
): Request<Boolean> { ): Request<Boolean> {
val data = CreateNewAnimatedStickerSet(userId, name, emojis, sticker as? FileId, containsMasks, maskPosition) val data = CreateNewAnimatedStickerSet(userId, name, title, emojis, sticker as? FileId, containsMasks, maskPosition)
return when (sticker) { return when (sticker) {
is MultipartFile -> CommonMultipartFileRequest( is MultipartFile -> CommonMultipartFileRequest(
data, data,
mapOf(pngStickerField to sticker) mapOf(tgsStickerField to sticker)
) )
is FileId -> data is FileId -> data
} }
@@ -31,6 +33,8 @@ data class CreateNewAnimatedStickerSet internal constructor(
override val userId: UserId, override val userId: UserId,
@SerialName(nameField) @SerialName(nameField)
override val name: String, override val name: String,
@SerialName(titleField)
override val title: String,
@SerialName(emojisField) @SerialName(emojisField)
override val emojis: String, override val emojis: String,
@SerialName(tgsStickerField) @SerialName(tgsStickerField)
@@ -39,7 +43,7 @@ data class CreateNewAnimatedStickerSet internal constructor(
val containsMasks: Boolean? = null, val containsMasks: Boolean? = null,
@SerialName(maskPositionField) @SerialName(maskPositionField)
override val maskPosition: MaskPosition? = null override val maskPosition: MaskPosition? = null
) : StandardStickerSetAction { ) : CreateStickerSetAction {
init { init {
if(emojis.isEmpty()) { if(emojis.isEmpty()) {
throw IllegalArgumentException("Emojis must not be empty") throw IllegalArgumentException("Emojis must not be empty")

View File

@@ -2,6 +2,7 @@ package dev.inmo.tgbotapi.requests.stickers
import dev.inmo.tgbotapi.requests.abstracts.* import dev.inmo.tgbotapi.requests.abstracts.*
import dev.inmo.tgbotapi.requests.common.CommonMultipartFileRequest import dev.inmo.tgbotapi.requests.common.CommonMultipartFileRequest
import dev.inmo.tgbotapi.requests.stickers.abstracts.CreateStickerSetAction
import dev.inmo.tgbotapi.requests.stickers.abstracts.StandardStickerSetAction import dev.inmo.tgbotapi.requests.stickers.abstracts.StandardStickerSetAction
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.stickers.MaskPosition import dev.inmo.tgbotapi.types.stickers.MaskPosition
@@ -10,12 +11,13 @@ import kotlinx.serialization.*
fun CreateNewStaticStickerSet( fun CreateNewStaticStickerSet(
userId: UserId, userId: UserId,
name: String, name: String,
title: String,
sticker: InputFile, sticker: InputFile,
emojis: String, emojis: String,
containsMasks: Boolean? = null, containsMasks: Boolean? = null,
maskPosition: MaskPosition? = null maskPosition: MaskPosition? = null
): Request<Boolean> { ): Request<Boolean> {
val data = CreateNewStaticStickerSet(userId, name, emojis, sticker as? FileId, containsMasks, maskPosition) val data = CreateNewStaticStickerSet(userId, name, title, emojis, sticker as? FileId, containsMasks, maskPosition)
return when (sticker) { return when (sticker) {
is MultipartFile -> CommonMultipartFileRequest( is MultipartFile -> CommonMultipartFileRequest(
data, data,
@@ -28,11 +30,12 @@ fun CreateNewStaticStickerSet(
fun CreateNewStickerSet( fun CreateNewStickerSet(
userId: UserId, userId: UserId,
name: String, name: String,
title: String,
sticker: InputFile, sticker: InputFile,
emojis: String, emojis: String,
containsMasks: Boolean? = null, containsMasks: Boolean? = null,
maskPosition: MaskPosition? = null maskPosition: MaskPosition? = null
): Request<Boolean> = CreateNewStaticStickerSet(userId, name, sticker, emojis, containsMasks, maskPosition) ): Request<Boolean> = CreateNewStaticStickerSet(userId, name, title, sticker, emojis, containsMasks, maskPosition)
@Serializable @Serializable
data class CreateNewStaticStickerSet internal constructor( data class CreateNewStaticStickerSet internal constructor(
@@ -40,6 +43,8 @@ data class CreateNewStaticStickerSet internal constructor(
override val userId: UserId, override val userId: UserId,
@SerialName(nameField) @SerialName(nameField)
override val name: String, override val name: String,
@SerialName(titleField)
override val title: String,
@SerialName(emojisField) @SerialName(emojisField)
override val emojis: String, override val emojis: String,
@SerialName(pngStickerField) @SerialName(pngStickerField)
@@ -48,7 +53,7 @@ data class CreateNewStaticStickerSet internal constructor(
val containsMasks: Boolean? = null, val containsMasks: Boolean? = null,
@SerialName(maskPositionField) @SerialName(maskPositionField)
override val maskPosition: MaskPosition? = null override val maskPosition: MaskPosition? = null
) : StandardStickerSetAction { ) : CreateStickerSetAction {
init { init {
if(emojis.isEmpty()) { if(emojis.isEmpty()) {
throw IllegalArgumentException("Emojis must not be empty") throw IllegalArgumentException("Emojis must not be empty")

View File

@@ -0,0 +1,57 @@
package dev.inmo.tgbotapi.requests.stickers
import dev.inmo.tgbotapi.requests.abstracts.*
import dev.inmo.tgbotapi.requests.common.CommonMultipartFileRequest
import dev.inmo.tgbotapi.requests.stickers.abstracts.CreateStickerSetAction
import dev.inmo.tgbotapi.requests.stickers.abstracts.StandardStickerSetAction
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.stickers.MaskPosition
import kotlinx.serialization.*
fun CreateNewVideoStickerSet(
userId: UserId,
linkName: String,
title: String,
sticker: InputFile,
emojis: String,
containsMasks: Boolean? = null,
maskPosition: MaskPosition? = null
): Request<Boolean> {
val data = CreateNewVideoStickerSet(userId, linkName, title, emojis, sticker as? FileId, containsMasks, maskPosition)
return when (sticker) {
is MultipartFile -> CommonMultipartFileRequest(
data,
mapOf(webmStickerField to sticker)
)
is FileId -> data
}
}
@Serializable
data class CreateNewVideoStickerSet internal constructor(
@SerialName(userIdField)
override val userId: UserId,
@SerialName(nameField)
override val name: String,
@SerialName(titleField)
override val title: String,
@SerialName(emojisField)
override val emojis: String,
@SerialName(webmStickerField)
val sticker: FileId? = null,
@SerialName(containsMasksField)
val containsMasks: Boolean? = null,
@SerialName(maskPositionField)
override val maskPosition: MaskPosition? = null
) : CreateStickerSetAction {
init {
if(emojis.isEmpty()) {
throw IllegalArgumentException("Emojis must not be empty")
}
}
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
override fun method(): String = "createNewStickerSet"
}

View File

@@ -0,0 +1,5 @@
package dev.inmo.tgbotapi.requests.stickers.abstracts
interface CreateStickerSetAction : StandardStickerSetAction {
val title: String
}

View File

@@ -1,7 +1,8 @@
package dev.inmo.tgbotapi.types.CallbackQuery package dev.inmo.tgbotapi.types.CallbackQuery
import dev.inmo.tgbotapi.types.message.abstracts.Message import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
sealed interface MessageCallbackQuery : CallbackQuery { sealed interface MessageCallbackQuery : CallbackQuery {
val message: Message val message: ContentMessage<MessageContent>
} }

View File

@@ -2,12 +2,13 @@ package dev.inmo.tgbotapi.types.CallbackQuery
import dev.inmo.tgbotapi.types.CallbackQueryIdentifier import dev.inmo.tgbotapi.types.CallbackQueryIdentifier
import dev.inmo.tgbotapi.types.User import dev.inmo.tgbotapi.types.User
import dev.inmo.tgbotapi.types.message.abstracts.Message import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
data class MessageDataCallbackQuery( data class MessageDataCallbackQuery(
override val id: CallbackQueryIdentifier, override val id: CallbackQueryIdentifier,
override val from: User, override val from: User,
override val chatInstance: String, override val chatInstance: String,
override val message: Message, override val message: ContentMessage<MessageContent>,
override val data: String override val data: String
) : DataCallbackQuery, MessageCallbackQuery ) : DataCallbackQuery, MessageCallbackQuery

View File

@@ -2,12 +2,13 @@ package dev.inmo.tgbotapi.types.CallbackQuery
import dev.inmo.tgbotapi.types.CallbackQueryIdentifier import dev.inmo.tgbotapi.types.CallbackQueryIdentifier
import dev.inmo.tgbotapi.types.User import dev.inmo.tgbotapi.types.User
import dev.inmo.tgbotapi.types.message.abstracts.Message import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
data class MessageGameShortNameCallbackQuery( data class MessageGameShortNameCallbackQuery(
override val id: CallbackQueryIdentifier, override val id: CallbackQueryIdentifier,
override val from: User, override val from: User,
override val chatInstance: String, override val chatInstance: String,
override val message: Message, override val message: ContentMessage<MessageContent>,
override val gameShortName: String override val gameShortName: String
) : GameShortNameCallbackQuery, MessageCallbackQuery ) : GameShortNameCallbackQuery, MessageCallbackQuery

View File

@@ -1,8 +1,9 @@
package dev.inmo.tgbotapi.types.CallbackQuery package dev.inmo.tgbotapi.types.CallbackQuery
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.message.abstracts.Message import dev.inmo.tgbotapi.types.message.abstracts.*
import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializeOnlySerializer import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializeOnlySerializer
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
import kotlinx.serialization.SerialName import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
@@ -13,7 +14,7 @@ internal data class RawCallbackQuery(
@SerialName(fromField) @SerialName(fromField)
val from: User, val from: User,
@Serializable(TelegramBotAPIMessageDeserializeOnlySerializer::class) @Serializable(TelegramBotAPIMessageDeserializeOnlySerializer::class)
val message: Message? = null, val message: ContentMessage<MessageContent>? = null,
@SerialName(inlineMessageIdField) @SerialName(inlineMessageIdField)
val inlineMessageId: InlineMessageIdentifier? = null, val inlineMessageId: InlineMessageIdentifier? = null,
@SerialName("chat_instance") @SerialName("chat_instance")

View File

@@ -46,6 +46,9 @@ fun Byte.toChatId(): ChatId = toLong().toChatId()
data class Username( data class Username(
val username: String val username: String
) : ChatIdentifier() { ) : ChatIdentifier() {
val usernameWithoutAt
get() = username.dropWhile { it == '@' }
init { init {
if (!username.startsWith("@")) { if (!username.startsWith("@")) {
throw IllegalArgumentException("Username must starts with `@`") throw IllegalArgumentException("Username must starts with `@`")

View File

@@ -1,5 +1,6 @@
package dev.inmo.tgbotapi.types package dev.inmo.tgbotapi.types
import com.soywiz.klock.DateTime
import dev.inmo.tgbotapi.CommonAbstracts.FromUser import dev.inmo.tgbotapi.CommonAbstracts.FromUser
import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat
import kotlinx.serialization.SerialName import kotlinx.serialization.SerialName
@@ -20,4 +21,7 @@ data class ChatJoinRequest(
val inviteLink: ChatInviteLink, val inviteLink: ChatInviteLink,
@SerialName(bioField) @SerialName(bioField)
val bio: String? = null val bio: String? = null
) : FromUser ) : FromUser {
val dateTime: DateTime
get() = date.asDate
}

View File

@@ -168,6 +168,7 @@ const val botUsernameField = "bot_username"
const val switchInlineQueryCurrentChatField = "switch_inline_query_current_chat" const val switchInlineQueryCurrentChatField = "switch_inline_query_current_chat"
const val switchInlineQueryField = "switch_inline_query" const val switchInlineQueryField = "switch_inline_query"
const val isAnimatedField = "is_animated" const val isAnimatedField = "is_animated"
const val isVideoField = "is_video"
const val inviteLinkField = "invite_link" const val inviteLinkField = "invite_link"
const val pinnedMessageField = "pinned_message" const val pinnedMessageField = "pinned_message"
const val customTitleField = "custom_title" const val customTitleField = "custom_title"
@@ -265,6 +266,7 @@ const val canManageVoiceChatsField = "can_manage_voice_chats"
const val canManageChatField = "can_manage_chat" 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 webmStickerField = "webm_sticker"
const val oldChatMemberField = "old_chat_member" const val oldChatMemberField = "old_chat_member"
const val newChatMemberField = "new_chat_member" const val newChatMemberField = "new_chat_member"

View File

@@ -20,11 +20,11 @@ internal data class RawMessageEntity(
internal fun RawMessageEntity.asTextSource( internal fun RawMessageEntity.asTextSource(
source: String, source: String,
subParts: TextSourcesList subParts: List<Pair<Int, TextSource>>
): TextSource { ): TextSource {
val sourceSubstring: String = source.substring(range) val sourceSubstring: String = source.substring(range)
val subPartsWithRegulars by lazy { val subPartsWithRegulars by lazy {
subParts.fillWithRegulars(sourceSubstring) subParts.map { (it.first - offset) to it.second }.fillWithRegulars(sourceSubstring)
} }
return when (type) { return when (type) {
"mention" -> MentionTextSource(sourceSubstring, subPartsWithRegulars) "mention" -> MentionTextSource(sourceSubstring, subPartsWithRegulars)
@@ -58,16 +58,14 @@ private inline operator fun <T : Comparable<T>> ClosedRange<T>.contains(other: C
return start <= other.start && endInclusive >= other.endInclusive return start <= other.start && endInclusive >= other.endInclusive
} }
internal fun TextSourcesList.fillWithRegulars(source: String): TextSourcesList { internal fun List<Pair<Int, TextSource>>.fillWithRegulars(source: String): TextSourcesList {
var index = 0 var index = 0
val result = mutableListOf<TextSource>() val result = mutableListOf<TextSource>()
for (i in 0 until size) { for (i in indices) {
val textSource = get(i) val (offset, textSource) = get(i)
val thisSourceInStart = source.startsWith(textSource.source, index) if (offset - index > 0) {
if (!thisSourceInStart) { result.add(regular(source.substring(index, offset)))
val regularEndIndex = source.indexOf(textSource.source, index) index = offset
result.add(regular(source.substring(index, regularEndIndex)))
index = regularEndIndex
} }
result.add(textSource) result.add(textSource)
index += textSource.source.length index += textSource.source.length
@@ -83,9 +81,9 @@ internal fun TextSourcesList.fillWithRegulars(source: String): TextSourcesList {
private fun createTextSources( private fun createTextSources(
originalFullString: String, originalFullString: String,
entities: RawMessageEntities entities: RawMessageEntities
): TextSourcesList { ): List<Pair<Int, TextSource>> {
val mutableEntities = entities.toMutableList().apply { sortBy { it.offset } } val mutableEntities = entities.toMutableList().apply { sortBy { it.offset } }
val resultList = mutableListOf<TextSource>() val resultList = mutableListOf<Pair<Int, TextSource>>()
while (mutableEntities.isNotEmpty()) { while (mutableEntities.isNotEmpty()) {
var parent = mutableEntities.removeFirst() var parent = mutableEntities.removeFirst()
@@ -129,7 +127,7 @@ private fun createTextSources(
emptyList() emptyList()
} }
resultList.add( resultList.add(
parent.asTextSource( parent.offset to parent.asTextSource(
originalFullString, originalFullString,
subtextSources subtextSources
) )

View File

@@ -1,5 +1,6 @@
package dev.inmo.tgbotapi.types.MessageEntity.textsources package dev.inmo.tgbotapi.types.MessageEntity.textsources
import dev.inmo.tgbotapi.types.Username
import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.extensions.makeString import dev.inmo.tgbotapi.utils.extensions.makeString
import dev.inmo.tgbotapi.utils.internal.* import dev.inmo.tgbotapi.utils.internal.*
@@ -23,6 +24,7 @@ data class MentionTextSource @RiskFeature(DirectInvocationOfTextSourceConstructo
override val markdown: String by lazy { source.mentionMarkdown() } override val markdown: String by lazy { source.mentionMarkdown() }
override val markdownV2: String by lazy { mentionMarkdownV2() } override val markdownV2: String by lazy { mentionMarkdownV2() }
override val html: String by lazy { mentionHTML() } override val html: String by lazy { mentionHTML() }
val username: Username = Username(source)
init { init {
if (!source.startsWith("@")) { if (!source.startsWith("@")) {
@@ -42,3 +44,6 @@ inline fun mention(vararg parts: TextSource) = mention(parts.toList())
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
inline fun mention(whoToMention: String) = mention(regular(whoToMention)) inline fun mention(whoToMention: String) = mention(regular(whoToMention))
@Suppress("NOTHING_TO_INLINE")
inline fun mention(whoToMention: Username) = mention(whoToMention.username.dropWhile { it == '@' })

View File

@@ -1,32 +1,6 @@
package dev.inmo.tgbotapi.types.files package dev.inmo.tgbotapi.types.files
import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.types.files.sticker.Sticker
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.files.abstracts.*
import dev.inmo.tgbotapi.types.stickers.MaskPosition
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable @Deprecated("Replaced", ReplaceWith("Sticker", "dev.inmo.tgbotapi.types.files.sticker.Sticker"))
data class Sticker( typealias Sticker = Sticker
@SerialName(fileIdField)
override val fileId: FileId,
@SerialName(fileUniqueIdField)
override val fileUniqueId: FileUniqueId,
@SerialName(widthField)
override val width: Int,
@SerialName(heightField)
override val height: Int,
@SerialName(thumbField)
override val thumb: PhotoSize? = null,
@SerialName(emojiField)
val emoji: String? = null,
@SerialName(stickerSetNameField)
val stickerSetName: StickerSetName? = null,
@SerialName(isAnimatedField)
val isAnimated: Boolean = false,
@SerialName(maskPositionField)
val maskPosition: MaskPosition? = null,
@SerialName(fileSizeField)
override val fileSize: Long? = null
) : TelegramMediaFile, SizedMediaFile, ThumbedMediaFile

View File

@@ -0,0 +1,158 @@
package dev.inmo.tgbotapi.types.files.sticker
import dev.inmo.tgbotapi.requests.abstracts.FileId
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.files.PhotoSize
import dev.inmo.tgbotapi.types.files.abstracts.*
import dev.inmo.tgbotapi.types.stickers.MaskPosition
import dev.inmo.tgbotapi.utils.RiskFeature
import kotlinx.serialization.*
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
@Serializable
@RiskFeature("This class is used for serialization/deserialization of Sticker interface")
data class StickerSurrogate(
val file_id: FileId,
val file_unique_id: FileUniqueId,
val width: Int,
val height: Int,
val is_animated: Boolean? = null,
val is_video: Boolean? = null,
val thumb: PhotoSize? = null,
val emoji: String? = null,
val set_name: StickerSetName? = null,
val mask_position: MaskPosition? = null,
val file_size: Long? = null
)
// TODO:: Serializer
@Serializable(StickerSerializer::class)
sealed interface Sticker : TelegramMediaFile, SizedMediaFile, ThumbedMediaFile {
val emoji: String?
val maskPosition: MaskPosition?
val stickerSetName: StickerSetName?
val isAnimated
get() = this is AnimatedSticker
val isVideo
get() = this is VideoSticker
companion object {
fun serializer(): KSerializer<Sticker> = StickerSerializer
}
}
object StickerSerializer : KSerializer<Sticker> {
override val descriptor: SerialDescriptor = StickerSurrogate.serializer().descriptor
override fun deserialize(decoder: Decoder): Sticker {
val surrogate = StickerSurrogate.serializer().deserialize(decoder)
return when {
surrogate.is_animated == true -> AnimatedSticker(
surrogate.file_id,
surrogate.file_unique_id,
surrogate.width,
surrogate.height,
surrogate.thumb,
surrogate.emoji,
surrogate.set_name,
surrogate.mask_position,
surrogate.file_size
)
surrogate.is_video == true -> VideoSticker(
surrogate.file_id,
surrogate.file_unique_id,
surrogate.width,
surrogate.height,
surrogate.thumb,
surrogate.emoji,
surrogate.set_name,
surrogate.mask_position,
surrogate.file_size
)
else -> SimpleSticker(
surrogate.file_id,
surrogate.file_unique_id,
surrogate.width,
surrogate.height,
surrogate.thumb,
surrogate.emoji,
surrogate.set_name,
surrogate.mask_position,
surrogate.file_size
)
}
}
override fun serialize(encoder: Encoder, value: Sticker) {
TODO("Not yet implemented")
}
}
@Serializable
data class SimpleSticker(
@SerialName(fileIdField)
override val fileId: FileId,
@SerialName(fileUniqueIdField)
override val fileUniqueId: FileUniqueId,
@SerialName(widthField)
override val width: Int,
@SerialName(heightField)
override val height: Int,
@SerialName(thumbField)
override val thumb: PhotoSize? = null,
@SerialName(emojiField)
override val emoji: String? = null,
@SerialName(stickerSetNameField)
override val stickerSetName: StickerSetName? = null,
@SerialName(maskPositionField)
override val maskPosition: MaskPosition? = null,
@SerialName(fileSizeField)
override val fileSize: Long? = null,
) : Sticker
@Serializable
data class AnimatedSticker(
@SerialName(fileIdField)
override val fileId: FileId,
@SerialName(fileUniqueIdField)
override val fileUniqueId: FileUniqueId,
@SerialName(widthField)
override val width: Int,
@SerialName(heightField)
override val height: Int,
@SerialName(thumbField)
override val thumb: PhotoSize? = null,
@SerialName(emojiField)
override val emoji: String? = null,
@SerialName(stickerSetNameField)
override val stickerSetName: StickerSetName? = null,
@SerialName(maskPositionField)
override val maskPosition: MaskPosition? = null,
@SerialName(fileSizeField)
override val fileSize: Long? = null,
) : Sticker
@Serializable
data class VideoSticker(
@SerialName(fileIdField)
override val fileId: FileId,
@SerialName(fileUniqueIdField)
override val fileUniqueId: FileUniqueId,
@SerialName(widthField)
override val width: Int,
@SerialName(heightField)
override val height: Int,
@SerialName(thumbField)
override val thumb: PhotoSize? = null,
@SerialName(emojiField)
override val emoji: String? = null,
@SerialName(stickerSetNameField)
override val stickerSetName: StickerSetName? = null,
@SerialName(maskPositionField)
override val maskPosition: MaskPosition? = null,
@SerialName(fileSizeField)
override val fileSize: Long? = null,
) : Sticker

View File

@@ -0,0 +1,7 @@
package dev.inmo.tgbotapi.types.message.ChatEvents
import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.PrivateEvent
data class UserLoggedIn(
val domain: String
) : PrivateEvent

View File

@@ -2,8 +2,7 @@ package dev.inmo.tgbotapi.types.message
import dev.inmo.tgbotapi.CommonAbstracts.FromUser import dev.inmo.tgbotapi.CommonAbstracts.FromUser
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.chat.abstracts.ChannelChat import dev.inmo.tgbotapi.types.chat.abstracts.*
import dev.inmo.tgbotapi.types.chat.abstracts.SupergroupChat
sealed class ForwardInfo { sealed class ForwardInfo {
abstract val dateOfOriginal: TelegramDate abstract val dateOfOriginal: TelegramDate
@@ -19,14 +18,24 @@ data class UserForwardInfo(
override val from: User override val from: User
) : ForwardInfo(), FromUser ) : ForwardInfo(), FromUser
sealed class ForwardFromPublicChatInfo : ForwardInfo() {
abstract val chat: PublicChat
}
data class ForwardFromChannelInfo( data class ForwardFromChannelInfo(
override val dateOfOriginal: TelegramDate, override val dateOfOriginal: TelegramDate,
val messageId: MessageIdentifier, val messageId: MessageIdentifier,
val channelChat: ChannelChat, val channelChat: ChannelChat,
val signature: String? = null val signature: String? = null
) : ForwardInfo() ) : ForwardFromPublicChatInfo() {
override val chat: PublicChat
get() = channelChat
}
data class ForwardFromSupergroupInfo( data class ForwardFromSupergroupInfo(
override val dateOfOriginal: TelegramDate, override val dateOfOriginal: TelegramDate,
val group: SupergroupChat val group: SupergroupChat
) : ForwardInfo() ) : ForwardFromPublicChatInfo() {
override val chat: PublicChat
get() = group
}

View File

@@ -7,6 +7,7 @@ import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
import dev.inmo.tgbotapi.types.chat.abstracts.* import dev.inmo.tgbotapi.types.chat.abstracts.*
import dev.inmo.tgbotapi.types.dice.Dice import dev.inmo.tgbotapi.types.dice.Dice
import dev.inmo.tgbotapi.types.files.* import dev.inmo.tgbotapi.types.files.*
import dev.inmo.tgbotapi.types.files.sticker.Sticker
import dev.inmo.tgbotapi.types.games.RawGame 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.*
@@ -201,6 +202,7 @@ internal data class RawMessage(
pinned_message != null -> PinnedMessage(pinned_message.asMessage) pinned_message != null -> PinnedMessage(pinned_message.asMessage)
proximity_alert_triggered != null -> proximity_alert_triggered proximity_alert_triggered != null -> proximity_alert_triggered
successful_payment != null -> SuccessfulPaymentEvent(successful_payment) successful_payment != null -> SuccessfulPaymentEvent(successful_payment)
connected_website != null -> UserLoggedIn(connected_website)
else -> null else -> null
} }
} }

View File

@@ -1,3 +1,41 @@
package dev.inmo.tgbotapi.types.message.content.abstracts package dev.inmo.tgbotapi.types.message.content.abstracts
interface MessageContent: ResendableContent import dev.inmo.tgbotapi.types.message.content.*
import dev.inmo.tgbotapi.types.message.content.media.*
import dev.inmo.tgbotapi.types.message.payments.InvoiceContent
import dev.inmo.tgbotapi.utils.RiskFeature
import kotlinx.serialization.modules.*
interface MessageContent: ResendableContent {
companion object {
@RiskFeature("This serialization module can be changed in near releases")
fun serializationModule(
additionalBuilder: PolymorphicModuleBuilder<MessageContent>.() -> Unit = {}
) = SerializersModule {
polymorphic(MessageContent::class) {
subclass(ContactContent::class)
subclass(VenueContent::class)
subclass(PollContent::class)
subclass(DiceContent::class)
subclass(TextContent::class)
subclass(LiveLocationContent::class)
subclass(StaticLocationContent::class)
subclass(PhotoContent::class)
subclass(VideoContent::class)
subclass(AudioContent::class)
subclass(DocumentContent::class)
subclass(VoiceContent::class)
subclass(VideoNoteContent::class)
subclass(AnimationContent::class)
subclass(StickerContent::class)
subclass(InvoiceContent::class)
additionalBuilder()
}
}
}
}

View File

@@ -6,7 +6,7 @@ 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.MessageIdentifier import dev.inmo.tgbotapi.types.MessageIdentifier
import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup import dev.inmo.tgbotapi.types.buttons.KeyboardMarkup
import dev.inmo.tgbotapi.types.files.Sticker import dev.inmo.tgbotapi.types.files.sticker.Sticker
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 kotlinx.serialization.Serializable import kotlinx.serialization.Serializable

View File

@@ -54,7 +54,9 @@ sealed interface Poll {
} }
@Serializable(PollSerializer::class) @Serializable(PollSerializer::class)
sealed interface MultipleAnswersPoll : Poll sealed interface MultipleAnswersPoll : Poll {
val allowMultipleAnswers: Boolean
}
@Serializable @Serializable
private class RawPoll( private class RawPoll(
@@ -122,7 +124,7 @@ data class RegularPoll(
override val votesCount: Int, override val votesCount: Int,
override val isClosed: Boolean = false, override val isClosed: Boolean = false,
override val isAnonymous: Boolean = false, override val isAnonymous: Boolean = false,
val allowMultipleAnswers: Boolean = false, override val allowMultipleAnswers: Boolean = false,
override val scheduledCloseInfo: ScheduledCloseInfo? = null override val scheduledCloseInfo: ScheduledCloseInfo? = null
) : MultipleAnswersPoll ) : MultipleAnswersPoll

View File

@@ -12,6 +12,13 @@ import kotlinx.serialization.encoding.Encoder
sealed class PollOption { sealed class PollOption {
abstract val text: String abstract val text: String
abstract val votes: Int abstract val votes: Int
companion object {
fun simple(
text: String,
votes: Int = 0
) = SimplePollOption(text, votes)
}
} }
@Serializable @Serializable
@@ -19,7 +26,7 @@ data class SimplePollOption (
@SerialName(textField) @SerialName(textField)
override val text: String, override val text: String,
@SerialName(votesCountField) @SerialName(votesCountField)
override val votes: Int override val votes: Int = 0
) : PollOption() ) : PollOption()
@RiskFeature @RiskFeature

View File

@@ -2,7 +2,7 @@ package dev.inmo.tgbotapi.types.stickers
import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.files.PhotoSize import dev.inmo.tgbotapi.types.files.PhotoSize
import dev.inmo.tgbotapi.types.files.Sticker import dev.inmo.tgbotapi.types.files.sticker.Sticker
import kotlinx.serialization.SerialName import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
@@ -16,6 +16,8 @@ data class StickerSet(
val stickers: List<Sticker>, val stickers: List<Sticker>,
@SerialName(isAnimatedField) @SerialName(isAnimatedField)
val isAnimated: Boolean = false, val isAnimated: Boolean = false,
@SerialName(isVideoField)
val isVideo: Boolean = false,
@SerialName(containsMasksField) @SerialName(containsMasksField)
val containsMasks: Boolean = false, val containsMasks: Boolean = false,
@SerialName(thumbField) @SerialName(thumbField)

View File

@@ -2,34 +2,69 @@ package dev.inmo.tgbotapi.utils
import dev.inmo.tgbotapi.types.buttons.Matrix import dev.inmo.tgbotapi.types.buttons.Matrix
/**
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.InlineKeyboardRowBuilder
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.ReplyKeyboardRowBuilder
*/
@Deprecated("This functionality will be removed soon")
fun <T> row(block: RowBuilder<T>.() -> Unit): List<T> { fun <T> row(block: RowBuilder<T>.() -> Unit): List<T> {
return RowBuilder<T>().also(block).row return RowBuilder<T>().also(block).row
} }
/**
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.InlineKeyboardRowBuilder
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.ReplyKeyboardRowBuilder
*/
@Deprecated("This functionality will be removed soon")
fun <T> MatrixBuilder<T>.row(block: RowBuilder<T>.() -> Unit) { fun <T> MatrixBuilder<T>.row(block: RowBuilder<T>.() -> Unit) {
add(RowBuilder<T>().also(block).row) add(RowBuilder<T>().also(block).row)
} }
/**
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.InlineKeyboardRowBuilder
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.ReplyKeyboardRowBuilder
*/
@Deprecated("This functionality will be removed soon")
fun <T> MatrixBuilder<T>.row(vararg elements: T) { fun <T> MatrixBuilder<T>.row(vararg elements: T) {
add(elements.toList()) add(elements.toList())
} }
/**
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.InlineKeyboardBuilder
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.ReplyKeyboardBuilder
*/
@Deprecated("This functionality will be removed soon")
fun <T> matrix(block: MatrixBuilder<T>.() -> Unit): Matrix<T> { fun <T> matrix(block: MatrixBuilder<T>.() -> Unit): Matrix<T> {
return MatrixBuilder<T>().also(block).matrix return MatrixBuilder<T>().also(block).matrix
} }
/**
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.InlineKeyboardBuilder
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.ReplyKeyboardBuilder
*/
@Deprecated("This functionality will be removed soon")
fun <T> flatMatrix(block: RowBuilder<T>.() -> Unit): Matrix<T> { fun <T> flatMatrix(block: RowBuilder<T>.() -> Unit): Matrix<T> {
return MatrixBuilder<T>().apply { return MatrixBuilder<T>().apply {
row(block) row(block)
}.matrix }.matrix
} }
/**
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.InlineKeyboardBuilder
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.ReplyKeyboardBuilder
*/
@Deprecated("This functionality will be removed soon")
fun <T> flatMatrix(vararg elements: T): Matrix<T> { fun <T> flatMatrix(vararg elements: T): Matrix<T> {
return MatrixBuilder<T>().apply { return MatrixBuilder<T>().apply {
row { elements.forEach { +it } } row { elements.forEach { +it } }
}.matrix }.matrix
} }
/**
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.InlineKeyboardRowBuilder
* @see dev.inmo.tgbotapi.extensions.utils.types.buttons.ReplyKeyboardRowBuilder
*/
@Deprecated("This functionality will be removed soon")
operator fun <T> RowBuilder<T>.plus(t: T) = add(t) operator fun <T> RowBuilder<T>.plus(t: T) = add(t)
open class RowBuilder<T> { open class RowBuilder<T> {

View File

@@ -3,43 +3,43 @@ package dev.inmo.tgbotapi.types.MessageEntity
import dev.inmo.tgbotapi.types.MessageEntity.textsources.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.*
import kotlin.test.assertTrue import kotlin.test.assertTrue
const val testText = "It is simple hello world with #tag and @mention" const val testText = "It (is?) is simple hello world with #tag and @mention"
const val formattedV2Text = "It *_is_ ~__simple__~* ||hello world|| with \\#tag and @mention" const val formattedV2Text = "It \\(is?\\) *_is_ ~__simple__~* ||hello world|| with \\#tag and @mention"
const val formattedHtmlText = "It <b><i>is</i> <s><u>simple</u></s></b> <span class=\"tg-spoiler\">hello world</span> with #tag and @mention" const val formattedHtmlText = "It (is?) <b><i>is</i> <s><u>simple</u></s></b> <span class=\"tg-spoiler\">hello world</span> with #tag and @mention"
internal val testTextEntities = listOf( internal val testTextEntities = listOf(
RawMessageEntity( RawMessageEntity(
"bold", "bold",
3, 9,
9 9
), ),
RawMessageEntity( RawMessageEntity(
"italic", "italic",
3, 9,
2 2
), ),
RawMessageEntity( RawMessageEntity(
"strikethrough", "strikethrough",
6, 12,
6 6
), ),
RawMessageEntity( RawMessageEntity(
"underline", "underline",
6, 12,
6 6
), ),
RawMessageEntity( RawMessageEntity(
"spoiler", "spoiler",
13, 19,
11 11
), ),
RawMessageEntity( RawMessageEntity(
"hashtag", "hashtag",
30, 36,
4 4
), ),
RawMessageEntity( RawMessageEntity(
"mention", "mention",
39, 45,
8 8
) )
) )

View File

@@ -2,8 +2,7 @@ package dev.inmo.tgbotapi.types.MessageEntity
import dev.inmo.tgbotapi.extensions.utils.formatting.* import dev.inmo.tgbotapi.extensions.utils.formatting.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.* import dev.inmo.tgbotapi.types.MessageEntity.textsources.*
import kotlin.test.Test import kotlin.test.*
import kotlin.test.assertEquals
class StringFormattingTests { class StringFormattingTests {
@Test @Test
@@ -38,7 +37,7 @@ class StringFormattingTests {
@Test @Test
fun testThatCreatingOfStringWithSimpleDSLWorksCorrectly() { fun testThatCreatingOfStringWithSimpleDSLWorksCorrectly() {
val sources: TextSourcesList = regular("It ") + val sources: TextSourcesList = regular("It (is?) ") +
bold(italic("is") + bold(italic("is") +
" " + " " +
strikethrough(underline("simple"))) + strikethrough(underline("simple"))) +
@@ -53,4 +52,43 @@ class StringFormattingTests {
assertEquals(formattedV2Text, sources.toMarkdownV2Texts().first()) assertEquals(formattedV2Text, sources.toMarkdownV2Texts().first())
assertEquals(formattedHtmlText, sources.toHtmlTexts().first()) assertEquals(formattedHtmlText, sources.toHtmlTexts().first())
} }
@Test
fun testForRepeatingWordsInOneSentenceWithTheSecondOneFormatted() {
val sourceText = "link link"
val messageEntities = listOf(
RawMessageEntity("bold", 5, 4),
RawMessageEntity("text_link", 6, 2, "google.com")
)
val textSources = messageEntities.asTextSources(sourceText)
val (regular, bold) = textSources
assertTrue(regular is RegularTextSource)
assertTrue(bold is BoldTextSource)
assertTrue(regular.source == "link ")
assertTrue(bold.source == "link")
assertTrue((bold.subsources[0] as? RegularTextSource) ?.source == "l")
assertTrue((bold.subsources[1] as? TextLinkTextSource) ?.source == "in")
assertTrue((bold.subsources[1] as? TextLinkTextSource) ?.url == "google.com")
assertTrue((bold.subsources[2] as? RegularTextSource) ?.source == "k")
assertTrue(bold.subsources.size == 3)
assertTrue(textSources.size == 2)
}
@Test
fun testForRepeatingWordsInOneSentenceWithTheSecondOneFormattedInsideOfFormatting() {
val sourceText = "text"
val messageEntities = listOf(
RawMessageEntity("bold", 0, 4),
RawMessageEntity("text_link", 3, 1, "google.com")
)
val textSources = messageEntities.asTextSources(sourceText)
val (bold) = textSources
assertTrue(bold is BoldTextSource)
assertTrue(bold.source == "text")
assertTrue((bold.subsources[0] as? RegularTextSource) ?.source == "tex")
assertTrue((bold.subsources[1] as? TextLinkTextSource) ?.source == "t")
assertTrue((bold.subsources[1] as? TextLinkTextSource) ?.url == "google.com")
assertTrue(bold.subsources.size == 2)
assertTrue(textSources.size == 1)
}
} }

View File

@@ -17,8 +17,9 @@ plugins {
project.version = "$library_version" project.version = "$library_version"
project.group = "$library_group" project.group = "$library_group"
project.description = "DEPRECATED, use tgbotapi.api"
apply from: "publish.gradle" apply from: "../publish.gradle"
repositories { repositories {
mavenLocal() mavenLocal()

View File

@@ -1 +0,0 @@
{"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 API Extensions for tgbotapi.api","description":"","url":"https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI-behaviour_builder-fsm","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/"}]}}

View File

@@ -1,69 +0,0 @@
apply plugin: 'maven-publish'
apply plugin: 'signing'
task javadocsJar(type: Jar) {
classifier = 'javadoc'
}
publishing {
publications.all {
artifact javadocsJar
pom {
description = "${project.name}"
name = "Telegram Bot API API Extensions for tgbotapi.api"
url = "https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI-behaviour_builder-fsm"
scm {
developerConnection = "scm:git:[fetch=]https://github.com/insanusmokrassar/TelegramBotAPI.git[push=]https://github.com/insanusmokrassar/TelegramBotAPI.git"
url = "https://github.com/insanusmokrassar/TelegramBotAPI.git"
}
developers {
developer {
id = "InsanusMokrassar"
name = "Ovsiannikov Aleksei"
email = "ovsyannikov.alexey95@gmail.com"
}
}
licenses {
license {
name = "Apache Software License 2.0"
url = "https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"
}
}
}
repositories {
if ((project.hasProperty('GITHUBPACKAGES_USER') || System.getenv('GITHUBPACKAGES_USER') != null) && (project.hasProperty('GITHUBPACKAGES_PASSWORD') || System.getenv('GITHUBPACKAGES_PASSWORD') != null)) {
maven {
name = "GithubPackages"
url = uri("https://maven.pkg.github.com/InsanusMokrassar/TelegramBotAPI")
credentials {
username = project.hasProperty('GITHUBPACKAGES_USER') ? project.property('GITHUBPACKAGES_USER') : System.getenv('GITHUBPACKAGES_USER')
password = project.hasProperty('GITHUBPACKAGES_PASSWORD') ? project.property('GITHUBPACKAGES_PASSWORD') : System.getenv('GITHUBPACKAGES_PASSWORD')
}
}
}
if ((project.hasProperty('SONATYPE_USER') || System.getenv('SONATYPE_USER') != null) && (project.hasProperty('SONATYPE_PASSWORD') || System.getenv('SONATYPE_PASSWORD') != null)) {
maven {
name = "sonatype"
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials {
username = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : System.getenv('SONATYPE_USER')
password = project.hasProperty('SONATYPE_PASSWORD') ? project.property('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD')
}
}
}
}
}
}
signing {
useGpgCmd()
sign publishing.publications
}

View File

@@ -17,8 +17,9 @@ plugins {
project.version = "$library_version" project.version = "$library_version"
project.group = "$library_group" project.group = "$library_group"
project.description = "DEPRECATED, use tgbotapi.behaviour_builder.fsm"
apply from: "publish.gradle" apply from: "../publish.gradle"
repositories { repositories {
mavenLocal() mavenLocal()

View File

@@ -1 +0,0 @@
{"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 BehaviourBuilder FSM Extensions for tgbotapi.behaviour_builder.fsm","description":"","url":"https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI-behaviour_builder-fsm","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/"}]}}

View File

@@ -1,69 +0,0 @@
apply plugin: 'maven-publish'
apply plugin: 'signing'
task javadocsJar(type: Jar) {
classifier = 'javadoc'
}
publishing {
publications.all {
artifact javadocsJar
pom {
description = "${project.name}"
name = "Telegram Bot API BehaviourBuilder FSM Extensions for tgbotapi.behaviour_builder.fsm"
url = "https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI-behaviour_builder-fsm"
scm {
developerConnection = "scm:git:[fetch=]https://github.com/insanusmokrassar/TelegramBotAPI.git[push=]https://github.com/insanusmokrassar/TelegramBotAPI.git"
url = "https://github.com/insanusmokrassar/TelegramBotAPI.git"
}
developers {
developer {
id = "InsanusMokrassar"
name = "Ovsiannikov Aleksei"
email = "ovsyannikov.alexey95@gmail.com"
}
}
licenses {
license {
name = "Apache Software License 2.0"
url = "https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"
}
}
}
repositories {
if ((project.hasProperty('GITHUBPACKAGES_USER') || System.getenv('GITHUBPACKAGES_USER') != null) && (project.hasProperty('GITHUBPACKAGES_PASSWORD') || System.getenv('GITHUBPACKAGES_PASSWORD') != null)) {
maven {
name = "GithubPackages"
url = uri("https://maven.pkg.github.com/InsanusMokrassar/TelegramBotAPI")
credentials {
username = project.hasProperty('GITHUBPACKAGES_USER') ? project.property('GITHUBPACKAGES_USER') : System.getenv('GITHUBPACKAGES_USER')
password = project.hasProperty('GITHUBPACKAGES_PASSWORD') ? project.property('GITHUBPACKAGES_PASSWORD') : System.getenv('GITHUBPACKAGES_PASSWORD')
}
}
}
if ((project.hasProperty('SONATYPE_USER') || System.getenv('SONATYPE_USER') != null) && (project.hasProperty('SONATYPE_PASSWORD') || System.getenv('SONATYPE_PASSWORD') != null)) {
maven {
name = "sonatype"
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials {
username = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : System.getenv('SONATYPE_USER')
password = project.hasProperty('SONATYPE_PASSWORD') ? project.property('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD')
}
}
}
}
}
}
signing {
useGpgCmd()
sign publishing.publications
}

View File

@@ -17,8 +17,9 @@ plugins {
project.version = "$library_version" project.version = "$library_version"
project.group = "$library_group" project.group = "$library_group"
project.description = "DEPRECATED, use tgbotapi.behaviour_builder"
apply from: "publish.gradle" apply from: "../publish.gradle"
repositories { repositories {
mavenLocal() mavenLocal()

View File

@@ -1 +0,0 @@
{"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 BehaviourBuilder Extensions for tgbotapi.behaviour_builder","description":"","url":"https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI-behaviour_builder-fsm","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/"}]}}

View File

@@ -1,69 +0,0 @@
apply plugin: 'maven-publish'
apply plugin: 'signing'
task javadocsJar(type: Jar) {
classifier = 'javadoc'
}
publishing {
publications.all {
artifact javadocsJar
pom {
description = "${project.name}"
name = "Telegram Bot API BehaviourBuilder Extensions for tgbotapi.behaviour_builder"
url = "https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI-behaviour_builder-fsm"
scm {
developerConnection = "scm:git:[fetch=]https://github.com/insanusmokrassar/TelegramBotAPI.git[push=]https://github.com/insanusmokrassar/TelegramBotAPI.git"
url = "https://github.com/insanusmokrassar/TelegramBotAPI.git"
}
developers {
developer {
id = "InsanusMokrassar"
name = "Ovsiannikov Aleksei"
email = "ovsyannikov.alexey95@gmail.com"
}
}
licenses {
license {
name = "Apache Software License 2.0"
url = "https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"
}
}
}
repositories {
if ((project.hasProperty('GITHUBPACKAGES_USER') || System.getenv('GITHUBPACKAGES_USER') != null) && (project.hasProperty('GITHUBPACKAGES_PASSWORD') || System.getenv('GITHUBPACKAGES_PASSWORD') != null)) {
maven {
name = "GithubPackages"
url = uri("https://maven.pkg.github.com/InsanusMokrassar/TelegramBotAPI")
credentials {
username = project.hasProperty('GITHUBPACKAGES_USER') ? project.property('GITHUBPACKAGES_USER') : System.getenv('GITHUBPACKAGES_USER')
password = project.hasProperty('GITHUBPACKAGES_PASSWORD') ? project.property('GITHUBPACKAGES_PASSWORD') : System.getenv('GITHUBPACKAGES_PASSWORD')
}
}
}
if ((project.hasProperty('SONATYPE_USER') || System.getenv('SONATYPE_USER') != null) && (project.hasProperty('SONATYPE_PASSWORD') || System.getenv('SONATYPE_PASSWORD') != null)) {
maven {
name = "sonatype"
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials {
username = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : System.getenv('SONATYPE_USER')
password = project.hasProperty('SONATYPE_PASSWORD') ? project.property('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD')
}
}
}
}
}
}
signing {
useGpgCmd()
sign publishing.publications
}

View File

@@ -17,8 +17,9 @@ plugins {
project.version = "$library_version" project.version = "$library_version"
project.group = "$library_group" project.group = "$library_group"
project.description = "DEPRECATED, use tgbotapi.utils"
apply from: "publish.gradle" apply from: "../publish.gradle"
repositories { repositories {
mavenLocal() mavenLocal()

View File

@@ -1 +0,0 @@
{"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 Utils Extensions for tgbotapi.utils","description":"","url":"https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI-behaviour_builder-fsm","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/"}]}}

View File

@@ -1,69 +0,0 @@
apply plugin: 'maven-publish'
apply plugin: 'signing'
task javadocsJar(type: Jar) {
classifier = 'javadoc'
}
publishing {
publications.all {
artifact javadocsJar
pom {
description = "${project.name}"
name = "Telegram Bot API Utils Extensions for tgbotapi.utils"
url = "https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI-behaviour_builder-fsm"
scm {
developerConnection = "scm:git:[fetch=]https://github.com/insanusmokrassar/TelegramBotAPI.git[push=]https://github.com/insanusmokrassar/TelegramBotAPI.git"
url = "https://github.com/insanusmokrassar/TelegramBotAPI.git"
}
developers {
developer {
id = "InsanusMokrassar"
name = "Ovsiannikov Aleksei"
email = "ovsyannikov.alexey95@gmail.com"
}
}
licenses {
license {
name = "Apache Software License 2.0"
url = "https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"
}
}
}
repositories {
if ((project.hasProperty('GITHUBPACKAGES_USER') || System.getenv('GITHUBPACKAGES_USER') != null) && (project.hasProperty('GITHUBPACKAGES_PASSWORD') || System.getenv('GITHUBPACKAGES_PASSWORD') != null)) {
maven {
name = "GithubPackages"
url = uri("https://maven.pkg.github.com/InsanusMokrassar/TelegramBotAPI")
credentials {
username = project.hasProperty('GITHUBPACKAGES_USER') ? project.property('GITHUBPACKAGES_USER') : System.getenv('GITHUBPACKAGES_USER')
password = project.hasProperty('GITHUBPACKAGES_PASSWORD') ? project.property('GITHUBPACKAGES_PASSWORD') : System.getenv('GITHUBPACKAGES_PASSWORD')
}
}
}
if ((project.hasProperty('SONATYPE_USER') || System.getenv('SONATYPE_USER') != null) && (project.hasProperty('SONATYPE_PASSWORD') || System.getenv('SONATYPE_PASSWORD') != null)) {
maven {
name = "sonatype"
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials {
username = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : System.getenv('SONATYPE_USER')
password = project.hasProperty('SONATYPE_PASSWORD') ? project.property('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD')
}
}
}
}
}
}
signing {
useGpgCmd()
sign publishing.publications
}

View File

@@ -17,8 +17,9 @@ plugins {
project.version = "$library_version" project.version = "$library_version"
project.group = "$library_group" project.group = "$library_group"
project.description = "Additional extensions for core part of tgbotapi"
apply from: "publish.gradle" apply from: "../publish.gradle"
repositories { repositories {
mavenLocal() mavenLocal()

View File

@@ -1 +0,0 @@
{"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 Utility Extensions","description":"Util extensions for more useful work with updates and other things","url":"https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI-extensions-utils","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/"}]}}

View File

@@ -1,69 +0,0 @@
apply plugin: 'maven-publish'
apply plugin: 'signing'
task javadocsJar(type: Jar) {
classifier = 'javadoc'
}
publishing {
publications.all {
artifact javadocsJar
pom {
description = "Util extensions for more useful work with updates and other things"
name = "Telegram Bot API Utility Extensions"
url = "https://insanusmokrassar.github.io/TelegramBotAPI/TelegramBotAPI-extensions-utils"
scm {
developerConnection = "scm:git:[fetch=]https://github.com/insanusmokrassar/TelegramBotAPI.git[push=]https://github.com/insanusmokrassar/TelegramBotAPI.git"
url = "https://github.com/insanusmokrassar/TelegramBotAPI.git"
}
developers {
developer {
id = "InsanusMokrassar"
name = "Ovsiannikov Aleksei"
email = "ovsyannikov.alexey95@gmail.com"
}
}
licenses {
license {
name = "Apache Software License 2.0"
url = "https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE"
}
}
}
repositories {
if ((project.hasProperty('GITHUBPACKAGES_USER') || System.getenv('GITHUBPACKAGES_USER') != null) && (project.hasProperty('GITHUBPACKAGES_PASSWORD') || System.getenv('GITHUBPACKAGES_PASSWORD') != null)) {
maven {
name = "GithubPackages"
url = uri("https://maven.pkg.github.com/InsanusMokrassar/TelegramBotAPI")
credentials {
username = project.hasProperty('GITHUBPACKAGES_USER') ? project.property('GITHUBPACKAGES_USER') : System.getenv('GITHUBPACKAGES_USER')
password = project.hasProperty('GITHUBPACKAGES_PASSWORD') ? project.property('GITHUBPACKAGES_PASSWORD') : System.getenv('GITHUBPACKAGES_PASSWORD')
}
}
}
if ((project.hasProperty('SONATYPE_USER') || System.getenv('SONATYPE_USER') != null) && (project.hasProperty('SONATYPE_PASSWORD') || System.getenv('SONATYPE_PASSWORD') != null)) {
maven {
name = "sonatype"
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials {
username = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : System.getenv('SONATYPE_USER')
password = project.hasProperty('SONATYPE_PASSWORD') ? project.property('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD')
}
}
}
}
}
}
signing {
useGpgCmd()
sign publishing.publications
}

View File

@@ -8,7 +8,7 @@ import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.CallbackQuery.* import dev.inmo.tgbotapi.types.CallbackQuery.*
import dev.inmo.tgbotapi.types.ChatMember.* import dev.inmo.tgbotapi.types.ChatMember.*
import dev.inmo.tgbotapi.types.ChatMember.abstracts.* import dev.inmo.tgbotapi.types.ChatMember.abstracts.*
import dev.inmo.tgbotapi.types.ChatMember.abstracts.MemberChatMember import dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult.*
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.*
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.*
import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.audio.* import dev.inmo.tgbotapi.types.InlineQueries.InlineQueryResult.abstracts.results.audio.*
@@ -31,6 +31,8 @@ import dev.inmo.tgbotapi.types.chat.abstracts.extended.*
import dev.inmo.tgbotapi.types.dice.* import dev.inmo.tgbotapi.types.dice.*
import dev.inmo.tgbotapi.types.files.* import dev.inmo.tgbotapi.types.files.*
import dev.inmo.tgbotapi.types.files.abstracts.* import dev.inmo.tgbotapi.types.files.abstracts.*
import dev.inmo.tgbotapi.types.files.sticker.*
import dev.inmo.tgbotapi.types.files.sticker.Sticker
import dev.inmo.tgbotapi.types.location.* import dev.inmo.tgbotapi.types.location.*
import dev.inmo.tgbotapi.types.message.* import dev.inmo.tgbotapi.types.message.*
import dev.inmo.tgbotapi.types.message.ChatEvents.* import dev.inmo.tgbotapi.types.message.ChatEvents.*
@@ -42,6 +44,7 @@ import dev.inmo.tgbotapi.types.message.content.*
import dev.inmo.tgbotapi.types.message.content.abstracts.* import dev.inmo.tgbotapi.types.message.content.abstracts.*
import dev.inmo.tgbotapi.types.message.content.media.* import dev.inmo.tgbotapi.types.message.content.media.*
import dev.inmo.tgbotapi.types.message.payments.InvoiceContent import dev.inmo.tgbotapi.types.message.payments.InvoiceContent
import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentEvent
import dev.inmo.tgbotapi.types.passport.* import dev.inmo.tgbotapi.types.passport.*
import dev.inmo.tgbotapi.types.passport.decrypted.* import dev.inmo.tgbotapi.types.passport.decrypted.*
import dev.inmo.tgbotapi.types.passport.decrypted.abstracts.* import dev.inmo.tgbotapi.types.passport.decrypted.abstracts.*
@@ -2308,6 +2311,33 @@ inline fun TelegramMediaFile.asSticker(): Sticker? = this as? Sticker
@PreviewFeature @PreviewFeature
inline fun TelegramMediaFile.requireSticker(): Sticker = this as Sticker inline fun TelegramMediaFile.requireSticker(): Sticker = this as Sticker
@PreviewFeature
inline fun <T> TelegramMediaFile.whenSimpleSticker(block: (SimpleSticker) -> T) = asSimpleSticker() ?.let(block)
@PreviewFeature
inline fun TelegramMediaFile.asSimpleSticker(): SimpleSticker? = this as? SimpleSticker
@PreviewFeature
inline fun TelegramMediaFile.requireSimpleSticker(): SimpleSticker = this as SimpleSticker
@PreviewFeature
inline fun <T> TelegramMediaFile.whenAnimatedSticker(block: (AnimatedSticker) -> T) = asAnimatedSticker() ?.let(block)
@PreviewFeature
inline fun TelegramMediaFile.asAnimatedSticker(): AnimatedSticker? = this as? AnimatedSticker
@PreviewFeature
inline fun TelegramMediaFile.requireAnimatedSticker(): AnimatedSticker = this as AnimatedSticker
@PreviewFeature
inline fun <T> TelegramMediaFile.whenVideoSticker(block: (VideoSticker) -> T) = asVideoSticker() ?.let(block)
@PreviewFeature
inline fun TelegramMediaFile.asVideoSticker(): VideoSticker? = this as? VideoSticker
@PreviewFeature
inline fun TelegramMediaFile.requireVideoSticker(): VideoSticker = this as VideoSticker
@PreviewFeature @PreviewFeature
inline fun <T> TelegramMediaFile.whenVideoFile(block: (VideoFile) -> T) = asVideoFile() ?.let(block) inline fun <T> TelegramMediaFile.whenVideoFile(block: (VideoFile) -> T) = asVideoFile() ?.let(block)
@@ -3064,6 +3094,15 @@ inline fun ChatEvent.asPinnedMessage(): PinnedMessage? = this as? PinnedMessage
@PreviewFeature @PreviewFeature
inline fun ChatEvent.requirePinnedMessage(): PinnedMessage = this as PinnedMessage inline fun ChatEvent.requirePinnedMessage(): PinnedMessage = this as PinnedMessage
@PreviewFeature
inline fun <T> ChatEvent.whenSuccessfulPaymentEvent(block: (SuccessfulPaymentEvent) -> T) = asSuccessfulPaymentEvent() ?.let(block)
@PreviewFeature
inline fun ChatEvent.asSuccessfulPaymentEvent(): SuccessfulPaymentEvent? = this as? SuccessfulPaymentEvent
@PreviewFeature
inline fun ChatEvent.requireSuccessfulPaymentEvent(): SuccessfulPaymentEvent = this as SuccessfulPaymentEvent
@PreviewFeature @PreviewFeature
inline fun <T> ChatEvent.whenProximityAlertTriggered(block: (ProximityAlertTriggered) -> T) = asProximityAlertTriggered() ?.let(block) inline fun <T> ChatEvent.whenProximityAlertTriggered(block: (ProximityAlertTriggered) -> T) = asProximityAlertTriggered() ?.let(block)
@@ -3174,6 +3213,24 @@ inline fun ChatEvent.asVoiceChatStarted(): VoiceChatStarted? = this as? VoiceCha
@PreviewFeature @PreviewFeature
inline fun ChatEvent.requireVoiceChatStarted(): VoiceChatStarted = this as VoiceChatStarted inline fun ChatEvent.requireVoiceChatStarted(): VoiceChatStarted = this as VoiceChatStarted
@PreviewFeature
inline fun <T> ChatEvent.whenVoiceChatScheduled(block: (VoiceChatScheduled) -> T) = asVoiceChatScheduled() ?.let(block)
@PreviewFeature
inline fun ChatEvent.asVoiceChatScheduled(): VoiceChatScheduled? = this as? VoiceChatScheduled
@PreviewFeature
inline fun ChatEvent.requireVoiceChatScheduled(): VoiceChatScheduled = this as VoiceChatScheduled
@PreviewFeature
inline fun <T> ChatEvent.whenUserLoggedIn(block: (UserLoggedIn) -> T) = asUserLoggedIn() ?.let(block)
@PreviewFeature
inline fun ChatEvent.asUserLoggedIn(): UserLoggedIn? = this as? UserLoggedIn
@PreviewFeature
inline fun ChatEvent.requireUserLoggedIn(): UserLoggedIn = this as UserLoggedIn
@PreviewFeature @PreviewFeature
inline fun <T> CommonSendInvoiceData.whenSendInvoice(block: (SendInvoice) -> T) = asSendInvoice() ?.let(block) inline fun <T> CommonSendInvoiceData.whenSendInvoice(block: (SendInvoice) -> T) = asSendInvoice() ?.let(block)
@@ -3283,3 +3340,93 @@ inline fun ChatInviteLink.asChatInviteLinkUnlimited(): ChatInviteLinkUnlimited?
@PreviewFeature @PreviewFeature
inline fun ChatInviteLink.requireChatInviteLinkUnlimited(): ChatInviteLinkUnlimited = this as ChatInviteLinkUnlimited inline fun ChatInviteLink.requireChatInviteLinkUnlimited(): ChatInviteLinkUnlimited = this as ChatInviteLinkUnlimited
@PreviewFeature
inline fun <T> ForwardInfo.whenAnonymousForwardInfo(block: (AnonymousForwardInfo) -> T) = asAnonymousForwardInfo() ?.let(block)
@PreviewFeature
inline fun ForwardInfo.asAnonymousForwardInfo(): AnonymousForwardInfo? = this as? AnonymousForwardInfo
@PreviewFeature
inline fun ForwardInfo.requireAnonymousForwardInfo(): AnonymousForwardInfo = this as AnonymousForwardInfo
@PreviewFeature
inline fun <T> ForwardInfo.whenUserForwardInfo(block: (UserForwardInfo) -> T) = asUserForwardInfo() ?.let(block)
@PreviewFeature
inline fun ForwardInfo.asUserForwardInfo(): UserForwardInfo? = this as? UserForwardInfo
@PreviewFeature
inline fun ForwardInfo.requireUserForwardInfo(): UserForwardInfo = this as UserForwardInfo
@PreviewFeature
inline fun <T> ForwardInfo.whenForwardFromPublicChatInfo(block: (ForwardFromPublicChatInfo) -> T) = asForwardFromPublicChatInfo() ?.let(block)
@PreviewFeature
inline fun ForwardInfo.asForwardFromPublicChatInfo(): ForwardFromPublicChatInfo? = this as? ForwardFromPublicChatInfo
@PreviewFeature
inline fun ForwardInfo.requireForwardFromPublicChatInfo(): ForwardFromPublicChatInfo = this as ForwardFromPublicChatInfo
@PreviewFeature
inline fun <T> ForwardInfo.whenForwardFromChannelInfo(block: (ForwardFromChannelInfo) -> T) = asForwardFromChannelInfo() ?.let(block)
@PreviewFeature
inline fun ForwardInfo.asForwardFromChannelInfo(): ForwardFromChannelInfo? = this as? ForwardFromChannelInfo
@PreviewFeature
inline fun ForwardInfo.requireForwardFromChannelInfo(): ForwardFromChannelInfo = this as ForwardFromChannelInfo
@PreviewFeature
inline fun <T> ForwardInfo.whenForwardFromSupergroupInfo(block: (ForwardFromSupergroupInfo) -> T) = asForwardFromSupergroupInfo() ?.let(block)
@PreviewFeature
inline fun ForwardInfo.asForwardFromSupergroupInfo(): ForwardFromSupergroupInfo? = this as? ForwardFromSupergroupInfo
@PreviewFeature
inline fun ForwardInfo.requireForwardFromSupergroupInfo(): ForwardFromSupergroupInfo = this as ForwardFromSupergroupInfo
@PreviewFeature
inline fun <T> MessageContent.whenTextedInput(block: (TextedInput) -> T) = asTextedInput() ?.let(block)
@PreviewFeature
inline fun MessageContent.asTextedInput(): TextedInput? = this as? TextedInput
@PreviewFeature
inline fun MessageContent.requireTextedInput(): TextedInput = this as TextedInput
@PreviewFeature
inline fun <T> ScheduledCloseInfo.whenExactScheduledCloseInfo(block: (ExactScheduledCloseInfo) -> T) = asExactScheduledCloseInfo() ?.let(block)
@PreviewFeature
inline fun ScheduledCloseInfo.asExactScheduledCloseInfo(): ExactScheduledCloseInfo? = this as? ExactScheduledCloseInfo
@PreviewFeature
inline fun ScheduledCloseInfo.requireExactScheduledCloseInfo(): ExactScheduledCloseInfo = this as ExactScheduledCloseInfo
@PreviewFeature
inline fun <T> ScheduledCloseInfo.whenApproximateScheduledCloseInfo(block: (ApproximateScheduledCloseInfo) -> T) = asApproximateScheduledCloseInfo() ?.let(block)
@PreviewFeature
inline fun ScheduledCloseInfo.asApproximateScheduledCloseInfo(): ApproximateScheduledCloseInfo? = this as? ApproximateScheduledCloseInfo
@PreviewFeature
inline fun ScheduledCloseInfo.requireApproximateScheduledCloseInfo(): ApproximateScheduledCloseInfo = this as ApproximateScheduledCloseInfo
@PreviewFeature
inline fun <T> ChosenInlineResult.whenLocationChosenInlineResult(block: (LocationChosenInlineResult) -> T) = asLocationChosenInlineResult() ?.let(block)
@PreviewFeature
inline fun ChosenInlineResult.asLocationChosenInlineResult(): LocationChosenInlineResult? = this as? LocationChosenInlineResult
@PreviewFeature
inline fun ChosenInlineResult.requireLocationChosenInlineResult(): LocationChosenInlineResult = this as LocationChosenInlineResult
@PreviewFeature
inline fun <T> ChosenInlineResult.whenBaseChosenInlineResult(block: (BaseChosenInlineResult) -> T) = asBaseChosenInlineResult() ?.let(block)
@PreviewFeature
inline fun ChosenInlineResult.asBaseChosenInlineResult(): BaseChosenInlineResult? = this as? BaseChosenInlineResult
@PreviewFeature
inline fun ChosenInlineResult.requireBaseChosenInlineResult(): BaseChosenInlineResult = this as BaseChosenInlineResult

View File

@@ -1,7 +1,2 @@
package dev.inmo.tgbotapi.extensions.utils.extensions package dev.inmo.tgbotapi.extensions.utils.extensions
import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.SentMediaGroupUpdate
import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate
import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.merge

View File

@@ -2,13 +2,11 @@ package dev.inmo.tgbotapi.extensions.utils.extensions
import dev.inmo.tgbotapi.CommonAbstracts.FromUser import dev.inmo.tgbotapi.CommonAbstracts.FromUser
import dev.inmo.tgbotapi.CommonAbstracts.WithUser import dev.inmo.tgbotapi.CommonAbstracts.WithUser
import dev.inmo.tgbotapi.extensions.utils.asFromUser
import dev.inmo.tgbotapi.extensions.utils.asUser import dev.inmo.tgbotapi.extensions.utils.asUser
import dev.inmo.tgbotapi.extensions.utils.shortcuts.chat import dev.inmo.tgbotapi.extensions.utils.shortcuts.chat
import dev.inmo.tgbotapi.types.ChatJoinRequest
import dev.inmo.tgbotapi.types.User import dev.inmo.tgbotapi.types.User
import dev.inmo.tgbotapi.types.chat.abstracts.Chat import dev.inmo.tgbotapi.types.chat.abstracts.Chat
import dev.inmo.tgbotapi.types.update.* import dev.inmo.tgbotapi.types.update.ChatJoinRequestUpdate
import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.* import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.*
import dev.inmo.tgbotapi.types.update.abstracts.BaseMessageUpdate import dev.inmo.tgbotapi.types.update.abstracts.BaseMessageUpdate
import dev.inmo.tgbotapi.types.update.abstracts.Update import dev.inmo.tgbotapi.types.update.abstracts.Update

View File

@@ -0,0 +1,21 @@
package dev.inmo.tgbotapi.extensions.utils.extensions.raw
import dev.inmo.tgbotapi.extensions.utils.*
import dev.inmo.tgbotapi.types.CallbackQuery.CallbackQuery
import dev.inmo.tgbotapi.types.InlineMessageIdentifier
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent
import dev.inmo.tgbotapi.utils.RiskFeature
@RiskFeature(RawFieldsUsageWarning)
val CallbackQuery.message: ContentMessage<MessageContent>?
get() = asMessageCallbackQuery() ?.message
@RiskFeature(RawFieldsUsageWarning)
val CallbackQuery.inline_message_id: InlineMessageIdentifier?
get() = asInlineMessageIdCallbackQuery() ?.inlineMessageId
@RiskFeature(RawFieldsUsageWarning)
val CallbackQuery.data: String?
get() = asDataCallbackQuery() ?.data
@RiskFeature(RawFieldsUsageWarning)
val CallbackQuery.game_short_name: String?
get() = asGameShortNameCallbackQuery() ?.gameShortName

View File

@@ -0,0 +1,9 @@
package dev.inmo.tgbotapi.extensions.utils.extensions.raw
import dev.inmo.tgbotapi.types.ChatInviteLink
import dev.inmo.tgbotapi.types.ChatJoinRequest
import dev.inmo.tgbotapi.utils.RiskFeature
@RiskFeature(RawFieldsUsageWarning)
val ChatJoinRequest.invite_link: ChatInviteLink
get() = inviteLink

View File

@@ -0,0 +1,16 @@
package dev.inmo.tgbotapi.extensions.utils.extensions.raw
import dev.inmo.tgbotapi.types.ChatInviteLink
import dev.inmo.tgbotapi.types.ChatMember.abstracts.ChatMember
import dev.inmo.tgbotapi.types.ChatMemberUpdated
import dev.inmo.tgbotapi.utils.RiskFeature
@RiskFeature(RawFieldsUsageWarning)
val ChatMemberUpdated.old_chat_member: ChatMember
get() = oldChatMemberState
@RiskFeature(RawFieldsUsageWarning)
val ChatMemberUpdated.new_chat_member: ChatMember
get() = newChatMemberState
@RiskFeature(RawFieldsUsageWarning)
val ChatMemberUpdated.invite_link: ChatInviteLink?
get() = inviteLink

View File

@@ -0,0 +1,20 @@
package dev.inmo.tgbotapi.extensions.utils.extensions.raw
import dev.inmo.tgbotapi.extensions.utils.asLocationChosenInlineResult
import dev.inmo.tgbotapi.types.InlineMessageIdentifier
import dev.inmo.tgbotapi.types.InlineQueries.ChosenInlineResult.ChosenInlineResult
import dev.inmo.tgbotapi.types.InlineQueryIdentifier
import dev.inmo.tgbotapi.types.location.Location
import dev.inmo.tgbotapi.utils.RiskFeature
@RiskFeature(RawFieldsUsageWarning)
val ChosenInlineResult.location: Location?
get() = asLocationChosenInlineResult() ?.location
@RiskFeature(RawFieldsUsageWarning)
val ChosenInlineResult.result_id: InlineQueryIdentifier
get() = resultId
@RiskFeature(RawFieldsUsageWarning)
val ChosenInlineResult.inline_message_id: InlineMessageIdentifier?
get() = inlineMessageId

View File

@@ -0,0 +1,14 @@
package dev.inmo.tgbotapi.extensions.utils.extensions.raw
import dev.inmo.tgbotapi.extensions.utils.asLocationInlineQuery
import dev.inmo.tgbotapi.types.InlineQueries.query.InlineQuery
import dev.inmo.tgbotapi.types.location.Location
import dev.inmo.tgbotapi.utils.RiskFeature
@RiskFeature(RawFieldsUsageWarning)
val InlineQuery.location: Location?
get() = asLocationInlineQuery() ?.location
@RiskFeature(RawFieldsUsageWarning)
val InlineQuery.chat_type: String?
get() = chatType ?.stringified

View File

@@ -0,0 +1,209 @@
package dev.inmo.tgbotapi.extensions.utils.extensions.raw
import dev.inmo.tgbotapi.extensions.utils.*
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList
import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup
import dev.inmo.tgbotapi.types.chat.abstracts.Chat
import dev.inmo.tgbotapi.types.chat.abstracts.PublicChat
import dev.inmo.tgbotapi.types.dice.Dice
import dev.inmo.tgbotapi.types.files.*
import dev.inmo.tgbotapi.types.files.sticker.Sticker
import dev.inmo.tgbotapi.types.games.Game
import dev.inmo.tgbotapi.types.location.Location
import dev.inmo.tgbotapi.types.message.ChatEvents.*
import dev.inmo.tgbotapi.types.message.ChatEvents.voice.*
import dev.inmo.tgbotapi.types.message.abstracts.ConnectedFromChannelGroupContentMessage
import dev.inmo.tgbotapi.types.message.abstracts.Message
import dev.inmo.tgbotapi.types.message.content.TextContent
import dev.inmo.tgbotapi.types.passport.PassportData
import dev.inmo.tgbotapi.types.payments.Invoice
import dev.inmo.tgbotapi.types.payments.SuccessfulPayment
import dev.inmo.tgbotapi.types.polls.Poll
import dev.inmo.tgbotapi.types.venue.Venue
import dev.inmo.tgbotapi.utils.RiskFeature
@RiskFeature(RawFieldsUsageWarning)
inline val Message.from: User?
get() = asFromUser() ?.from
@RiskFeature(RawFieldsUsageWarning)
inline val Message.sender_chat: PublicChat?
get() = asFromChannelGroupContentMessage() ?.senderChat
@RiskFeature(RawFieldsUsageWarning)
inline val Message.forward_from: User?
get() = asPossiblyForwardedMessage() ?.forwardInfo ?.asUserForwardInfo() ?.from
@RiskFeature(RawFieldsUsageWarning)
inline val Message.forward_from_chat: Chat?
get() = asPossiblyForwardedMessage() ?.forwardInfo ?.asForwardFromPublicChatInfo() ?.chat
@RiskFeature(RawFieldsUsageWarning)
inline val Message.forward_from_message_id: MessageIdentifier?
get() = asPossiblyForwardedMessage() ?.forwardInfo ?.asForwardFromChannelInfo() ?.messageId
@RiskFeature(RawFieldsUsageWarning)
inline val Message.forward_signature: ForwardSignature?
get() = asPossiblyForwardedMessage() ?.forwardInfo ?.asForwardFromChannelInfo() ?.signature
@RiskFeature(RawFieldsUsageWarning)
inline val Message.forward_sender_name: ForwardSenderName?
get() = asPossiblyForwardedMessage() ?.forwardInfo ?.asAnonymousForwardInfo() ?.senderName
@RiskFeature(RawFieldsUsageWarning)
inline val Message.forward_date: TelegramDate?
get() = asPossiblyForwardedMessage() ?.forwardInfo ?.dateOfOriginal
@RiskFeature(RawFieldsUsageWarning)
inline val Message.is_automatic_forward: Boolean?
get() = this is ConnectedFromChannelGroupContentMessage<*>
@RiskFeature(RawFieldsUsageWarning)
inline val Message.reply_to_message: Message?
get() = asPossiblyReplyMessage() ?.replyTo
@RiskFeature(RawFieldsUsageWarning)
inline val Message.via_bot: CommonBot?
get() = asPossiblySentViaBotCommonMessage() ?.senderBot
@RiskFeature(RawFieldsUsageWarning)
inline val Message.edit_date: TelegramDate?
get() = asPossiblyEditedMessage() ?.editDate ?.toTelegramDate()
@RiskFeature(RawFieldsUsageWarning)
inline val Message.has_protected_content: Boolean?
get() = asContentMessage() ?.hasProtectedContent
@RiskFeature(RawFieldsUsageWarning)
inline val Message.media_group_id: MediaGroupIdentifier?
get() = asMediaGroupMessage() ?.mediaGroupId
@RiskFeature(RawFieldsUsageWarning)
inline val Message.author_signature: AuthorSignature?
get() = asSignedMessage() ?.authorSignature
@RiskFeature(RawFieldsUsageWarning)
inline val Message.text: String?
get() = asContentMessage() ?.content ?.asTextContent() ?.text
@RiskFeature(RawFieldsUsageWarning)
inline val Message.entities: TextSourcesList?
get() = asContentMessage() ?.content ?.asTextContent() ?.textSources
@RiskFeature(RawFieldsUsageWarning)
inline val Message.caption: String?
get() = whenContentMessage {
if (it.content !is TextContent) {
it.content.asTextedInput() ?.text
} else {
null
}
}
@RiskFeature(RawFieldsUsageWarning)
inline val Message.caption_entities: TextSourcesList?
get() = whenContentMessage {
if (it.content !is TextContent) {
it.content.asTextedInput() ?.textSources
} else {
null
}
}
@RiskFeature(RawFieldsUsageWarning)
inline val Message.audio: AudioFile?
get() = asContentMessage() ?.content ?.asAudioContent() ?.media
@RiskFeature(RawFieldsUsageWarning)
inline val Message.document: DocumentFile?
get() = asContentMessage() ?.content ?.asDocumentContent() ?.media
@RiskFeature(RawFieldsUsageWarning)
inline val Message.animation: AnimationFile?
get() = asContentMessage() ?.content ?.asAnimationContent() ?.media
@RiskFeature(RawFieldsUsageWarning)
inline val Message.game: Game?
get() = asContentMessage() ?.content ?.asGameContent() ?.game
@RiskFeature(RawFieldsUsageWarning)
inline val Message.photo: Photo?
get() = asContentMessage() ?.content ?.asPhotoContent() ?.mediaCollection
@RiskFeature(RawFieldsUsageWarning)
inline val Message.sticker: Sticker?
get() = asContentMessage() ?.content ?.asStickerContent() ?.media
@RiskFeature(RawFieldsUsageWarning)
inline val Message.video: VideoFile?
get() = asContentMessage() ?.content ?.asVideoContent() ?.media
@RiskFeature(RawFieldsUsageWarning)
inline val Message.voice: VoiceFile?
get() = asContentMessage() ?.content ?.asVoiceContent() ?.media
@RiskFeature(RawFieldsUsageWarning)
inline val Message.video_note: VideoNoteFile?
get() = asContentMessage() ?.content ?.asVideoNoteContent() ?.media
@RiskFeature(RawFieldsUsageWarning)
inline val Message.contact: Contact?
get() = asContentMessage() ?.content ?.asContactContent() ?.contact
@RiskFeature(RawFieldsUsageWarning)
inline val Message.location: Location?
get() = asContentMessage() ?.content ?.asLocationContent() ?.location
@RiskFeature(RawFieldsUsageWarning)
inline val Message.venue: Venue?
get() = asContentMessage() ?.content ?.asVenueContent() ?.venue
@RiskFeature(RawFieldsUsageWarning)
inline val Message.poll: Poll?
get() = asContentMessage() ?.content ?.asPollContent() ?.poll
@RiskFeature(RawFieldsUsageWarning)
inline val Message.invoice: Invoice?
get() = asContentMessage() ?.content ?.asInvoiceContent() ?.invoice
@RiskFeature(RawFieldsUsageWarning)
inline val Message.dice: Dice?
get() = asContentMessage() ?.content ?.asDiceContent() ?.dice
@RiskFeature(RawFieldsUsageWarning)
inline val Message.new_chat_members: List<User>?
get() = asChatEventMessage() ?.chatEvent ?.asNewChatMembers() ?.members
@RiskFeature(RawFieldsUsageWarning)
inline val Message.left_chat_member: User?
get() = asChatEventMessage() ?.chatEvent ?.asLeftChatMember() ?.user
@RiskFeature(RawFieldsUsageWarning)
inline val Message.new_chat_title: String?
get() = asChatEventMessage() ?.chatEvent ?.asNewChatTitle() ?.title
@RiskFeature(RawFieldsUsageWarning)
inline val Message.new_chat_photo: Photo?
get() = asChatEventMessage() ?.chatEvent ?.asNewChatPhoto() ?.photo
@RiskFeature(RawFieldsUsageWarning)
inline val Message.delete_chat_photo: Boolean
get() = asChatEventMessage() ?.chatEvent is DeleteChatPhoto
@RiskFeature(RawFieldsUsageWarning)
inline val Message.group_chat_created: Boolean
get() = asChatEventMessage() ?.chatEvent is GroupChatCreated
@RiskFeature(RawFieldsUsageWarning)
inline val Message.supergroup_chat_created: Boolean
get() = asChatEventMessage() ?.chatEvent is SupergroupChatCreated
@RiskFeature(RawFieldsUsageWarning)
inline val Message.channel_chat_created: Boolean
get() = asChatEventMessage() ?.chatEvent is ChannelChatCreated
@RiskFeature(RawFieldsUsageWarning)
inline val Message.migrate_to_chat_id: ChatId?
get() = asChatEventMessage() ?.chatEvent ?.asGroupChatCreated() ?.migratedTo
@RiskFeature(RawFieldsUsageWarning)
inline val Message.migrate_from_chat_id: ChatId?
get() = asChatEventMessage() ?.chatEvent ?.let {
it ?.asSupergroupChatCreated() ?.migratedFrom ?: it ?.asMigratedToSupergroup() ?.migratedFrom
}
@RiskFeature(RawFieldsUsageWarning)
inline val Message.pinned_message: Message?
get() = asChatEventMessage() ?.chatEvent ?.asPinnedMessage() ?.message
@RiskFeature(RawFieldsUsageWarning)
inline val Message.successful_payment: SuccessfulPayment?
get() = asChatEventMessage() ?.chatEvent ?.asSuccessfulPaymentEvent() ?.payment
@RiskFeature(RawFieldsUsageWarning)
inline val Message.voice_chat_scheduled: VoiceChatScheduled?
get() = asChatEventMessage() ?.chatEvent ?.asVoiceChatScheduled()
@RiskFeature(RawFieldsUsageWarning)
inline val Message.voice_chat_started: VoiceChatStarted?
get() = asChatEventMessage() ?.chatEvent ?.asVoiceChatStarted()
@RiskFeature(RawFieldsUsageWarning)
inline val Message.voice_chat_ended: VoiceChatEnded?
get() = asChatEventMessage() ?.chatEvent ?.asVoiceChatEnded()
@RiskFeature(RawFieldsUsageWarning)
inline val Message.voice_chat_participants_invited: VoiceChatParticipantsInvited?
get() = asChatEventMessage() ?.chatEvent ?.asVoiceChatParticipantsInvited()
@RiskFeature(RawFieldsUsageWarning)
inline val Message.message_auto_delete_timer_changed: MessageAutoDeleteTimerChanged?
get() = asChatEventMessage() ?.chatEvent ?.asMessageAutoDeleteTimerChanged()
@RiskFeature(RawFieldsUsageWarning)
inline val Message.connected_website: String?
get() = asChatEventMessage() ?.chatEvent ?.asUserLoggedIn() ?.domain
@RiskFeature(RawFieldsUsageWarning)
inline val Message.proximity_alert_triggered: ProximityAlertTriggered?
get() = asChatEventMessage() ?.chatEvent ?.asProximityAlertTriggered()
@RiskFeature(RawFieldsUsageWarning)
inline val Message.passport_data: PassportData?
get() = asPassportMessage() ?.passportData
@RiskFeature(RawFieldsUsageWarning)
inline val Message.reply_markup: InlineKeyboardMarkup?
get() = asCommonMessage() ?.replyMarkup

View File

@@ -0,0 +1,43 @@
package dev.inmo.tgbotapi.extensions.utils.extensions.raw
import dev.inmo.tgbotapi.extensions.utils.*
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.MessageEntity.textsources.TextSourcesList
import dev.inmo.tgbotapi.types.polls.*
import dev.inmo.tgbotapi.utils.RiskFeature
import kotlinx.serialization.json.jsonPrimitive
@RiskFeature(RawFieldsUsageWarning)
val Poll.total_voter_count: Int
get() = votesCount
@RiskFeature(RawFieldsUsageWarning)
val Poll.type: String
get() = when (this) {
is RegularPoll -> "regular"
is UnknownPollType -> raw["type"]!!.jsonPrimitive.content
is QuizPoll -> "quiz"
}
@RiskFeature(RawFieldsUsageWarning)
val Poll.allows_multiple_answers: Boolean
get() = asMultipleAnswersPoll() ?.allowMultipleAnswers == true
@RiskFeature(RawFieldsUsageWarning)
val Poll.correct_option_id: Int?
get() = asQuizPoll() ?.correctOptionId
@RiskFeature(RawFieldsUsageWarning)
val Poll.explanation: String?
get() = asQuizPoll() ?.text
@RiskFeature(RawFieldsUsageWarning)
val Poll.explanation_entities: TextSourcesList?
get() = asQuizPoll() ?.textSources
@RiskFeature(RawFieldsUsageWarning)
val Poll.open_period: Seconds?
get() = scheduledCloseInfo ?.asApproximateScheduledCloseInfo() ?.openDuration ?.seconds ?.toInt()
@RiskFeature(RawFieldsUsageWarning)
val Poll.close_date: TelegramDate?
get() = scheduledCloseInfo ?.asExactScheduledCloseInfo() ?.closeDateTime ?.toTelegramDate()
@RiskFeature(RawFieldsUsageWarning)
val Poll.is_closed: Boolean
get() = isClosed
@RiskFeature(RawFieldsUsageWarning)
val Poll.is_anonymous: Boolean
get() = isAnonymous

View File

@@ -0,0 +1,12 @@
package dev.inmo.tgbotapi.extensions.utils.extensions.raw
import dev.inmo.tgbotapi.types.PollIdentifier
import dev.inmo.tgbotapi.types.polls.PollAnswer
import dev.inmo.tgbotapi.utils.RiskFeature
@RiskFeature(RawFieldsUsageWarning)
val PollAnswer.poll_id: PollIdentifier
get() = pollId
@RiskFeature(RawFieldsUsageWarning)
val PollAnswer.option_ids: List<Int>
get() = chosen

View File

@@ -0,0 +1,20 @@
package dev.inmo.tgbotapi.extensions.utils.extensions.raw
import dev.inmo.tgbotapi.types.InvoicePayload
import dev.inmo.tgbotapi.types.ShippingOptionIdentifier
import dev.inmo.tgbotapi.types.payments.OrderInfo
import dev.inmo.tgbotapi.types.payments.PreCheckoutQuery
import dev.inmo.tgbotapi.utils.RiskFeature
@RiskFeature(RawFieldsUsageWarning)
val PreCheckoutQuery.total_amount: Long
get() = amount
@RiskFeature(RawFieldsUsageWarning)
val PreCheckoutQuery.invoice_payload: InvoicePayload
get() = invoicePayload
@RiskFeature(RawFieldsUsageWarning)
val PreCheckoutQuery.shipping_option_id: ShippingOptionIdentifier?
get() = shippingOptionId
@RiskFeature(RawFieldsUsageWarning)
val PreCheckoutQuery.order_info: OrderInfo?
get() = orderInfo

View File

@@ -0,0 +1,3 @@
package dev.inmo.tgbotapi.extensions.utils.extensions.raw
internal const val RawFieldsUsageWarning = "This API is raw and experimental. So, it is possible that behaviour of this API will be changed in near updates"

View File

@@ -0,0 +1,13 @@
package dev.inmo.tgbotapi.extensions.utils.extensions.raw
import dev.inmo.tgbotapi.types.InvoicePayload
import dev.inmo.tgbotapi.types.payments.ShippingAddress
import dev.inmo.tgbotapi.types.payments.ShippingQuery
import dev.inmo.tgbotapi.utils.RiskFeature
@RiskFeature(RawFieldsUsageWarning)
val ShippingQuery.invoice_payload: InvoicePayload
get() = invoicePayload
@RiskFeature(RawFieldsUsageWarning)
val ShippingQuery.shipping_address: ShippingAddress
get() = shippingAddress

View File

@@ -0,0 +1,21 @@
package dev.inmo.tgbotapi.extensions.utils.extensions.raw
import dev.inmo.tgbotapi.requests.abstracts.FileId
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.files.sticker.*
import dev.inmo.tgbotapi.types.stickers.MaskPosition
inline val Sticker.file_id: FileId
get() = fileId
inline val Sticker.file_unique_id: FileUniqueId
get() = fileUniqueId
inline val Sticker.is_animated: Boolean
get() = this is AnimatedSticker
inline val Sticker.is_video: Boolean
get() = this is VideoSticker
inline val Sticker.set_name: StickerSetName?
get() = stickerSetName
inline val Sticker.mask_position: MaskPosition?
get() = maskPosition
inline val Sticker.file_size: Long?
get() = fileSize

View File

@@ -9,9 +9,15 @@ import dev.inmo.tgbotapi.types.message.abstracts.Message
private const val internalLinkBeginning = "https://t.me" private const val internalLinkBeginning = "https://t.me"
fun makeUsernameLink(username: String) = "$internalLinkBeginning/$username" fun makeUsernameLink(username: String) = "$internalLinkBeginning/$username"
fun makeUsernameDeepLinkPrefix(username: String) = "${makeUsernameLink(username)}?start="
inline val Username.link inline val Username.link
get() = makeUsernameLink(username) get() = makeUsernameLink(usernameWithoutAt)
inline val Username.deepLinkPrefix
get() = makeUsernameDeepLinkPrefix(usernameWithoutAt)
inline fun makeLink(username: Username) = username.link inline fun makeLink(username: Username) = username.link
inline fun makeTelegramDeepLink(username: String, startParameter: String) = "${makeUsernameDeepLinkPrefix(username)}$startParameter"
inline fun makeDeepLink(username: Username, startParameter: String) = "${username.deepLinkPrefix}$startParameter"
inline fun makeTelegramDeepLink(username: Username, startParameter: String) = makeDeepLink(username, startParameter)
fun makeLinkToMessage( fun makeLinkToMessage(
username: String, username: String,

Some files were not shown because too many files have changed in this diff Show More