mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-11-19 13:55:57 +00:00
Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2bd5d53b2a | |||
| 577436843d | |||
| 048aa93044 | |||
| 4e49de0dd7 | |||
| 9dc5a7624d | |||
| 21a15db031 | |||
| a6aa4b8758 | |||
| e85d5df03e | |||
| 6833640c48 | |||
| c22c1bb144 | |||
| 8293d6683c | |||
| 7e6e892c45 | |||
| 43ac09a79b | |||
| ee1f115d77 | |||
| 7d85b6fb88 | |||
| 013944c5c9 | |||
| 55ed3e165b | |||
| 9c0106d229 | |||
| 9cd2a6220c | |||
| 033ec8f2da |
1
.github/write-good.yml
vendored
Normal file
1
.github/write-good.yml
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
spellchecker: true
|
||||||
77
CHANGELOG.md
77
CHANGELOG.md
@@ -1,5 +1,56 @@
|
|||||||
# TelegramBotAPI changelog
|
# TelegramBotAPI changelog
|
||||||
|
|
||||||
|
## 0.26.0
|
||||||
|
|
||||||
|
* `Common`:
|
||||||
|
* Versions updates:
|
||||||
|
* `Klock`: `1.10.0` -> `1.10.3`
|
||||||
|
* `TelegramBotAPI`:
|
||||||
|
* Request `SendDice` was added (calling [sendDice](https://core.telegram.org/bots/api#senddice))
|
||||||
|
* Class `Dice` was added (type [dice](https://core.telegram.org/bots/api#dice))
|
||||||
|
* Class `DiceContent` was added (for including it in [message](https://core.telegram.org/bots/api#message) object)
|
||||||
|
* `BotCommand` was added
|
||||||
|
* `GetMyCommands` request was added
|
||||||
|
* `SetMyCommands` request was added
|
||||||
|
* `GetMe` now is object instead of class
|
||||||
|
* `GetMe` was replaced into package `com.github.insanusmokrassar.TelegramBotAPI.requests.bot.GetMe`
|
||||||
|
* `CreateNewStickerSet` renamed to `CreateStaticNewStickerSet`
|
||||||
|
* `CreateNewAnimatedStickerSet` request was added (it handle work with `tgs_sticker`)
|
||||||
|
* `StickerSet#thumb` was added
|
||||||
|
* `AddStickerToSet` renamed to `AddStaticStickerToSet`
|
||||||
|
* `AddAnimatedStickerToSet` request was added
|
||||||
|
* `SetStickerSetThumb` request was added
|
||||||
|
* Most of sticker actions now implements `StandardStickerSetAction` instead of `StickerSetAction`
|
||||||
|
* `getUpdatesLimit` was added to be ensure in get updates limit
|
||||||
|
* `GetUpdates` now will check count of requesting updates and throw exception if it is not in range `1 .. 100`
|
||||||
|
* `GetUpdates#limit` now is not nullable and by default set up to 100
|
||||||
|
* `TelegramBotAPI-extensions-api`:
|
||||||
|
* Extensions `sendDice` was added
|
||||||
|
* Extension `getMyCommands` request was added
|
||||||
|
* Extension `setMyCommands` request was added
|
||||||
|
* Extension `getMe` was replaced into package `com.github.insanusmokrassar.TelegramBotAPI.extensions.api.bot.GetMeKt.getMe`
|
||||||
|
* **All extensions `createNewStickerSet` was renamed to `createNewStaticStickerSet`**
|
||||||
|
* Extensions `createNewAnimatedStickerSet` was added
|
||||||
|
* **All extensions `addStickerToSet` was renamed to `addStaticStickerToSet`**
|
||||||
|
* Extensions `addAnimatedStickerToSet` was added
|
||||||
|
* Extensions `setStickerSetThumb` was added
|
||||||
|
* Extension `startGettingUpdates` now will drop `SentMediaGroupUpdate` in case if it is the last in updates group
|
||||||
|
and size of retrieved updates is equal to 100 (max count of retrieved updates)
|
||||||
|
* Extensions `getUpdates` now will receive only not nullable `limit` parameter
|
||||||
|
|
||||||
|
### 0.26.1
|
||||||
|
|
||||||
|
* `TelegramBotAPI`:
|
||||||
|
* `BotCommand` now will check and throw error in case when command or description lengths is/are incorrect
|
||||||
|
* `StorageFile` now is common for all platforms
|
||||||
|
* JavaScript realization was removed due to its redundancy
|
||||||
|
* JVM realization was replaced with `fun` factory
|
||||||
|
* `StorageFile` now able to accept any factory of `Input`
|
||||||
|
* `StorageFileInfo` was added to avoid strange collisions with throws in `StorageFile`
|
||||||
|
* Fixes issue with `hashTag` for markdown
|
||||||
|
* `InvalidPhotoDimensionsException` was added for cases when `PHOTO_INVALID_DIMENSION` answer received
|
||||||
|
* Other fixes
|
||||||
|
|
||||||
## 0.25.0
|
## 0.25.0
|
||||||
|
|
||||||
* Common:
|
* Common:
|
||||||
@@ -25,32 +76,6 @@
|
|||||||
* `FlowsUpdatesFilter` now have two additional flows: `pollAnswerFlow`, `unknownUpdateTypeFlow`
|
* `FlowsUpdatesFilter` now have two additional flows: `pollAnswerFlow`, `unknownUpdateTypeFlow`
|
||||||
* `ExtendedUser` (`typealias`) was added as a `PreviewFeature`
|
* `ExtendedUser` (`typealias`) was added as a `PreviewFeature`
|
||||||
|
|
||||||
### 0.25.2
|
|
||||||
|
|
||||||
* `TelegramBotAPI`:
|
|
||||||
* Request `SendDice` was added (calling [sendDice](https://core.telegram.org/bots/api#senddice))
|
|
||||||
* Class `Dice` was added (type [dice](https://core.telegram.org/bots/api#dice))
|
|
||||||
* Class `DiceContent` was added (for including it in [message](https://core.telegram.org/bots/api#message) object)
|
|
||||||
* `BotCommand` was added
|
|
||||||
* `GetMyCommands` request was added
|
|
||||||
* `SetMyCommands` request was added
|
|
||||||
* `GetMe` now is object instead of class
|
|
||||||
* `GetMe` was replaced into package `com.github.insanusmokrassar.TelegramBotAPI.requests.bot.GetMe`
|
|
||||||
* `CreateNewStickerSet` renamed to `CreateStaticNewStickerSet`
|
|
||||||
* `CreateNewAnimatedStickerSet` request was added (it handle work with `tgs_sticker`)
|
|
||||||
* `StickerSet#thumb` was added
|
|
||||||
* `AddStickerToSet` renamed to `AddStaticStickerToSet`
|
|
||||||
* `AddAnimatedStickerToSet` request was added
|
|
||||||
* `TelegramBotAPI-extensions-api`:
|
|
||||||
* Extensions `sendDice` was added
|
|
||||||
* Extension `getMyCommands` request was added
|
|
||||||
* Extension `setMyCommands` request was added
|
|
||||||
* Extension `getMe` was replaced into package `com.github.insanusmokrassar.TelegramBotAPI.extensions.api.bot.GetMeKt.getMe`
|
|
||||||
* **All extensions `createNewStickerSet` was renamed to `createNewStaticStickerSet`**
|
|
||||||
* Extensions `createNewAnimatedStickerSet` was added
|
|
||||||
* **All extensions `addStickerToSet` was renamed to `addStaticStickerToSet`**
|
|
||||||
* Extensions `addAnimatedStickerToSet` was added
|
|
||||||
|
|
||||||
### 0.25.1
|
### 0.25.1
|
||||||
|
|
||||||
* Update kotlin: `1.3.70` -> `1.3.71`
|
* Update kotlin: `1.3.70` -> `1.3.71`
|
||||||
|
|||||||
@@ -56,20 +56,46 @@ compile "com.github.insanusmokrassar:TelegramBotAPI-extensions-api:$telegrambota
|
|||||||
|
|
||||||
## Example of usage and comparison with `TelegramBotAPI`
|
## Example of usage and comparison with `TelegramBotAPI`
|
||||||
|
|
||||||
As said in [TelegramBotAPI](../TelegramBotAPI/README.md#Requests), it is possible to use next syntax for requests:
|
Here presented review table for comparison of api from original [TelegramBotAPI](../TelegramBotAPI/README.md#Requests)
|
||||||
|
and extensions-api library:
|
||||||
|
|
||||||
```kotlin
|
In all examples supposed that you have created bot with next approximate lines:
|
||||||
val requestsExecutor: RequestsExecutor = ...
|
|
||||||
requestsExecutor.execute(GetMe())
|
|
||||||
```
|
|
||||||
|
|
||||||
This library offer a little bit another way for this:
|
|
||||||
|
|
||||||
```kotlin
|
```kotlin
|
||||||
val bot: RequestsExecutor = ...
|
val bot: RequestsExecutor = ...
|
||||||
bot.getMe()
|
|
||||||
```
|
```
|
||||||
|
|
||||||
The result type of [GetMe (and getMe extension)](https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetMe.kt)
|
| TelegramBotAPI | TelegramBotAPI-extensions-api |
|
||||||
request is
|
|----------------|-------------------------------|
|
||||||
[ExtendedBot](https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/User.kt).
|
| bot.execute(GetMe) | bot.getMe() |
|
||||||
|
| bot.execute(SendTextMessage(someChatId, text)) | bot.sendTextMessage(chat, text) |
|
||||||
|
|
||||||
|
## Updates
|
||||||
|
|
||||||
|
Usually, it is more comfortable to use filter object to get separated types of updates:
|
||||||
|
|
||||||
|
```kotlin
|
||||||
|
val filter = FlowsUpdatesFilter(100)
|
||||||
|
```
|
||||||
|
|
||||||
|
In this case you will be able:
|
||||||
|
|
||||||
|
* Separate types of incoming updates (even media groups)
|
||||||
|
* Simplify launch of getting updates:
|
||||||
|
```kotlin
|
||||||
|
bot.startGettingOfUpdates(
|
||||||
|
filter,
|
||||||
|
scope = CoroutineScope(Dispatchers.Default)
|
||||||
|
)
|
||||||
|
```
|
||||||
|
* Use `filter` flows to comfortable filter, map and do other operations with the whole
|
||||||
|
getting updates process:
|
||||||
|
```kotlin
|
||||||
|
filter.messageFlow.mapNotNull {
|
||||||
|
it.data as? ContentMessage<*>
|
||||||
|
}.onEach {
|
||||||
|
println(it)
|
||||||
|
}.launchIn(
|
||||||
|
CoroutineScope(Dispatchers.Default)
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update
|
|||||||
|
|
||||||
suspend fun RequestsExecutor.getUpdates(
|
suspend fun RequestsExecutor.getUpdates(
|
||||||
offset: UpdateIdentifier? = null,
|
offset: UpdateIdentifier? = null,
|
||||||
limit: Int? = null,
|
limit: Int = getUpdatesLimit.last,
|
||||||
timeout: Seconds? = null,
|
timeout: Seconds? = null,
|
||||||
allowed_updates: List<String>? = ALL_UPDATES_LIST
|
allowed_updates: List<String>? = ALL_UPDATES_LIST
|
||||||
) = execute(
|
) = execute(
|
||||||
@@ -18,7 +18,7 @@ suspend fun RequestsExecutor.getUpdates(
|
|||||||
|
|
||||||
suspend fun RequestsExecutor.getUpdates(
|
suspend fun RequestsExecutor.getUpdates(
|
||||||
lastUpdate: Update,
|
lastUpdate: Update,
|
||||||
limit: Int? = null,
|
limit: Int = getUpdatesLimit.last,
|
||||||
timeout: Seconds? = null,
|
timeout: Seconds? = null,
|
||||||
allowed_updates: List<String>? = ALL_UPDATES_LIST
|
allowed_updates: List<String>? = ALL_UPDATES_LIST
|
||||||
) = getUpdates(
|
) = getUpdates(
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.bot
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.bot
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.bot.GetMyCommands
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.bot.SetMyCommands
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.bot.SetMyCommands
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.BotCommand
|
import com.github.insanusmokrassar.TelegramBotAPI.types.BotCommand
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,74 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.thumbs
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.MultipartFile
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.SetStickerSetThumb
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.CommonUser
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.UserId
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.StickerSet
|
||||||
|
|
||||||
|
suspend fun RequestsExecutor.setStickerSetThumb(
|
||||||
|
userId: UserId,
|
||||||
|
thumbSetName: String,
|
||||||
|
thumb: FileId
|
||||||
|
) = execute(
|
||||||
|
SetStickerSetThumb(userId, thumbSetName, thumb)
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun RequestsExecutor.setStickerSetThumb(
|
||||||
|
userId: UserId,
|
||||||
|
thumbSetName: String,
|
||||||
|
thumb: MultipartFile
|
||||||
|
) = execute(
|
||||||
|
SetStickerSetThumb(userId, thumbSetName, thumb)
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun RequestsExecutor.setStickerSetThumb(
|
||||||
|
user: CommonUser,
|
||||||
|
thumbSetName: String,
|
||||||
|
thumb: FileId
|
||||||
|
) = setStickerSetThumb(
|
||||||
|
user.id, thumbSetName, thumb
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun RequestsExecutor.setStickerSetThumb(
|
||||||
|
user: CommonUser,
|
||||||
|
thumbSetName: String,
|
||||||
|
thumb: MultipartFile
|
||||||
|
) = setStickerSetThumb(
|
||||||
|
user.id, thumbSetName, thumb
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun RequestsExecutor.setStickerSetThumb(
|
||||||
|
userId: UserId,
|
||||||
|
thumbSet: StickerSet,
|
||||||
|
thumb: FileId
|
||||||
|
) = setStickerSetThumb(
|
||||||
|
userId, thumbSet.name, thumb
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun RequestsExecutor.setStickerSetThumb(
|
||||||
|
userId: UserId,
|
||||||
|
thumbSet: StickerSet,
|
||||||
|
thumb: MultipartFile
|
||||||
|
) = setStickerSetThumb(
|
||||||
|
userId, thumbSet.name, thumb
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun RequestsExecutor.setStickerSetThumb(
|
||||||
|
user: CommonUser,
|
||||||
|
thumbSet: StickerSet,
|
||||||
|
thumb: FileId
|
||||||
|
) = setStickerSetThumb(
|
||||||
|
user.id, thumbSet.name, thumb
|
||||||
|
)
|
||||||
|
|
||||||
|
suspend fun RequestsExecutor.setStickerSetThumb(
|
||||||
|
user: CommonUser,
|
||||||
|
thumbSet: StickerSet,
|
||||||
|
thumb: MultipartFile
|
||||||
|
) = setStickerSetThumb(
|
||||||
|
user.id, thumbSet.name, thumb
|
||||||
|
)
|
||||||
|
|
||||||
@@ -5,8 +5,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.RequestExceptio
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.extensions.api.InternalUtils.convertWithMediaGroupUpdates
|
import com.github.insanusmokrassar.TelegramBotAPI.extensions.api.InternalUtils.convertWithMediaGroupUpdates
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.extensions.api.InternalUtils.lastUpdateIdentifier
|
import com.github.insanusmokrassar.TelegramBotAPI.extensions.api.InternalUtils.lastUpdateIdentifier
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.extensions.api.getUpdates
|
import com.github.insanusmokrassar.TelegramBotAPI.extensions.api.getUpdates
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.Seconds
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.UpdateIdentifier
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdates.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdates.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update
|
import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update
|
||||||
@@ -30,7 +29,20 @@ fun RequestsExecutor.startGettingOfUpdates(
|
|||||||
offset = lastUpdateIdentifier?.plus(1),
|
offset = lastUpdateIdentifier?.plus(1),
|
||||||
timeout = timeoutSeconds,
|
timeout = timeoutSeconds,
|
||||||
allowed_updates = allowedUpdates
|
allowed_updates = allowedUpdates
|
||||||
).convertWithMediaGroupUpdates()
|
).let { originalUpdates ->
|
||||||
|
val converted = originalUpdates.convertWithMediaGroupUpdates()
|
||||||
|
/**
|
||||||
|
* Dirty hack for cases when the media group was retrieved not fully:
|
||||||
|
*
|
||||||
|
* We are throw out the last media group and will reretrieve it again in the next get updates
|
||||||
|
* and it will guarantee that it is full
|
||||||
|
*/
|
||||||
|
if (originalUpdates.size == getUpdatesLimit.last && converted.last() is SentMediaGroupUpdate) {
|
||||||
|
converted - converted.last()
|
||||||
|
} else {
|
||||||
|
converted
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
supervisorScope {
|
supervisorScope {
|
||||||
for (update in updates) {
|
for (update in updates) {
|
||||||
|
|||||||
@@ -12,11 +12,10 @@ moments are describing by official [Telegram Bot API](https://core.telegram.org/
|
|||||||
|
|
||||||
## Compatibility
|
## Compatibility
|
||||||
|
|
||||||
This version compatible with [23th of January 2020 update of TelegramBotAPI (version 4.6)](https://core.telegram.org/bots/api#january-23-2020).
|
This version compatible with [30th of March 2020 update of TelegramBotAPI (version 4.7)](https://core.telegram.org/bots/api#march-30-2020).
|
||||||
There is Telegram Passport API exception of implemented functionality, which was presented in
|
There is only one exception of implemented functionality - Telegram Passport API, which was presented in
|
||||||
[August 2018 update of TelegramBotAPI](https://core.telegram.org/bots/api-changelog#august-27-2018) update. It will be implemented
|
[August 2018 update of TelegramBotAPI](https://core.telegram.org/bots/api-changelog#august-27-2018) update. It will be implemented
|
||||||
as soon as possible. All APIs that are not included are presented
|
as soon as possible.
|
||||||
[wiki](https://github.com/InsanusMokrassar/TelegramBotAPI/wiki/Not-included-API).
|
|
||||||
|
|
||||||
## How to implement library?
|
## How to implement library?
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ fun newRequestException(
|
|||||||
description == "Bad Request: message to edit not found" -> MessageToEditNotFoundException(response, plainAnswer, message, cause)
|
description == "Bad Request: message to edit not found" -> MessageToEditNotFoundException(response, plainAnswer, message, cause)
|
||||||
description.contains("Bad Request: message is not modified") -> MessageIsNotModifiedException(response, plainAnswer, message, cause)
|
description.contains("Bad Request: message is not modified") -> MessageIsNotModifiedException(response, plainAnswer, message, cause)
|
||||||
description == "Unauthorized" -> UnauthorizedException(response, plainAnswer, message, cause)
|
description == "Unauthorized" -> UnauthorizedException(response, plainAnswer, message, cause)
|
||||||
|
description.contains("PHOTO_INVALID_DIMENSIONS") -> InvalidPhotoDimensionsException(response, plainAnswer, message, cause)
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
} ?: CommonRequestException(response, plainAnswer, message, cause)
|
} ?: CommonRequestException(response, plainAnswer, message, cause)
|
||||||
@@ -41,3 +42,6 @@ class MessageIsNotModifiedException(response: Response, plainAnswer: String, mes
|
|||||||
|
|
||||||
class MessageToEditNotFoundException(response: Response, plainAnswer: String, message: String?, cause: Throwable?) :
|
class MessageToEditNotFoundException(response: Response, plainAnswer: String, message: String?, cause: Throwable?) :
|
||||||
RequestException(response, plainAnswer, message, cause)
|
RequestException(response, plainAnswer, message, cause)
|
||||||
|
|
||||||
|
class InvalidPhotoDimensionsException(response: Response, plainAnswer: String, message: String?, cause: Throwable?) :
|
||||||
|
RequestException(response, plainAnswer, message, cause)
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ private val updatesListSerializer = ListSerializer(
|
|||||||
@Serializable
|
@Serializable
|
||||||
data class GetUpdates(
|
data class GetUpdates(
|
||||||
val offset: UpdateIdentifier? = null,// set `last update id + 1` to receive next part of updates
|
val offset: UpdateIdentifier? = null,// set `last update id + 1` to receive next part of updates
|
||||||
val limit: Int? = null,
|
val limit: Int = getUpdatesLimit.last,
|
||||||
val timeout: Seconds? = null,
|
val timeout: Seconds? = null,
|
||||||
val allowed_updates: List<String>? = ALL_UPDATES_LIST
|
val allowed_updates: List<String>? = ALL_UPDATES_LIST
|
||||||
): SimpleRequest<List<Update>> {
|
): SimpleRequest<List<Update>> {
|
||||||
@@ -25,4 +25,10 @@ data class GetUpdates(
|
|||||||
|
|
||||||
override val requestSerializer: SerializationStrategy<*>
|
override val requestSerializer: SerializationStrategy<*>
|
||||||
get() = serializer()
|
get() = serializer()
|
||||||
|
|
||||||
|
init {
|
||||||
|
if (limit !in getUpdatesLimit) {
|
||||||
|
error("GetUpdates request can be called only with limit in range $getUpdatesLimit (actual value is $limit)")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,8 +33,8 @@ internal object InputFileSerializer : KSerializer<InputFile> {
|
|||||||
@Serializable(InputFileSerializer::class)
|
@Serializable(InputFileSerializer::class)
|
||||||
data class MultipartFile (
|
data class MultipartFile (
|
||||||
val file: StorageFile,
|
val file: StorageFile,
|
||||||
val mimeType: String = file.contentType,
|
val mimeType: String = file.storageFileInfo.contentType,
|
||||||
val filename: String = file.fileName
|
val filename: String = file.storageFileInfo.fileName
|
||||||
) : InputFile() {
|
) : InputFile() {
|
||||||
override val fileId: String = file.generateCustomName()
|
override val fileId: String = file.storageFileInfo.generateCustomName()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.bot
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
import kotlinx.serialization.builtins.ListSerializer
|
|
||||||
import kotlinx.serialization.builtins.serializer
|
import kotlinx.serialization.builtins.serializer
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
|
|||||||
@@ -2,10 +2,11 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.stickers
|
|||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.common.CommonMultipartFileRequest
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.common.CommonMultipartFileRequest
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StickerSetAction
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StandardStickerSetAction
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition
|
import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
|
|
||||||
fun AddAnimatedStickerToSet(
|
fun AddAnimatedStickerToSet(
|
||||||
userId: UserId,
|
userId: UserId,
|
||||||
stickerSetName: String,
|
stickerSetName: String,
|
||||||
@@ -35,7 +36,7 @@ data class AddAnimatedStickerToSet internal constructor(
|
|||||||
val sticker: FileId? = null,
|
val sticker: FileId? = null,
|
||||||
@SerialName(maskPositionField)
|
@SerialName(maskPositionField)
|
||||||
override val maskPosition: MaskPosition? = null
|
override val maskPosition: MaskPosition? = null
|
||||||
) : StickerSetAction {
|
) : StandardStickerSetAction {
|
||||||
init {
|
init {
|
||||||
if(emojis.isEmpty()) {
|
if(emojis.isEmpty()) {
|
||||||
throw IllegalArgumentException("Emojis must not be empty")
|
throw IllegalArgumentException("Emojis must not be empty")
|
||||||
|
|||||||
@@ -2,10 +2,11 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.stickers
|
|||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.common.CommonMultipartFileRequest
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.common.CommonMultipartFileRequest
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StickerSetAction
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StandardStickerSetAction
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition
|
import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
|
|
||||||
fun AddStaticStickerToSet(
|
fun AddStaticStickerToSet(
|
||||||
userId: UserId,
|
userId: UserId,
|
||||||
stickerSetName: String,
|
stickerSetName: String,
|
||||||
@@ -53,7 +54,7 @@ data class AddStaticStickerToSet internal constructor(
|
|||||||
val sticker: FileId? = null,
|
val sticker: FileId? = null,
|
||||||
@SerialName(maskPositionField)
|
@SerialName(maskPositionField)
|
||||||
override val maskPosition: MaskPosition? = null
|
override val maskPosition: MaskPosition? = null
|
||||||
) : StickerSetAction {
|
) : StandardStickerSetAction {
|
||||||
init {
|
init {
|
||||||
if(emojis.isEmpty()) {
|
if(emojis.isEmpty()) {
|
||||||
throw IllegalArgumentException("Emojis must not be empty")
|
throw IllegalArgumentException("Emojis must not be empty")
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.stickers
|
|||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.common.CommonMultipartFileRequest
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.common.CommonMultipartFileRequest
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StickerSetAction
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StandardStickerSetAction
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition
|
import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
@@ -39,7 +39,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
|
||||||
) : StickerSetAction {
|
) : StandardStickerSetAction {
|
||||||
init {
|
init {
|
||||||
if(emojis.isEmpty()) {
|
if(emojis.isEmpty()) {
|
||||||
throw IllegalArgumentException("Emojis must not be empty")
|
throw IllegalArgumentException("Emojis must not be empty")
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.stickers
|
|||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.common.CommonMultipartFileRequest
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.common.CommonMultipartFileRequest
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StickerSetAction
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StandardStickerSetAction
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition
|
import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
@@ -54,7 +54,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
|
||||||
) : StickerSetAction {
|
) : StandardStickerSetAction {
|
||||||
init {
|
init {
|
||||||
if(emojis.isEmpty()) {
|
if(emojis.isEmpty()) {
|
||||||
throw IllegalArgumentException("Emojis must not be empty")
|
throw IllegalArgumentException("Emojis must not be empty")
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.requests.stickers
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.*
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.common.CommonMultipartFileRequest
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts.StickerSetAction
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||||
|
import kotlinx.serialization.*
|
||||||
|
|
||||||
|
fun SetStickerSetThumb(
|
||||||
|
userId: UserId,
|
||||||
|
stickerSetName: String,
|
||||||
|
thumb: MultipartFile
|
||||||
|
): Request<Boolean> {
|
||||||
|
return CommonMultipartFileRequest(
|
||||||
|
SetStickerSetThumb(userId, stickerSetName),
|
||||||
|
mapOf(thumbField to thumb)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class SetStickerSetThumb (
|
||||||
|
@SerialName(userIdField)
|
||||||
|
override val userId: UserId,
|
||||||
|
@SerialName(nameField)
|
||||||
|
override val name: StickerSetName,
|
||||||
|
@SerialName(thumbField)
|
||||||
|
val thumb: FileId? = null
|
||||||
|
) : StickerSetAction {
|
||||||
|
override val requestSerializer: SerializationStrategy<*>
|
||||||
|
get() = serializer()
|
||||||
|
|
||||||
|
override fun method(): String = "setStickerSetThumb"
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition
|
||||||
|
|
||||||
|
interface StandardStickerSetAction : StickerSetAction {
|
||||||
|
val emojis: String // must be more than one
|
||||||
|
val maskPosition: MaskPosition?
|
||||||
|
}
|
||||||
@@ -2,15 +2,12 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.abstracts
|
|||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.UserId
|
import com.github.insanusmokrassar.TelegramBotAPI.types.UserId
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition
|
|
||||||
import kotlinx.serialization.KSerializer
|
import kotlinx.serialization.KSerializer
|
||||||
import kotlinx.serialization.builtins.serializer
|
import kotlinx.serialization.builtins.serializer
|
||||||
|
|
||||||
interface StickerSetAction : SimpleRequest<Boolean> {
|
interface StickerSetAction : SimpleRequest<Boolean> {
|
||||||
val userId: UserId
|
val userId: UserId
|
||||||
val name: String
|
val name: String
|
||||||
val emojis: String // must be more than one
|
|
||||||
val maskPosition: MaskPosition?
|
|
||||||
|
|
||||||
override val resultDeserializer: KSerializer<Boolean>
|
override val resultDeserializer: KSerializer<Boolean>
|
||||||
get() = Boolean.serializer()
|
get() = Boolean.serializer()
|
||||||
|
|||||||
@@ -9,4 +9,13 @@ data class BotCommand(
|
|||||||
val command: String,
|
val command: String,
|
||||||
@SerialName(descriptionField)
|
@SerialName(descriptionField)
|
||||||
val description: String
|
val description: String
|
||||||
)
|
) {
|
||||||
|
init {
|
||||||
|
if (command.length !in botCommandLengthLimit) {
|
||||||
|
error("Command size must be in range $botCommandLengthLimit, but actually have length ${command.length}")
|
||||||
|
}
|
||||||
|
if (description.length !in botCommandDescriptionLimit) {
|
||||||
|
error("Command description size must be in range $botCommandDescriptionLimit, but actually have length ${description.length}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ typealias DiceResult = Int
|
|||||||
|
|
||||||
typealias Seconds = Int
|
typealias Seconds = Int
|
||||||
|
|
||||||
|
val getUpdatesLimit = 1 .. 100
|
||||||
val callbackQueryAnswerLength = 0 until 200
|
val callbackQueryAnswerLength = 0 until 200
|
||||||
val captionLength = 0 until 1024
|
val captionLength = 0 until 1024
|
||||||
val textLength = 0 until 4096
|
val textLength = 0 until 4096
|
||||||
@@ -48,7 +49,8 @@ val customTitleLength = 0 .. 16
|
|||||||
|
|
||||||
val diceResultLimit = 1 .. 6
|
val diceResultLimit = 1 .. 6
|
||||||
|
|
||||||
val botCommandLimit = 1 .. 32
|
val botCommandLengthLimit = 1 .. 32
|
||||||
|
val botCommandLimit = botCommandLengthLimit
|
||||||
val botCommandDescriptionLimit = 3 .. 256
|
val botCommandDescriptionLimit = 3 .. 256
|
||||||
val botCommandsLimit = 0 .. 100
|
val botCommandsLimit = 0 .. 100
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.message.payments.Success
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.payments.Invoice
|
import com.github.insanusmokrassar.TelegramBotAPI.types.payments.Invoice
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.payments.SuccessfulPayment
|
import com.github.insanusmokrassar.TelegramBotAPI.types.payments.SuccessfulPayment
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.polls.Poll
|
import com.github.insanusmokrassar.TelegramBotAPI.types.polls.Poll
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
// TODO:: add PassportData type
|
// TODO:: add PassportData type
|
||||||
|
|||||||
@@ -1,12 +1,21 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.utils
|
package com.github.insanusmokrassar.TelegramBotAPI.utils
|
||||||
|
|
||||||
|
import com.benasher44.uuid.uuid4
|
||||||
import io.ktor.utils.io.core.Input
|
import io.ktor.utils.io.core.Input
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
import kotlinx.serialization.Transient
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
expect class StorageFile {
|
data class StorageFileInfo(
|
||||||
val contentType: String
|
val contentType: String,
|
||||||
val fileName: String
|
val fileName: String
|
||||||
fun generateCustomName(): String
|
) {
|
||||||
fun asInput(): Input
|
fun generateCustomName() = "${uuid4()}.${fileName.fileExtension}"
|
||||||
|
}
|
||||||
|
|
||||||
|
data class StorageFile(
|
||||||
|
val storageFileInfo: StorageFileInfo,
|
||||||
|
private val inputSource: () -> Input
|
||||||
|
) {
|
||||||
|
fun asInput() = inputSource()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.utils
|
||||||
|
|
||||||
|
private val extensionRegex = Regex("[^.]*$")
|
||||||
|
|
||||||
|
val String.fileExtension
|
||||||
|
get() = extensionRegex.find(this) ?.value ?: ""
|
||||||
@@ -120,7 +120,7 @@ fun String.mentionHTML(): String = mention(String::toHtml)
|
|||||||
|
|
||||||
|
|
||||||
fun String.hashTagMarkdown(): String = hashTag(String::toMarkdown)
|
fun String.hashTagMarkdown(): String = hashTag(String::toMarkdown)
|
||||||
fun String.hashTagMarkdownV2(): String = hashTag(String::escapeMarkdownV2Common)
|
fun String.hashTagMarkdownV2(): String = hashTag(String::escapeMarkdownV2Common).escapeMarkdownV2Common()
|
||||||
fun String.hashTagHTML(): String = hashTag(String::toHtml)
|
fun String.hashTagHTML(): String = hashTag(String::toHtml)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ fun String.toMarkdown(): String {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val markdownV2LinkEscapes = mutableSetOf(')', '\\')
|
private val markdownV2LinkEscapes = setOf(')', '\\')
|
||||||
private val markdownV2PreAndCodeEscapes = mutableSetOf('`', '\\')
|
private val markdownV2PreAndCodeEscapes = setOf('`', '\\')
|
||||||
private val markdownV2CommonEscapes = mutableSetOf(
|
private val markdownV2CommonEscapes = setOf(
|
||||||
'_',
|
'_',
|
||||||
'*',
|
'*',
|
||||||
'[', ']',
|
'[', ']',
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.utils
|
|
||||||
|
|
||||||
import com.benasher44.uuid.uuid4
|
|
||||||
import io.ktor.utils.io.core.Input
|
|
||||||
import kotlinx.serialization.Serializable
|
|
||||||
import kotlinx.serialization.Transient
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
actual data class StorageFile(
|
|
||||||
actual val contentType: String,
|
|
||||||
actual val fileName: String,
|
|
||||||
@Transient
|
|
||||||
val inputGetter: () -> Input = throw IllegalStateException("Can't create object without input"),
|
|
||||||
@Transient
|
|
||||||
val extension: String = throw IllegalStateException("Can't create object without extension")
|
|
||||||
) {
|
|
||||||
actual fun asInput(): Input = inputGetter()
|
|
||||||
actual fun generateCustomName(): String = "${uuid4()}.$extension"
|
|
||||||
}
|
|
||||||
@@ -1,20 +1,16 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.utils
|
package com.github.insanusmokrassar.TelegramBotAPI.utils
|
||||||
|
|
||||||
import com.benasher44.uuid.uuid4
|
|
||||||
import io.ktor.utils.io.core.Input
|
|
||||||
import io.ktor.utils.io.streams.asInput
|
import io.ktor.utils.io.streams.asInput
|
||||||
import kotlinx.serialization.Serializable
|
|
||||||
import kotlinx.serialization.Transient
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
|
|
||||||
@Serializable
|
fun StorageFile(
|
||||||
actual class StorageFile(
|
file: File
|
||||||
@Transient
|
) = StorageFile(
|
||||||
private val file: File = throw IllegalStateException("Can't create object without file")
|
StorageFileInfo(
|
||||||
|
Files.probeContentType(file.toPath()),
|
||||||
|
file.name
|
||||||
|
)
|
||||||
) {
|
) {
|
||||||
actual val contentType: String = Files.probeContentType(file.toPath())
|
file.inputStream().asInput()
|
||||||
actual val fileName: String = file.name
|
|
||||||
actual fun generateCustomName(): String = "${uuid4()}.${file.extension}"
|
|
||||||
actual fun asInput(): Input = Files.newInputStream(file.toPath()).asInput()
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ kotlin.code.style=official
|
|||||||
kotlin_version=1.3.71
|
kotlin_version=1.3.71
|
||||||
kotlin_coroutines_version=1.3.5
|
kotlin_coroutines_version=1.3.5
|
||||||
kotlin_serialisation_runtime_version=0.20.0
|
kotlin_serialisation_runtime_version=0.20.0
|
||||||
klock_version=1.10.0
|
klock_version=1.10.3
|
||||||
uuid_version=0.1.0
|
uuid_version=0.1.0
|
||||||
ktor_version=1.3.2
|
ktor_version=1.3.2
|
||||||
|
|
||||||
library_group=com.github.insanusmokrassar
|
library_group=com.github.insanusmokrassar
|
||||||
library_version=0.25.2
|
library_version=0.26.1
|
||||||
|
|
||||||
gradle_bintray_plugin_version=1.8.4
|
gradle_bintray_plugin_version=1.8.4
|
||||||
|
|||||||
Reference in New Issue
Block a user