mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-11-16 12:00:18 +00:00
Compare commits
80 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f80bb18ca5 | |||
| 40eaffb8e3 | |||
| 0c9f9f59c1 | |||
| 12496f8261 | |||
| 3fe7bd1382 | |||
| e3117f3679 | |||
| 562459f0b7 | |||
| e98e61747c | |||
| e1082c3741 | |||
| 3fa2071847 | |||
| 4c60b8fd82 | |||
| cb30beaa31 | |||
| 10df8cbc55 | |||
| 4b66617db6 | |||
| 9ddab0bf29 | |||
| e43d7350ed | |||
| 82129205fa | |||
| 034b30d65f | |||
| 0d72c51448 | |||
| fe11b088fc | |||
| 336f280b8a | |||
| 0f9e048274 | |||
| f8b6073cd4 | |||
| 0899a69762 | |||
| 031c61a872 | |||
| 33d8dcf977 | |||
| 2f09504f08 | |||
| f4c11cacc6 | |||
| 4ac01d5331 | |||
| bb3ebb455e | |||
| 7694b25d33 | |||
| b095f07b9c | |||
| 72127ce133 | |||
| 398adf06ff | |||
| dbef69ffac | |||
| f68edebd24 | |||
| 482d924070 | |||
| e7495468a2 | |||
| bba37d8889 | |||
| 198e15a937 | |||
| 5ee472305c | |||
| 47428dd6f9 | |||
| b4e4bed622 | |||
| 4dd2a8437c | |||
| 8b93922f82 | |||
| 43b08e9319 | |||
| 62d474b7cc | |||
| 0066e814b3 | |||
| ef7e94ba68 | |||
| 27aba72a5a | |||
| 680e960037 | |||
| ff47168fdc | |||
| a68c31f9d1 | |||
| ac915b79f7 | |||
| 1659f6f909 | |||
| 5249fb517f | |||
| fdf45d7566 | |||
| dc93997b8c | |||
| 6dd701d33c | |||
| 6f1f5e640a | |||
| dd0e3c04bc | |||
| a17af67f83 | |||
| 761e08afc6 | |||
| a09af8870a | |||
| 0ef4341baf | |||
| 91d8fbb232 | |||
| 0c1df47dbb | |||
| b582adc3a0 | |||
| 7660102435 | |||
| 5dbfeca18f | |||
| f3fc0769ef | |||
| 24d11d2c2b | |||
| 498efc2ec3 | |||
| 21544013d9 | |||
| e296c2ee00 | |||
| ed60dc49e7 | |||
| c1b5b3ca19 | |||
| 24498479a8 | |||
| cb64f44ceb | |||
| ba145d3ff8 |
165
CHANGELOG.md
165
CHANGELOG.md
@@ -1,5 +1,170 @@
|
||||
# TelegramBotAPI changelog
|
||||
|
||||
## 0.22.0
|
||||
|
||||
* **`KtorCallFactory` must return `HttpStatement` instead of `HttpClientCall`**
|
||||
* `SendMessage` was renamed to `SendTextMessage` and previous `SendMessage` is deprecated
|
||||
* All `AbleToBe*` interfaces was renamed to `Possibly*`
|
||||
* `AbleToBeEditedMessage` -> `PossiblyEditedMessage`
|
||||
* `AbleToBeForwardedMessage` -> `PossiblyForwardedMessage`
|
||||
* `AbleToBeMarkedUp` -> `PossiblyMarkedUp`
|
||||
* `AbleToBeEditedMessage` -> `PossiblyEditedMessage`
|
||||
* `ForwardedMessage` type was renamed to `ForwardInfo`
|
||||
* `AnonymousForwardedMessage` -> `AnonymousForwardInfo`
|
||||
* `UserForwardedMessage` -> `UserForwardInfo`
|
||||
* `ForwardedFromChannelMessage` -> `ForwardFromChannelInfo`
|
||||
* `PossiblyForwardedMessage#forwarded` field now renamed to `forwardInfo`
|
||||
* All serializers in library now are `internal`. **If you have used some of them or I have marked as internal by a
|
||||
mistake - don't hesitate to say this.**
|
||||
* `EditChatMessage` now have generic type and extends `SimpleRequest<ContentMessage<GenericType>>`
|
||||
* `ResendableContent` now extends `Request<out Message>` instead of `Request<Message>`
|
||||
* Most part of requests have changed return type. They are listed below:
|
||||
<details>
|
||||
|
||||
* `ForwardMessage`
|
||||
* `GetChatAdministrators`
|
||||
* `EditChatMessageLiveLocation`
|
||||
* `StopChatMessageLiveLocation`
|
||||
* `EditChatMessageText`
|
||||
* `EditChatMessageCaption`
|
||||
* `EditChatMessageMedia`
|
||||
* `EditChatMessageReplyMarkup`
|
||||
* `SendAnimation`
|
||||
* `SendAudio`
|
||||
* `SendContact`
|
||||
* `SendLocation`
|
||||
* `SendTextMessage`
|
||||
* `SendPoll`
|
||||
* `SendVenue`
|
||||
* `SendGame`
|
||||
* `SendDocument`
|
||||
* `SendMediaGroup`
|
||||
* `SendPhoto`
|
||||
* `SendVideo`
|
||||
* `SendVideoNote`
|
||||
* `SendVoice`
|
||||
* `SendSticker`
|
||||
|
||||
</details>
|
||||
* Changed type of `createResend`
|
||||
<details>
|
||||
|
||||
* `GameContent`
|
||||
* `LocationContent`
|
||||
* `PollContent`
|
||||
* `TextContent`
|
||||
* `VenueContent`
|
||||
* `AnimationContent`
|
||||
* `AudioContent`
|
||||
* `DocumentContent`
|
||||
* `ContactContent`
|
||||
* `PhotoContent`
|
||||
* `VideoContent`
|
||||
* `VideoNoteContent`
|
||||
* `VoiceContent`
|
||||
* `StickerContent`
|
||||
|
||||
</details>
|
||||
* Version updates:
|
||||
* Ktor `1.2.6` -> `1.3.0`
|
||||
|
||||
## 0.21.0 TelegramBotAPI 4.5
|
||||
|
||||
* _**All `MessageEntity`'es now are replaced with `TextPart`**_
|
||||
* Added support of strikethrough and underline
|
||||
* Added `UnderlineTextSource`
|
||||
* Added `StrikethroughTextSource`
|
||||
* Added support in `RawMessageEntity`
|
||||
* Added support of `MarkdownV2`
|
||||
* Now will not be thrown exception when there is income unknown type of `RawMessageEntity`. Instead of this will be
|
||||
created `RegularTextSource` with the same text
|
||||
* Fixed problem that usually string formatting did not trigger escaping of control characters
|
||||
* Actualized work with `pre` type of text - now it is possible to use `language` for formatting of text
|
||||
* Removed constructor of `TextMentionTextSource`, which was deprecated previously
|
||||
* All `TelegramMediaFile` instances now have field `fileUniqueId`, which represents `file_unique_id` field from API
|
||||
* Now `ChatPhoto` have two additional fields: `smallFileUniqueId` and `bigFileUniqueId`
|
||||
* Now any administrator object instance have `customTitle` nullable field
|
||||
* Added the new request `SetChatAdministratorCustomTitle` to manage the custom titles of administrators promoted by the
|
||||
bot.
|
||||
* Added the field `slowModeDelay` to the `ExtendedSupergroupChat` objects.
|
||||
|
||||
* `CaptionedInput` now have extension `fullEntitiesList` which will return list of `TextPart` with `RegularSource`'s
|
||||
* `TextPart` added - it will be used as part of some text and can be not related to telegram bot
|
||||
* `MultilevelTextSource` was added - it is type of `TextSource`, which can have subsources as parts of this text
|
||||
* In all `TextSource`s all fields now are lazy for avoiding of potential risk for performance issues
|
||||
|
||||
* Updates in versions:
|
||||
* Coroutines `1.3.2` -> `1.3.3`
|
||||
* Klock `1.8.0` -> `1.8.6`
|
||||
* UUID `0.0.6` -> `0.0.7`
|
||||
|
||||
## 0.20.0 MPP Migration
|
||||
|
||||
* Time library change: `joda-time` -> `com.soywiz.korlibs.klock:klock`
|
||||
* `Currencied` now using as `currency` value with type `String`
|
||||
* For `Java` there is `Currencied#javaCurrency` extension function, which will give an old currency work way
|
||||
* `User` now have no field `userLocale`
|
||||
* For `Java` there is `User#javaLocale` extension function, which will give an old locale work way
|
||||
|
||||
### 0.20.1
|
||||
|
||||
* `User` now implement `PrivateChat`
|
||||
* `TextMentionMessageEntity` now accept `PrivateChat` instead of `User` in main constructor
|
||||
* `TextMentionMessageEntity` now contains not user, but contains `PrivateChat`
|
||||
* Fixed: `TextMentionMessageEntity#asHtmlSource` previously worked incorrect
|
||||
* Abstraction `TextSource`
|
||||
* `MessageEntity` now extends `TextSource`
|
||||
* `createFormattedText` method now accept `List<TextSource>`
|
||||
* `createHtmlText` method now accept `List<TextSource>`
|
||||
* `createMarkdownText` method now accept `List<TextSource>`
|
||||
* A lot of `TextSource` implementors was added. More info [here](src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/MessageEntity/textsources/)
|
||||
* All `MessageEntity` implementations now are using new `TextSource` analogues as delegates
|
||||
|
||||
### 0.20.2
|
||||
|
||||
* New exception type `MessageIsNotModifierException` was added
|
||||
* New exception type `MessageToEditNotFoundException` was added
|
||||
* Now exceptions in requests will be caught correctly
|
||||
|
||||
### 0.20.3
|
||||
|
||||
* Now `LeftChatMamber` is a `CommonEvent`
|
||||
|
||||
### 0.20.4
|
||||
|
||||
* Now `setWebhook` supports setting up of path for listening
|
||||
* Now `setWebhook` supports custom listen address even if certificate was not provided
|
||||
|
||||
## 0.19.0 ImplicitReflection removing
|
||||
|
||||
* Total rework of serialization for requests. Now all `SimpleRequest` children have:
|
||||
* `requestSerializer` - field, which must provide serializer of current type
|
||||
* `resultDeserializer` - field, which must provide opportunity to deserializer result. Previously it was a function
|
||||
* Removed deprecations:
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.WebhookPrivateKeyConfig`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.UpdatesFilter`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.utils.extensions.createSimpleUpdateFilter`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.utils.createMarkdownText`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.utils.toMarkdownCaption`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.utils.toMarkdownText`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.updateshandlers.KtorUpdatesPoller`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.CaptionedMediaContent`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.types.message.CommonForwardedMessage`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.CaptionedInputMedia`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.types.games.Game#text`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.types.games.Game#textEntities`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.types.files.PathedFileKt.makeFileUrl`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.types.files.PathedFileKt.downloadingFilesBaseUrl`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.requests.send.media.base.Data`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ByInlineMessageId`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ByMessageId`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.bot.RequestException`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.ReplyMessageNotFound`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.bot.BaseRequestsExecutor#baseUrl`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.bot.BaseRequestsExecutor#constructor(token, hostUrl)`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.KtorRequestsExecutor#constructor(token, client, hostUrl, callsFactories, excludeDefaultFactories, requestsLimiter, jsonFormatter)`
|
||||
* `com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.KtorRequestsExecutor#constructor(token, engine, hostUrl)`
|
||||
|
||||
## 0.18.0 Raws cleaning
|
||||
|
||||
* Made internal and not available outside of library:
|
||||
|
||||
37
README.md
37
README.md
@@ -1,7 +1,7 @@
|
||||
# TelegramBotAPI
|
||||
|
||||
[ ](https://bintray.com/insanusmokrassar/StandardRepository/TelegramBotAPI/_latestVersion)
|
||||
[](https://jenkins.insanusmokrassar.space/job/TelegramBotAPI_master__publishing/)
|
||||
[](https://jenkins.insanusmokrassar.com/job/TelegramBotAPI_master__publishing/)
|
||||
|
||||
## What is it?
|
||||
|
||||
@@ -10,7 +10,7 @@ moments are describing by official [Telegram Bot API](https://core.telegram.org/
|
||||
|
||||
## Compatibility
|
||||
|
||||
This version compatible with [29th of July 2019 update of TelegramBotAPI](https://core.telegram.org/bots/api#july-29-2019).
|
||||
This version compatible with [31th of December 2019 update of TelegramBotAPI (version 4.5)](https://core.telegram.org/bots/api#december-31-2019).
|
||||
There is Telegram Passport API exception of implemented functionality, which was presented in
|
||||
[August 2018 update of TelegramBotAPI](https://core.telegram.org/bots/api#august-27-2018) update. It will be implemented
|
||||
as soon as possible. All APIs that are not included are presented
|
||||
@@ -25,8 +25,17 @@ like inserting of additional libraries (like `kotlin stdlib`). In the examples w
|
||||
|
||||
[ ](https://bintray.com/insanusmokrassar/StandardRepository/TelegramBotAPI/_latestVersion)
|
||||
|
||||
Currently, last versions of library are not included into the Maven repository (for the reason difficult in publishing
|
||||
of signed artifacts in Bintray). You can:
|
||||
|
||||
* Use earlier version (available version you can find
|
||||
[here](https://mvnrepository.com/artifact/com.github.insanusmokrassar/TelegramBotAPI))
|
||||
* Add `jCenter` repository in build config
|
||||
|
||||
### Maven
|
||||
|
||||
Dependency config presented here:
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>com.github.insanusmokrassar</groupId>
|
||||
@@ -37,14 +46,20 @@ like inserting of additional libraries (like `kotlin stdlib`). In the examples w
|
||||
|
||||
### Gradle
|
||||
|
||||
To use last versions you will need to add one line in repositories block of your `build.gradle`:
|
||||
|
||||
`jcenter()` or `mavenCentral()`
|
||||
|
||||
And add next line to your dependencies block:
|
||||
|
||||
```groovy
|
||||
implementation "com.github.insanusmokrassar:TelegramBotAPI:${telegrambotapi.version}"
|
||||
implementation "com.github.insanusmokrassar:TelegramBotAPI:$telegrambotapi_version"
|
||||
```
|
||||
|
||||
### Gradle (old)
|
||||
or for old gradle:
|
||||
|
||||
```groovy
|
||||
compile "com.github.insanusmokrassar:TelegramBotAPI:${telegrambotapi.version}"
|
||||
compile "com.github.insanusmokrassar:TelegramBotAPI:$telegrambotapi_version"
|
||||
```
|
||||
|
||||
## How to work with library?
|
||||
@@ -52,9 +67,9 @@ compile "com.github.insanusmokrassar:TelegramBotAPI:${telegrambotapi.version}"
|
||||
For now, this library have no some API god-object. Instead of this, this library has several
|
||||
important objects:
|
||||
|
||||
* [RequestsExecutor](src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/RequestsExecutor.kt)
|
||||
* [Requests](src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests)
|
||||
* [Types](src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types)
|
||||
* [RequestsExecutor](https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/RequestsExecutor.kt)
|
||||
* [Requests](https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests)
|
||||
* [Types](https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types)
|
||||
|
||||
### Types
|
||||
|
||||
@@ -81,8 +96,8 @@ val requestsExecutor: RequestsExecutor = ...
|
||||
requestsExecutor.execute(GetMe())
|
||||
```
|
||||
|
||||
The result type of [GetMe](src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetMe) request is
|
||||
[User](src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/User). In fact, in this result must contain
|
||||
The result type of [GetMe](https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetMe.kt) request is
|
||||
[User](https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/User.kt). In fact, in this result must contain
|
||||
`isBot` equal to `true` always.
|
||||
|
||||
|
||||
@@ -173,6 +188,6 @@ Here:
|
||||
|
||||
* `WEBHOOK_URL` - the url which will be used by Telegram system to send updates
|
||||
* `INTERNAL_PORT` - the port which will be used in bot for listening of updates
|
||||
* `filter` - instance of [UpdatesFilter](src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/utils/extensions/UpdatesFilter.kt),
|
||||
* `filter` - instance of [UpdatesFilter](https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/updateshandlers/UpdatesFilter.kt),
|
||||
which will be used to filter incoming updates
|
||||
* `ENGINE_FACTORY` - used factory name, for example, `CIO` in case of usage `io.ktor:ktor-server-cio` as server engine
|
||||
|
||||
1
_config.yml
Normal file
1
_config.yml
Normal file
@@ -0,0 +1 @@
|
||||
theme: jekyll-theme-cayman
|
||||
71
build.gradle
71
build.gradle
@@ -1,6 +1,3 @@
|
||||
project.version = "0.18.1"
|
||||
project.group = "com.github.insanusmokrassar"
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
@@ -15,9 +12,13 @@ buildscript {
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'java-library'
|
||||
apply plugin: 'kotlin'
|
||||
apply plugin: 'kotlinx-serialization'
|
||||
plugins {
|
||||
id "org.jetbrains.kotlin.multiplatform" version "$kotlin_version"
|
||||
id "org.jetbrains.kotlin.plugin.serialization" version "$kotlin_version"
|
||||
}
|
||||
|
||||
project.version = "0.22.0"
|
||||
project.group = "com.github.insanusmokrassar"
|
||||
|
||||
apply from: "publish.gradle"
|
||||
|
||||
@@ -28,23 +29,53 @@ repositories {
|
||||
maven { url "https://kotlin.bintray.com/kotlinx" }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
|
||||
api "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$kotlin_serialisation_runtime_version"
|
||||
api "joda-time:joda-time:$joda_time_version"
|
||||
kotlin {
|
||||
jvm()
|
||||
js()
|
||||
|
||||
api "io.ktor:ktor-client:$ktor_version"
|
||||
api "io.ktor:ktor-client-cio:$ktor_version"
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
implementation kotlin('stdlib')
|
||||
api "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$kotlin_coroutines_version"
|
||||
api "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$kotlin_serialisation_runtime_version"
|
||||
|
||||
api "io.ktor:ktor-server:$ktor_version"
|
||||
api "io.ktor:ktor-server-host-common:$ktor_version"
|
||||
api "com.soywiz.korlibs.klock:klock:$klock_version"
|
||||
api "com.benasher44:uuid:$uuid_version"
|
||||
|
||||
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
|
||||
}
|
||||
api "io.ktor:ktor-client-core:$ktor_version"
|
||||
}
|
||||
}
|
||||
commonTest {
|
||||
dependencies {
|
||||
implementation kotlin('test-common')
|
||||
implementation kotlin('test-annotations-common')
|
||||
}
|
||||
}
|
||||
|
||||
compileKotlin {
|
||||
kotlinOptions {
|
||||
freeCompilerArgs = [ disableImplicitReflectionSerializerAnnotation ]
|
||||
jvmMain {
|
||||
dependencies {
|
||||
api "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$kotlin_serialisation_runtime_version"
|
||||
|
||||
api "io.ktor:ktor-client:$ktor_version"
|
||||
api "io.ktor:ktor-server:$ktor_version"
|
||||
|
||||
api "io.ktor:ktor-server-host-common:$ktor_version"
|
||||
api "io.ktor:ktor-client-cio:$ktor_version"
|
||||
}
|
||||
}
|
||||
jvmTest {
|
||||
dependencies {
|
||||
implementation kotlin('test-junit')
|
||||
}
|
||||
}
|
||||
|
||||
jsMain {
|
||||
dependencies {
|
||||
api "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$kotlin_serialisation_runtime_version"
|
||||
api "org.jetbrains.kotlinx:kotlinx-coroutines-core-js:$kotlin_coroutines_version"
|
||||
api "io.ktor:ktor-client-js:$ktor_version"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
kotlin.code.style=official
|
||||
kotlin_version=1.3.61
|
||||
kotlin_coroutines_version=1.3.2
|
||||
kotlin_coroutines_version=1.3.3
|
||||
kotlin_serialisation_runtime_version=0.14.0
|
||||
joda_time_version=2.10.5
|
||||
ktor_version=1.2.6
|
||||
klock_version=1.8.6
|
||||
uuid_version=0.0.7
|
||||
ktor_version=1.3.0
|
||||
|
||||
gradle_bintray_plugin_version=1.8.4
|
||||
|
||||
project_public_name=Telegram Bot API
|
||||
project_public_description=Library for Object-Oriented and type-safe work with Telegram Bot API
|
||||
|
||||
disableImplicitReflectionSerializerAnnotation=-Xexperimental=kotlinx.serialization.ImplicitReflectionSerializer
|
||||
|
||||
@@ -1,63 +1,57 @@
|
||||
apply plugin: 'maven-publish'
|
||||
apply plugin: 'signing'
|
||||
|
||||
task sourcesJar(type: Jar) {
|
||||
from sourceSets.main.allSource
|
||||
classifier = 'sources'
|
||||
}
|
||||
|
||||
task javadocJar(type: Jar) {
|
||||
from javadoc
|
||||
task javadocsJar(type: Jar) {
|
||||
classifier = 'javadoc'
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
maven(MavenPublication) {
|
||||
from components.java
|
||||
groupId "${project.group}"
|
||||
artifactId "${project.name}"
|
||||
version "${project.version}"
|
||||
|
||||
artifact sourcesJar
|
||||
artifact javadocJar
|
||||
|
||||
pom.withXml {
|
||||
asNode().children().last() + {
|
||||
resolveStrategy = Closure.DELEGATE_FIRST
|
||||
name "${project_public_name}"
|
||||
description "${project_public_description}"
|
||||
url "https://insanusmokrassar.github.io/${project.name}"
|
||||
|
||||
scm {
|
||||
connection "scm:git:git://github.com/insanusmokrassar/${project.name}.git"
|
||||
developerConnection "scm:git:[fetch=]https://github.com/insanusmokrassar/${project.name}.git[push=]ssh:git@github.com:insanusmokrassar/${project.name}.git"
|
||||
url "https://github.com/insanusmokrassar/${project.name}"
|
||||
|
||||
}
|
||||
|
||||
developers {
|
||||
developer {
|
||||
id "InsanusMokrassar"
|
||||
name "Ovsyannikov Alexey"
|
||||
email "ovsyannikov.alexey95@gmail.com"
|
||||
}
|
||||
}
|
||||
|
||||
licenses {
|
||||
license {
|
||||
name 'The Apache Software License, Version 2.0'
|
||||
url 'https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/LICENSE'
|
||||
distribution 'repo'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
afterEvaluate {
|
||||
project.publishing.publications.all {
|
||||
// rename artifacts
|
||||
groupId "${project.group}"
|
||||
if (it.name.contains('kotlinMultiplatform')) {
|
||||
artifactId = "${project.name}"
|
||||
} else {
|
||||
artifactId = "${project.name}-$name"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
signing {
|
||||
useGpgCmd()
|
||||
sign publishing.publications.maven
|
||||
}
|
||||
publishing {
|
||||
publications.all {
|
||||
artifact javadocsJar
|
||||
|
||||
pom.withXml {
|
||||
asNode().children().last() + {
|
||||
resolveStrategy = Closure.DELEGATE_FIRST
|
||||
|
||||
description "Library for Object-Oriented and type-safe work with Telegram Bot API"
|
||||
name "Telegram Bot API"
|
||||
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"
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1
mpp_publish_template.json
Normal file
1
mpp_publish_template.json
Normal file
@@ -0,0 +1 @@
|
||||
{"bintrayConfig":{"repo":"StandardRepository","packageName":"${project.name}","packageVcs":"https://github.com/InsanusMokrassar/TelegramBotAPI"},"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","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","developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"}]}}
|
||||
@@ -1,33 +1,52 @@
|
||||
apply plugin: 'com.jfrog.bintray'
|
||||
|
||||
ext {
|
||||
projectBintrayDir = "${project.group}/".replace(".", "/") + "${project.name}/${project.version}"
|
||||
}
|
||||
apply from: "maven.publish.gradle"
|
||||
|
||||
bintray {
|
||||
user = project.hasProperty('BINTRAY_USER') ? project.property('BINTRAY_USER') : System.getenv('BINTRAY_USER')
|
||||
key = project.hasProperty('BINTRAY_KEY') ? project.property('BINTRAY_KEY') : System.getenv('BINTRAY_KEY')
|
||||
publications = ["maven"]
|
||||
filesSpec {
|
||||
into "$projectBintrayDir"
|
||||
from("build/libs") {
|
||||
include "**/*.asc"
|
||||
}
|
||||
from("build/publications/maven") {
|
||||
rename 'pom-default.xml(.*)', "${project.name}-${project.version}.pom\$1"
|
||||
from "${buildDir}/publications/"
|
||||
eachFile {
|
||||
if (it.getName() == "module.json") {
|
||||
File file = it.getFile()
|
||||
String directorySubname = file.parentFile.name
|
||||
if (directorySubname == "kotlinMultiplatform") {
|
||||
it.setPath("${project.name}/${project.version}/${project.name}-${project.version}.module")
|
||||
} else {
|
||||
it.setPath("${project.name}-${directorySubname}/${project.version}/${project.name}-${directorySubname}-${project.version}.module")
|
||||
}
|
||||
} else {
|
||||
it.exclude()
|
||||
}
|
||||
}
|
||||
into "${project.group}".replace(".", "/")
|
||||
}
|
||||
pkg {
|
||||
repo = 'StandardRepository'
|
||||
repo = "StandardRepository"
|
||||
name = "${project.name}"
|
||||
vcsUrl = "https://github.com/InsanusMokrassar/${project.name}"
|
||||
licenses = ['Apache-2.0']
|
||||
vcsUrl = "https://github.com/InsanusMokrassar/TelegramBotAPI"
|
||||
licenses = ["Apache-2.0"]
|
||||
version {
|
||||
name = "${project.version}"
|
||||
released = new Date()
|
||||
vcsTag = name
|
||||
vcsTag = "${project.version}"
|
||||
gpg {
|
||||
sign = true
|
||||
passphrase = project.hasProperty('signing.gnupg.passphrase') ? project.property('signing.gnupg.passphrase') : System.getenv('signing.gnupg.passphrase')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
apply from: "maven.publish.gradle"
|
||||
bintrayUpload.doFirst {
|
||||
publications = publishing.publications.collect {
|
||||
if (it.name.contains('kotlinMultiplatform')) {
|
||||
null
|
||||
} else {
|
||||
it.name
|
||||
}
|
||||
} - null
|
||||
}
|
||||
|
||||
bintrayUpload.dependsOn publishToMavenLocal
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.MessageEntity
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.fullListOfSubSource
|
||||
|
||||
interface Captioned {
|
||||
val caption: String?
|
||||
@@ -12,5 +12,7 @@ interface CaptionedOutput : Captioned {
|
||||
}
|
||||
|
||||
interface CaptionedInput : Captioned {
|
||||
val captionEntities: List<MessageEntity>
|
||||
val captionEntities: List<TextPart>
|
||||
}
|
||||
|
||||
fun CaptionedInput.fullEntitiesList() = caption ?.fullListOfSubSource(captionEntities) ?.map { it.source } ?: emptyList()
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts
|
||||
|
||||
interface TextSource {
|
||||
val asMarkdownSource: String
|
||||
val asMarkdownV2Source: String
|
||||
val asHtmlSource: String
|
||||
}
|
||||
|
||||
|
||||
interface MultilevelTextSource : TextSource {
|
||||
val textParts: List<TextPart>
|
||||
}
|
||||
|
||||
data class TextPart(
|
||||
val range: IntRange,
|
||||
val source: TextSource
|
||||
)
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.bot
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.TelegramAPIUrlsKeeper
|
||||
|
||||
abstract class BaseRequestsExecutor(
|
||||
protected val telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper
|
||||
) : RequestsExecutor
|
||||
@@ -3,11 +3,12 @@ package com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.call.HttpClientCall
|
||||
import io.ktor.client.statement.HttpStatement
|
||||
|
||||
interface KtorCallFactory {
|
||||
suspend fun <T: Any> prepareCall(
|
||||
client: HttpClient,
|
||||
baseUrl: String,
|
||||
request: Request<T>
|
||||
) : HttpClientCall?
|
||||
) : HttpStatement?
|
||||
}
|
||||
@@ -11,9 +11,10 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.Response
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.RetryAfterError
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.TelegramAPIUrlsKeeper
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.call.HttpClientCall
|
||||
import io.ktor.client.engine.HttpClientEngine
|
||||
import io.ktor.util.cio.toByteArray
|
||||
import io.ktor.client.call.receive
|
||||
import io.ktor.client.features.ClientRequestException
|
||||
import io.ktor.client.statement.HttpStatement
|
||||
import io.ktor.client.statement.readText
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
@@ -25,28 +26,6 @@ class KtorRequestsExecutor(
|
||||
private val requestsLimiter: RequestLimiter = EmptyLimiter,
|
||||
private val jsonFormatter: Json = Json.nonstrict
|
||||
) : BaseRequestsExecutor(telegramAPIUrlsKeeper) {
|
||||
|
||||
@Deprecated("Deprecated due to new TelegramAPIUrlKeeper API")
|
||||
constructor(
|
||||
token: String,
|
||||
client: HttpClient = HttpClient(),
|
||||
hostUrl: String = "https://api.telegram.org",
|
||||
callsFactories: List<KtorCallFactory> = emptyList(),
|
||||
excludeDefaultFactories: Boolean = false,
|
||||
requestsLimiter: RequestLimiter = EmptyLimiter,
|
||||
jsonFormatter: Json = Json.nonstrict
|
||||
) : this(TelegramAPIUrlsKeeper(token, hostUrl), client, callsFactories, excludeDefaultFactories, requestsLimiter, jsonFormatter)
|
||||
|
||||
@Deprecated("Deprecated due to new TelegramAPIUrlKeeper API")
|
||||
constructor(
|
||||
token: String,
|
||||
engine: HttpClientEngine? = null,
|
||||
hostUrl: String = "https://api.telegram.org"
|
||||
) : this(
|
||||
TelegramAPIUrlsKeeper(token, hostUrl),
|
||||
engine ?.let { HttpClient(engine) } ?: HttpClient()
|
||||
)
|
||||
|
||||
private val callsFactories: List<KtorCallFactory> = callsFactories.run {
|
||||
if (!excludeDefaultFactories) {
|
||||
asSequence().plus(SimpleRequestCallFactory()).plus(MultipartRequestCallFactory()).toList()
|
||||
@@ -57,42 +36,48 @@ class KtorRequestsExecutor(
|
||||
|
||||
override suspend fun <T : Any> execute(request: Request<T>): T {
|
||||
return requestsLimiter.limit {
|
||||
var call: HttpClientCall? = null
|
||||
var statement: HttpStatement? = null
|
||||
for (factory in callsFactories) {
|
||||
call = factory.prepareCall(
|
||||
statement = factory.prepareCall(
|
||||
client,
|
||||
telegramAPIUrlsKeeper.commonAPIUrl,
|
||||
request
|
||||
)
|
||||
if (call != null) {
|
||||
if (statement != null) {
|
||||
break
|
||||
}
|
||||
}
|
||||
if (call == null) {
|
||||
throw IllegalArgumentException("Can't execute request: $request")
|
||||
}
|
||||
val content = call.response.use {
|
||||
it.content.toByteArray().toString(Charsets.UTF_8)
|
||||
}
|
||||
val responseObject = jsonFormatter.parse(Response.serializer(), content)
|
||||
try {
|
||||
val response = statement ?.execute() ?: throw IllegalArgumentException("Can't execute request: $request")
|
||||
val content = response.receive<String>()
|
||||
val responseObject = jsonFormatter.parse(Response.serializer(), content)
|
||||
|
||||
(responseObject.result ?.let {
|
||||
jsonFormatter.fromJson(request.resultDeserializer(), it)
|
||||
} ?: responseObject.parameters ?.let {
|
||||
val error = it.error
|
||||
if (error is RetryAfterError) {
|
||||
delay(error.leftToRetry)
|
||||
execute(request)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
} ?: call.let {
|
||||
(responseObject.result?.let {
|
||||
jsonFormatter.fromJson(request.resultDeserializer, it)
|
||||
} ?: responseObject.parameters?.let {
|
||||
val error = it.error
|
||||
if (error is RetryAfterError) {
|
||||
delay(error.leftToRetry)
|
||||
execute(request)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
} ?: response.let {
|
||||
throw newRequestException(
|
||||
responseObject,
|
||||
content,
|
||||
"Can't get result object from $content"
|
||||
)
|
||||
})
|
||||
} catch (e: ClientRequestException) {
|
||||
val content = e.response.readText()
|
||||
val responseObject = jsonFormatter.parse(Response.serializer(), content)
|
||||
throw newRequestException(
|
||||
responseObject,
|
||||
content,
|
||||
"Can't get result object from $content"
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,11 +4,11 @@ import com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.KtorCallFactory
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.call.HttpClientCall
|
||||
import io.ktor.client.call.call
|
||||
import io.ktor.client.request.accept
|
||||
import io.ktor.client.request.url
|
||||
import io.ktor.client.request.*
|
||||
import io.ktor.client.statement.HttpStatement
|
||||
import io.ktor.http.ContentType
|
||||
import io.ktor.http.HttpMethod
|
||||
import kotlin.collections.set
|
||||
|
||||
abstract class AbstractRequestCallFactory : KtorCallFactory {
|
||||
private val methodsCache: MutableMap<String, String> = mutableMapOf()
|
||||
@@ -16,20 +16,23 @@ abstract class AbstractRequestCallFactory : KtorCallFactory {
|
||||
client: HttpClient,
|
||||
baseUrl: String,
|
||||
request: Request<T>
|
||||
): HttpClientCall? {
|
||||
): HttpStatement? {
|
||||
val preparedBody = prepareCallBody(client, baseUrl, request) ?: return null
|
||||
|
||||
return client.call {
|
||||
url(
|
||||
methodsCache[request.method()] ?: "$baseUrl/${request.method()}".also {
|
||||
methodsCache[request.method()] = it
|
||||
}
|
||||
)
|
||||
method = HttpMethod.Post
|
||||
accept(ContentType.Application.Json)
|
||||
return HttpStatement(
|
||||
HttpRequestBuilder().apply {
|
||||
url(
|
||||
methodsCache[request.method()] ?: "$baseUrl/${request.method()}".also {
|
||||
methodsCache[request.method()] = it
|
||||
}
|
||||
)
|
||||
method = HttpMethod.Post
|
||||
accept(ContentType.Application.Json)
|
||||
|
||||
body = preparedBody
|
||||
}
|
||||
body = preparedBody
|
||||
},
|
||||
client
|
||||
)
|
||||
}
|
||||
|
||||
protected abstract fun <T : Any> prepareCallBody(
|
||||
@@ -7,7 +7,6 @@ import io.ktor.client.request.forms.MultiPartFormDataContent
|
||||
import io.ktor.client.request.forms.formData
|
||||
import io.ktor.http.Headers
|
||||
import io.ktor.http.HttpHeaders
|
||||
import kotlinx.io.core.readBytes
|
||||
|
||||
class MultipartRequestCallFactory : AbstractRequestCallFactory() {
|
||||
|
||||
@@ -21,14 +20,15 @@ class MultipartRequestCallFactory : AbstractRequestCallFactory() {
|
||||
val params = castedRequest.paramsJson.mapWithCommonValues()
|
||||
for ((key, value) in castedRequest.mediaMap + params) {
|
||||
when (value) {
|
||||
is MultipartFile -> append(
|
||||
is MultipartFile -> appendInput(
|
||||
key,
|
||||
value.file.asInput().readBytes(),
|
||||
Headers.build {
|
||||
append(HttpHeaders.ContentType, value.mimeType)
|
||||
append(HttpHeaders.ContentDisposition, "filename=${value.fileId}")
|
||||
}
|
||||
)
|
||||
) {
|
||||
value.file.asInput()
|
||||
}
|
||||
is FileId -> append(key, value.fileId)
|
||||
else -> append(key, value.toString())
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.bot.Ktor.base
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.toJsonWithoutNulls
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.http.ContentType
|
||||
import io.ktor.http.content.TextContent
|
||||
@@ -12,12 +11,11 @@ class SimpleRequestCallFactory : AbstractRequestCallFactory() {
|
||||
baseUrl: String,
|
||||
request: Request<T>
|
||||
): Any? = (request as? SimpleRequest<T>) ?.let { _ ->
|
||||
val content = request.toJsonWithoutNulls(SimpleRequestSerializer).toString()
|
||||
val content = request.json().toString()
|
||||
|
||||
TextContent(
|
||||
content,
|
||||
ContentType.Application.Json
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.bot
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.RequestException
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request
|
||||
import kotlinx.io.core.Closeable
|
||||
import io.ktor.utils.io.core.Closeable
|
||||
|
||||
interface RequestsExecutor : Closeable {
|
||||
@Throws(RequestException::class)
|
||||
/**
|
||||
* @throws com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.RequestException
|
||||
*/
|
||||
suspend fun <T : Any> execute(request: Request<T>): T
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.bot
|
||||
|
||||
import io.ktor.utils.io.core.Closeable
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.io.core.Closeable
|
||||
|
||||
interface UpdatesPoller : Closeable {
|
||||
fun start(scope: CoroutineScope = CoroutineScope(Dispatchers.Default))
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.Response
|
||||
import kotlinx.io.IOException
|
||||
|
||||
fun newRequestException(
|
||||
response: Response,
|
||||
plainAnswer: String,
|
||||
message: String? = null,
|
||||
cause: Throwable? = null
|
||||
) = response.description ?.let { description ->
|
||||
when {
|
||||
description == "Bad Request: reply message not found" -> ReplyMessageNotFoundException(response, plainAnswer, message, cause)
|
||||
description == "Bad Request: message to edit not found" -> MessageToEditNotFoundException(response, plainAnswer, message, cause)
|
||||
description.contains("Bad Request: message is not modified") -> MessageIsNotModifiedException(response, plainAnswer, message, cause)
|
||||
description == "Unauthorized" -> UnauthorizedException(response, plainAnswer, message, cause)
|
||||
else -> null
|
||||
}
|
||||
} ?: CommonRequestException(response, plainAnswer, message, cause)
|
||||
|
||||
sealed class RequestException constructor(
|
||||
val response: Response,
|
||||
val plainAnswer: String,
|
||||
message: String? = null,
|
||||
override val cause: Throwable? = null
|
||||
) : IOException(
|
||||
message ?: "Something went wrong"
|
||||
)
|
||||
|
||||
class CommonRequestException(response: Response, plainAnswer: String, message: String?, cause: Throwable?) :
|
||||
RequestException(response, plainAnswer, message, cause)
|
||||
|
||||
class UnauthorizedException(response: Response, plainAnswer: String, message: String?, cause: Throwable?) :
|
||||
RequestException(response, plainAnswer, message, cause)
|
||||
|
||||
class ReplyMessageNotFoundException(response: Response, plainAnswer: String, message: String?, cause: Throwable?) :
|
||||
RequestException(response, plainAnswer, message, cause)
|
||||
|
||||
class MessageIsNotModifiedException(response: Response, plainAnswer: String, message: String?, cause: Throwable?) :
|
||||
RequestException(response, plainAnswer, message, cause)
|
||||
|
||||
class MessageToEditNotFoundException(response: Response, plainAnswer: String, message: String?, cause: Throwable?) :
|
||||
RequestException(response, plainAnswer, message, cause)
|
||||
@@ -1,9 +1,10 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.bot.settings.limiters
|
||||
|
||||
import com.soywiz.klock.DateTime
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
|
||||
private fun now(): Long = System.currentTimeMillis()
|
||||
private fun now(): Long = DateTime.nowUnixLong()
|
||||
|
||||
class CommonLimiter(
|
||||
private val lockCount: Int = 10,
|
||||
@@ -4,8 +4,8 @@ import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.Transient
|
||||
import java.util.concurrent.Executors
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.math.pow
|
||||
|
||||
private sealed class RequestEvent
|
||||
private class AddRequest(
|
||||
@@ -21,9 +21,7 @@ data class PowLimiter(
|
||||
private val powK: Double = 0.0016
|
||||
) : RequestLimiter {
|
||||
@Transient
|
||||
private val scope = CoroutineScope(
|
||||
Executors.newFixedThreadPool(3).asCoroutineDispatcher()
|
||||
)
|
||||
private val scope = CoroutineScope(Dispatchers.Default)
|
||||
@Transient
|
||||
private val eventsChannel = Channel<RequestEvent>(Channel.UNLIMITED)
|
||||
@Transient
|
||||
@@ -35,7 +33,7 @@ data class PowLimiter(
|
||||
for (event in eventsChannel) {
|
||||
when (event) {
|
||||
is AddRequest -> {
|
||||
val awaitTime = ((Math.pow(requestsInWork, powValue) * powK) * 1000L).toLong()
|
||||
val awaitTime = (((requestsInWork.pow(powValue) * powK) * 1000L).toLong())
|
||||
requestsInWork++
|
||||
|
||||
event.continuation.resume(
|
||||
@@ -15,5 +15,8 @@ data class DeleteMessage(
|
||||
) : SimpleRequest<Boolean>, MessageAction {
|
||||
override fun method(): String = "deleteMessage"
|
||||
|
||||
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -3,10 +3,11 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
|
||||
import kotlinx.serialization.*
|
||||
|
||||
private val AbleToBeForwardedMessageDeserializer = TelegramBotAPIMessageDeserializationStrategyClass<PossiblyForwardedMessage>()
|
||||
|
||||
@Serializable
|
||||
data class ForwardMessage(
|
||||
@SerialName(fromChatIdField)
|
||||
@@ -17,12 +18,14 @@ data class ForwardMessage(
|
||||
override val messageId: MessageIdentifier,
|
||||
@SerialName(disableNotificationField)
|
||||
val disableNotification: Boolean = false
|
||||
): SimpleRequest<Message>, MessageAction {
|
||||
@Transient
|
||||
): SimpleRequest<PossiblyForwardedMessage>, MessageAction {
|
||||
override val chatId: ChatIdentifier
|
||||
get() = fromChatId
|
||||
|
||||
override fun method(): String = "forwardMessage"
|
||||
|
||||
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
|
||||
override val resultDeserializer: DeserializationStrategy<PossiblyForwardedMessage>
|
||||
get() = AbleToBeForwardedMessageDeserializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -2,11 +2,13 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.User
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
class GetMe : SimpleRequest<User> {
|
||||
override fun method(): String = "getMe"
|
||||
override fun resultDeserializer(): KSerializer<User> = User.serializer()
|
||||
override val resultDeserializer: DeserializationStrategy<User>
|
||||
get() = User.serializer()
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -5,10 +5,13 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.ALL_UPDATES_LIST
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.UpdateIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.UpdateSerializerWithoutDeserialization
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.ArrayListSerializer
|
||||
|
||||
private val updatesListSerializer = ArrayListSerializer(
|
||||
UpdateSerializerWithoutDeserialization
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class GetUpdates(
|
||||
val offset: UpdateIdentifier? = null,// set `last update id + 1` to receive next part of updates
|
||||
@@ -18,7 +21,9 @@ data class GetUpdates(
|
||||
): SimpleRequest<List<Update>> {
|
||||
override fun method(): String = "getUpdates"
|
||||
|
||||
override fun resultDeserializer(): KSerializer<List<Update>> = ArrayListSerializer(
|
||||
UpdateSerializerWithoutDeserialization
|
||||
)
|
||||
override val resultDeserializer: DeserializationStrategy<List<Update>>
|
||||
get() = updatesListSerializer
|
||||
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -18,5 +18,8 @@ data class StopPoll(
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : MessageAction, SimpleRequest<Poll>, ReplyMarkup {
|
||||
override fun method(): String = "stopPoll"
|
||||
override fun resultDeserializer(): KSerializer<Poll> = Poll.serializer()
|
||||
override val resultDeserializer: DeserializationStrategy<Poll>
|
||||
get() = Poll.serializer()
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.StorageFile
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.StringDescriptor
|
||||
import java.io.File
|
||||
|
||||
@Serializable(InputFileSerializer::class)
|
||||
sealed class InputFile {
|
||||
@@ -22,7 +21,7 @@ data class FileId(
|
||||
fun String.toInputFile(): InputFile = FileId(this)
|
||||
|
||||
@Serializer(InputFile::class)
|
||||
object InputFileSerializer : KSerializer<InputFile> {
|
||||
internal object InputFileSerializer : KSerializer<InputFile> {
|
||||
override val descriptor: SerialDescriptor = StringDescriptor.withName(FileId::class.toString())
|
||||
override fun serialize(encoder: Encoder, obj: InputFile) = encoder.encodeString(obj.fileId)
|
||||
override fun deserialize(decoder: Decoder): FileId = FileId(decoder.decodeString())
|
||||
@@ -40,7 +39,3 @@ data class MultipartFile (
|
||||
) : InputFile() {
|
||||
override val fileId: String = file.generateCustomName()
|
||||
}
|
||||
|
||||
fun File.toInputFile(): InputFile = MultipartFile(
|
||||
StorageFile(this)
|
||||
)
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts
|
||||
|
||||
import kotlinx.serialization.DeserializationStrategy
|
||||
|
||||
interface Request<T: Any> {
|
||||
fun method(): String
|
||||
val resultDeserializer: DeserializationStrategy<T>
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.utils.toJsonWithoutNulls
|
||||
import kotlinx.serialization.SerializationStrategy
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
|
||||
interface SimpleRequest<T: Any> : Request<T> {
|
||||
val requestSerializer: SerializationStrategy<*>
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
inline fun <T: Any, K: SimpleRequest<T>> K.json(): JsonObject = toJsonWithoutNulls(requestSerializer as SerializationStrategy<K>)
|
||||
@@ -20,7 +20,10 @@ data class AnswerCallbackQuery(
|
||||
val cachedTimeSeconds: Int? = null
|
||||
) : SimpleRequest<Boolean> {
|
||||
override fun method(): String = "answerCallbackQuery"
|
||||
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
fun CallbackQuery.createAnswer(
|
||||
@@ -28,7 +28,10 @@ data class AnswerInlineQuery(
|
||||
val switchPmParameter: String? = null
|
||||
): SimpleRequest<Boolean> {
|
||||
override fun method(): String = "answerInlineQuery"
|
||||
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
fun InlineQuery.createAnswer(
|
||||
@@ -48,6 +51,6 @@ fun InlineQuery.createAnswer(
|
||||
switchPmParameter
|
||||
)
|
||||
|
||||
object InlineQueryAnswersResultsSerializer: KSerializer<List<InlineQueryResult>> by ArrayListSerializer(
|
||||
internal object InlineQueryAnswersResultsSerializer: KSerializer<List<InlineQueryResult>> by ArrayListSerializer(
|
||||
InlineQueryResultSerializer
|
||||
)
|
||||
@@ -3,8 +3,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.answers.payments
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.answers.payments.abstracts.AnswerPreCheckoutQuery
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.payments.PreCheckoutQuery
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class AnswerPreCheckoutQueryOk(
|
||||
@@ -13,6 +12,8 @@ data class AnswerPreCheckoutQueryOk(
|
||||
) : AnswerPreCheckoutQuery {
|
||||
@SerialName(okField)
|
||||
override val isOk: Boolean = true
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +26,8 @@ data class AnswerPreCheckoutQueryError(
|
||||
) : AnswerPreCheckoutQuery {
|
||||
@SerialName(okField)
|
||||
override val isOk: Boolean = false
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
fun PreCheckoutQuery.createAnswerOk(): AnswerPreCheckoutQueryOk = AnswerPreCheckoutQueryOk(
|
||||
@@ -17,9 +17,11 @@ data class AnswerShippingQueryOk(
|
||||
) : AnswerShippingQuery {
|
||||
@SerialName(okField)
|
||||
override val isOk: Boolean = true
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
object ShippingOptionsSerializer : KSerializer<List<ShippingOption>> by ArrayListSerializer(
|
||||
internal object ShippingOptionsSerializer : KSerializer<List<ShippingOption>> by ArrayListSerializer(
|
||||
ShippingOption.serializer()
|
||||
)
|
||||
|
||||
@@ -32,6 +34,8 @@ data class AnswerShippingQueryError(
|
||||
) : AnswerShippingQuery {
|
||||
@SerialName(okField)
|
||||
override val isOk: Boolean = false
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
|
||||
fun ShippingQuery.createAnswerOk(
|
||||
@@ -3,11 +3,12 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.answers.payments.abs
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.PreCheckoutQueryId
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.serializer
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
|
||||
interface AnswerPreCheckoutQuery : SimpleRequest<Boolean> {
|
||||
override fun method(): String = "answerPreCheckoutQuery"
|
||||
override fun resultDeserializer(): KSerializer<Boolean> = Boolean.serializer()
|
||||
override val resultDeserializer: KSerializer<Boolean>
|
||||
get() = BooleanSerializer
|
||||
|
||||
val preCheckoutQueryId: PreCheckoutQueryId
|
||||
val isOk: Boolean
|
||||
@@ -2,12 +2,13 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.answers.payments.abs
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ShippingQueryIdentifier
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.serializer
|
||||
import kotlinx.serialization.DeserializationStrategy
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
|
||||
interface AnswerShippingQuery : SimpleRequest<Boolean> {
|
||||
override fun method(): String = "answerShippingQuery"
|
||||
override fun resultDeserializer(): KSerializer<Boolean> = Boolean.serializer()
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
|
||||
val shippingQueryId: ShippingQueryIdentifier
|
||||
val isOk: Boolean
|
||||
@@ -13,5 +13,8 @@ data class ExportChatInviteLink(
|
||||
override val chatId: ChatIdentifier
|
||||
): ChatRequest, SimpleRequest<String> {
|
||||
override fun method(): String = "exportChatInviteLink"
|
||||
override fun resultDeserializer(): KSerializer<String> = StringSerializer
|
||||
override val resultDeserializer: DeserializationStrategy<String>
|
||||
get() = StringSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -13,5 +13,8 @@ data class LeaveChat(
|
||||
override val chatId: ChatIdentifier
|
||||
): ChatRequest, SimpleRequest<Boolean> {
|
||||
override fun method(): String = "leaveChat"
|
||||
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -14,5 +14,8 @@ data class GetChat(
|
||||
override val chatId: ChatIdentifier
|
||||
): ChatRequest, SimpleRequest<ExtendedChat> {
|
||||
override fun method(): String = "getChat"
|
||||
override fun resultDeserializer(): KSerializer<ExtendedChat> = ExtendedChatSerializer
|
||||
override val resultDeserializer: DeserializationStrategy<ExtendedChat>
|
||||
get() = ExtendedChatSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -3,19 +3,23 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.get
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.ChatMember
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.ChatMemberSerializerWithoutDeserialization
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatMember.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.ArrayListSerializer
|
||||
|
||||
private val chatMembersListSerializer = ArrayListSerializer(
|
||||
AdministratorChatMemberSerializerWithoutDeserialization
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class GetChatAdministrators(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatIdentifier
|
||||
): ChatRequest, SimpleRequest<List<ChatMember>> {
|
||||
): ChatRequest, SimpleRequest<List<AdministratorChatMember>> {
|
||||
override fun method(): String = "getChatAdministrators"
|
||||
override fun resultDeserializer(): KSerializer<List<ChatMember>> = ArrayListSerializer(
|
||||
ChatMemberSerializerWithoutDeserialization
|
||||
)
|
||||
override val resultDeserializer: DeserializationStrategy<List<AdministratorChatMember>>
|
||||
get() = chatMembersListSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -13,5 +13,8 @@ data class GetChatMembersCount(
|
||||
override val chatId: ChatIdentifier
|
||||
): ChatRequest, SimpleRequest<Int> {
|
||||
override fun method(): String = "getChatMembersCount"
|
||||
override fun resultDeserializer(): KSerializer<Int> = IntSerializer
|
||||
override val resultDeserializer: DeserializationStrategy<Int>
|
||||
get() = IntSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -14,5 +14,8 @@ data class GetChatMember(
|
||||
override val userId: UserId
|
||||
) : ChatMemberRequest<ChatMember> {
|
||||
override fun method(): String = "getChatMember"
|
||||
override fun resultDeserializer(): DeserializationStrategy<ChatMember> = ChatMemberDeserializationStrategy
|
||||
override val resultDeserializer: DeserializationStrategy<ChatMember>
|
||||
get() = ChatMemberDeserializationStrategy
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -16,5 +16,8 @@ data class KickChatMember(
|
||||
override val untilDate: TelegramDate? = null
|
||||
) : ChatMemberRequest<Boolean>, UntilDate {
|
||||
override fun method(): String = "kickChatMember"
|
||||
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -32,5 +32,8 @@ data class PromoteChatMember(
|
||||
private val canPromoteMembers: Boolean? = null
|
||||
) : ChatMemberRequest<Boolean>, UntilDate {
|
||||
override fun method(): String = "promoteChatMember"
|
||||
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -19,5 +19,8 @@ data class RestrictChatMember(
|
||||
val permissions: ChatPermissions
|
||||
) : ChatMemberRequest<Boolean>, UntilDate {
|
||||
override fun method(): String = "restrictChatMember"
|
||||
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.members
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.chat.abstracts.ChatMemberRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
|
||||
/**
|
||||
* Representation of https://core.telegram.org/bots/api#setchatadministratorcustomtitle
|
||||
*
|
||||
* Please, remember about restrictions for characters in custom title
|
||||
*/
|
||||
@Serializable
|
||||
data class SetChatAdministratorCustomTitle(
|
||||
@SerialName(chatIdField)
|
||||
override val chatId: ChatId,
|
||||
@SerialName(userIdField)
|
||||
override val userId: UserId,
|
||||
@SerialName(customTitleField)
|
||||
val customTitle: String
|
||||
) : ChatMemberRequest<Boolean> {
|
||||
override fun method(): String = "setChatAdministratorCustomTitle"
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = RestrictChatMember.serializer()
|
||||
|
||||
init {
|
||||
if (customTitle.length !in customTitleLength) {
|
||||
throw IllegalArgumentException("Custom title length must be in range $customTitleLength, but was ${customTitle.length}")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,5 +13,8 @@ data class UnbanChatMember(
|
||||
override val userId: UserId
|
||||
) : ChatMemberRequest<Boolean> {
|
||||
override fun method(): String = "unbanChatMember"
|
||||
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -13,5 +13,8 @@ data class DeleteChatPhoto(
|
||||
override val chatId: ChatIdentifier
|
||||
): ChatRequest, SimpleRequest<Boolean> {
|
||||
override fun method(): String = "deleteChatPhoto"
|
||||
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -16,5 +16,8 @@ data class PinChatMessage (
|
||||
override val disableNotification: Boolean = false
|
||||
): ChatRequest, SimpleRequest<Boolean>, MessageAction, DisableNotification {
|
||||
override fun method(): String = "pinChatMessage"
|
||||
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -20,5 +20,8 @@ data class SetChatDescription (
|
||||
}
|
||||
|
||||
override fun method(): String = "setChatDescription"
|
||||
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -15,5 +15,8 @@ data class SetChatPermissions (
|
||||
val permissions: ChatPermissions
|
||||
): ChatRequest, SimpleRequest<Boolean> {
|
||||
override fun method(): String = "setChatPermissions"
|
||||
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -16,7 +16,8 @@ data class SetChatPhoto (
|
||||
val photo: MultipartFile = throw IllegalArgumentException("Unfortunately, this type of objects can't be parsed automatically")
|
||||
): ChatRequest, MultipartRequest<Boolean> {
|
||||
override fun method(): String = "setChatPhoto"
|
||||
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
override val mediaMap: Map<String, MultipartFile> = mapOf(photoField to photo)
|
||||
override val paramsJson: JsonObject = toJson(serializer())
|
||||
}
|
||||
@@ -20,5 +20,8 @@ data class SetChatTitle (
|
||||
}
|
||||
|
||||
override fun method(): String = "setChatTitle"
|
||||
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -13,5 +13,8 @@ data class UnpinChatMessage(
|
||||
override val chatId: ChatIdentifier
|
||||
): ChatRequest, SimpleRequest<Boolean> {
|
||||
override fun method(): String = "unpinChatMessage"
|
||||
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -13,5 +13,8 @@ data class DeleteChatStickerSet(
|
||||
override val chatId: ChatIdentifier
|
||||
): ChatRequest, SimpleRequest<Boolean> {
|
||||
override fun method(): String = "deleteChatStickerSet"
|
||||
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -14,5 +14,8 @@ data class SetChatStickerSet(
|
||||
val stickerSetName: StickerSetName
|
||||
): ChatRequest, SimpleRequest<Boolean> {
|
||||
override fun method(): String = "setChatStickerSet"
|
||||
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
|
||||
data class CommonMultipartFileRequest<T: Any>(
|
||||
val data: Request<T>,
|
||||
val data: SimpleRequest<T>,
|
||||
override val mediaMap: Map<String, MultipartFile>
|
||||
) : MultipartRequest<T>, Request<T> by data {
|
||||
override val paramsJson: JsonObject = data.json()
|
||||
@@ -3,10 +3,15 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.LiveLocation
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.LocationContent
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.TextContent
|
||||
import kotlinx.serialization.*
|
||||
|
||||
private val commonResultDeserializer = TelegramBotAPIMessageDeserializationStrategyClass<ContentMessage<LocationContent>>()
|
||||
|
||||
@Serializable
|
||||
data class EditChatMessageLiveLocation(
|
||||
@SerialName(chatIdField)
|
||||
@@ -19,7 +24,10 @@ data class EditChatMessageLiveLocation(
|
||||
override val longitude: Double,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditChatMessage, EditReplyMessage, EditLocationMessage {
|
||||
) : EditChatMessage<LocationContent>, EditReplyMessage, EditLocationMessage {
|
||||
override fun method(): String = "editMessageLiveLocation"
|
||||
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
|
||||
override val resultDeserializer: DeserializationStrategy<ContentMessage<LocationContent>>
|
||||
get() = commonResultDeserializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -3,8 +3,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.LiveLocation
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class EditInlineMessageLiveLocation(
|
||||
@@ -18,4 +17,6 @@ data class EditInlineMessageLiveLocation(
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditInlineMessage, EditReplyMessage, EditLocationMessage {
|
||||
override fun method(): String = "editMessageLiveLocation"
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -4,10 +4,14 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditCh
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditReplyMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.LocationContent
|
||||
import kotlinx.serialization.*
|
||||
|
||||
private val commonResultDeserializer = TelegramBotAPIMessageDeserializationStrategyClass<ContentMessage<LocationContent>>()
|
||||
|
||||
@Serializable
|
||||
data class StopChatMessageLiveLocation(
|
||||
@SerialName(chatIdField)
|
||||
@@ -16,7 +20,10 @@ data class StopChatMessageLiveLocation(
|
||||
override val messageId: MessageIdentifier,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditChatMessage, EditReplyMessage {
|
||||
) : EditChatMessage<LocationContent>, EditReplyMessage {
|
||||
override fun method(): String = "stopMessageLiveLocation"
|
||||
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
|
||||
override val resultDeserializer: DeserializationStrategy<ContentMessage<LocationContent>>
|
||||
get() = commonResultDeserializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -4,8 +4,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditIn
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditReplyMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class StopInlineMessageLiveLocation(
|
||||
@@ -15,4 +14,6 @@ data class StopInlineMessageLiveLocation(
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditInlineMessage, EditReplyMessage {
|
||||
override fun method(): String = "stopMessageLiveLocation"
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -4,12 +4,16 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditCh
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditReplyMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaContent
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent
|
||||
import kotlinx.serialization.*
|
||||
|
||||
const val editMessageReplyMarkupMethod = "editMessageReplyMarkup"
|
||||
|
||||
private val commonResultDeserializer = TelegramBotAPIMessageDeserializationStrategyClass<ContentMessage<MessageContent>>()
|
||||
|
||||
@Serializable
|
||||
data class EditChatMessageReplyMarkup(
|
||||
@SerialName(chatIdField)
|
||||
@@ -18,8 +22,11 @@ data class EditChatMessageReplyMarkup(
|
||||
override val messageId: MessageIdentifier,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditChatMessage, EditReplyMessage {
|
||||
) : EditChatMessage<MessageContent>, EditReplyMessage {
|
||||
|
||||
override fun method(): String = editMessageReplyMarkupMethod
|
||||
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
|
||||
override val resultDeserializer: DeserializationStrategy<ContentMessage<MessageContent>>
|
||||
get() = commonResultDeserializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -4,8 +4,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditIn
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.EditReplyMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class EditInlineMessageReplyMarkup(
|
||||
@@ -15,4 +14,6 @@ data class EditInlineMessageReplyMarkup(
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditInlineMessage, EditReplyMessage {
|
||||
override fun method(): String = editMessageReplyMarkupMethod
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent
|
||||
|
||||
interface EditChatMessage : SimpleRequest<Message>, MessageAction
|
||||
interface EditChatMessage<MT: MessageContent> : SimpleRequest<ContentMessage<MT>>, MessageAction
|
||||
@@ -2,10 +2,11 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.InlineMessageIdentifier
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.DeserializationStrategy
|
||||
import kotlinx.serialization.internal.BooleanSerializer
|
||||
|
||||
interface EditInlineMessage : SimpleRequest<Boolean> {
|
||||
val inlineMessageId: InlineMessageIdentifier
|
||||
override fun resultDeserializer(): KSerializer<Boolean> = BooleanSerializer
|
||||
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||
get() = BooleanSerializer
|
||||
}
|
||||
@@ -1,12 +1,15 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.caption
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.media.MediaContentMessageResultDeserializer
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.TextContent
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaContent
|
||||
import kotlinx.serialization.*
|
||||
|
||||
const val editMessageCaptionMethod = "editMessageCaption"
|
||||
@@ -23,8 +26,11 @@ data class EditChatMessageCaption(
|
||||
override val parseMode: ParseMode? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditChatMessage, EditTextChatMessage, EditReplyMessage {
|
||||
) : EditChatMessage<MediaContent>, EditTextChatMessage, EditReplyMessage {
|
||||
|
||||
override fun method(): String = editMessageCaptionMethod
|
||||
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
|
||||
override val resultDeserializer: DeserializationStrategy<ContentMessage<MediaContent>>
|
||||
get() = MediaContentMessageResultDeserializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -5,8 +5,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class EditInlineMessageCaption(
|
||||
@@ -20,4 +19,6 @@ data class EditInlineMessageCaption(
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditInlineMessage, EditTextChatMessage, EditReplyMessage {
|
||||
override fun method(): String = editMessageCaptionMethod
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -5,12 +5,15 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.InputMedia
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MediaContent
|
||||
import kotlinx.serialization.*
|
||||
|
||||
const val editMessageMediaMethod = "editMessageMedia"
|
||||
|
||||
internal val MediaContentMessageResultDeserializer = TelegramBotAPIMessageDeserializationStrategyClass<ContentMessage<MediaContent>>()
|
||||
|
||||
@Serializable
|
||||
data class EditChatMessageMedia(
|
||||
@SerialName(chatIdField)
|
||||
@@ -21,7 +24,7 @@ data class EditChatMessageMedia(
|
||||
override val media: InputMedia,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditChatMessage, EditReplyMessage, EditMediaMessage {
|
||||
) : EditChatMessage<MediaContent>, EditReplyMessage, EditMediaMessage {
|
||||
|
||||
init {
|
||||
if (media.file is MultipartFile) {
|
||||
@@ -30,5 +33,8 @@ data class EditChatMessageMedia(
|
||||
}
|
||||
|
||||
override fun method(): String = editMessageMediaMethod
|
||||
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
|
||||
override val resultDeserializer: DeserializationStrategy<ContentMessage<MediaContent>>
|
||||
get() = MediaContentMessageResultDeserializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -5,8 +5,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.InputMedia.InputMedia
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class EditInlineMessageMedia(
|
||||
@@ -23,6 +22,8 @@ data class EditInlineMessageMedia(
|
||||
throw IllegalArgumentException("For editing of media messages you MUST use file id (according to documentation)")
|
||||
}
|
||||
}
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
|
||||
override fun method(): String = editMessageMediaMethod
|
||||
}
|
||||
@@ -1,12 +1,14 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.requests.edit.text
|
||||
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.edit.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.send.TextContentMessageResultDeserializer
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.Message
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategy
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.TextContent
|
||||
import kotlinx.serialization.*
|
||||
|
||||
const val editMessageTextMethod = "editMessageText"
|
||||
@@ -25,8 +27,11 @@ data class EditChatMessageText(
|
||||
override val disableWebPagePreview: Boolean? = null,
|
||||
@SerialName(replyMarkupField)
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditChatMessage, EditTextChatMessage, EditReplyMessage, EditDisableWebPagePreviewMessage {
|
||||
) : EditChatMessage<TextContent>, EditTextChatMessage, EditReplyMessage, EditDisableWebPagePreviewMessage {
|
||||
|
||||
override fun method(): String = editMessageTextMethod
|
||||
override fun resultDeserializer(): DeserializationStrategy<Message> = TelegramBotAPIMessageDeserializationStrategy
|
||||
override val resultDeserializer: DeserializationStrategy<ContentMessage<TextContent>>
|
||||
get() = TextContentMessageResultDeserializer
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -6,8 +6,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class EditInlineMessageText(
|
||||
@@ -23,4 +22,6 @@ data class EditInlineMessageText(
|
||||
override val replyMarkup: InlineKeyboardMarkup? = null
|
||||
) : EditInlineMessage, EditTextChatMessage, EditReplyMessage, EditDisableWebPagePreviewMessage {
|
||||
override fun method(): String = editMessageMediaMethod
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -3,8 +3,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.games
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.games.abstracts.GetGameHighScores
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class GetGameHighScoresByChat (
|
||||
@@ -14,4 +13,7 @@ data class GetGameHighScoresByChat (
|
||||
override val chatId: ChatId,
|
||||
@SerialName(messageIdField)
|
||||
override val messageId: MessageIdentifier
|
||||
) : GetGameHighScores, MessageAction
|
||||
) : GetGameHighScores, MessageAction {
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -3,8 +3,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.games
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.InlineMessageAction
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.games.abstracts.GetGameHighScores
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class GetGameHighScoresByInlineMessageId (
|
||||
@@ -12,4 +11,7 @@ data class GetGameHighScoresByInlineMessageId (
|
||||
override val userId: UserId,
|
||||
@SerialName(inlineMessageIdField)
|
||||
override val inlineMessageId: InlineMessageIdentifier
|
||||
) : GetGameHighScores, InlineMessageAction
|
||||
) : GetGameHighScores, InlineMessageAction {
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -3,8 +3,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.games
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.MessageAction
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.games.abstracts.SetGameScore
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class SetGameScoreByChatId (
|
||||
@@ -20,4 +19,7 @@ data class SetGameScoreByChatId (
|
||||
override val force: Boolean = false,
|
||||
@SerialName(disableEditMessageField)
|
||||
override val disableEditMessage: Boolean = false
|
||||
) : SetGameScore, MessageAction
|
||||
) : SetGameScore, MessageAction {
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -3,8 +3,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.games
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.InlineMessageAction
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.games.abstracts.SetGameScore
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.*
|
||||
|
||||
@Serializable
|
||||
data class SetGameScoreByInlineMessageId (
|
||||
@@ -18,4 +17,7 @@ data class SetGameScoreByInlineMessageId (
|
||||
override val force: Boolean = false,
|
||||
@SerialName(disableEditMessageField)
|
||||
override val disableEditMessage: Boolean = false
|
||||
) : SetGameScore, InlineMessageAction
|
||||
) : SetGameScore, InlineMessageAction {
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.games.abstracts
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.UserId
|
||||
import com.github.insanusmokrassar.TelegramBotAPI.types.games.GameHighScore
|
||||
import kotlinx.serialization.DeserializationStrategy
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.internal.ArrayListSerializer
|
||||
|
||||
@@ -10,7 +11,8 @@ interface GetGameHighScores : SimpleRequest<List<GameHighScore>> {
|
||||
val userId: UserId
|
||||
|
||||
override fun method(): String = "getGameHighScores"
|
||||
override fun resultDeserializer(): KSerializer<List<GameHighScore>> = GameHighScoresSerializer
|
||||
override val resultDeserializer: DeserializationStrategy<List<GameHighScore>>
|
||||
get() = GameHighScoresSerializer
|
||||
}
|
||||
|
||||
object GameHighScoresSerializer : KSerializer<List<GameHighScore>> by ArrayListSerializer(GameHighScore.serializer())
|
||||
internal object GameHighScoresSerializer : KSerializer<List<GameHighScore>> by ArrayListSerializer(GameHighScore.serializer())
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user