diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b9334f267..4eced9cdc8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,43 @@ # 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.25.0 * Common: diff --git a/TelegramBotAPI-extensions-api/README.md b/TelegramBotAPI-extensions-api/README.md index 4162bcd5f9..275b475f9c 100644 --- a/TelegramBotAPI-extensions-api/README.md +++ b/TelegramBotAPI-extensions-api/README.md @@ -56,20 +56,46 @@ compile "com.github.insanusmokrassar:TelegramBotAPI-extensions-api:$telegrambota ## 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 -val requestsExecutor: RequestsExecutor = ... -requestsExecutor.execute(GetMe()) -``` - -This library offer a little bit another way for this: +In all examples supposed that you have created bot with next approximate lines: ```kotlin 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) -request is -[ExtendedBot](https://github.com/InsanusMokrassar/TelegramBotAPI/blob/master/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/User.kt). +| TelegramBotAPI | TelegramBotAPI-extensions-api | +|----------------|-------------------------------| +| 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) +) +``` diff --git a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/GetMe.kt b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/GetMe.kt index d0a48bdbf4..889d07a6b0 100644 --- a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/GetMe.kt +++ b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/GetMe.kt @@ -1,6 +1,10 @@ package com.github.insanusmokrassar.TelegramBotAPI.extensions.api import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor -import com.github.insanusmokrassar.TelegramBotAPI.requests.GetMe +import com.github.insanusmokrassar.TelegramBotAPI.extensions.api.bot.getMe -suspend fun RequestsExecutor.getMe() = execute(GetMe()) \ No newline at end of file +@Deprecated( + "Replaced", + ReplaceWith("getMe", "com.github.insanusmokrassar.TelegramBotAPI.extensions.api.bot.GetMeKt.getMe") +) +suspend fun RequestsExecutor.getMe() = getMe() \ No newline at end of file diff --git a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/GetUpdates.kt b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/GetUpdates.kt index 728dfb0ec5..778ef5e983 100644 --- a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/GetUpdates.kt +++ b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/GetUpdates.kt @@ -7,7 +7,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update suspend fun RequestsExecutor.getUpdates( offset: UpdateIdentifier? = null, - limit: Int? = null, + limit: Int = getUpdatesLimit.last, timeout: Seconds? = null, allowed_updates: List? = ALL_UPDATES_LIST ) = execute( @@ -18,7 +18,7 @@ suspend fun RequestsExecutor.getUpdates( suspend fun RequestsExecutor.getUpdates( lastUpdate: Update, - limit: Int? = null, + limit: Int = getUpdatesLimit.last, timeout: Seconds? = null, allowed_updates: List? = ALL_UPDATES_LIST ) = getUpdates( diff --git a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/bot/GetMe.kt b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/bot/GetMe.kt new file mode 100644 index 0000000000..66d9b4512d --- /dev/null +++ b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/bot/GetMe.kt @@ -0,0 +1,6 @@ +package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.bot + +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor +import com.github.insanusmokrassar.TelegramBotAPI.requests.bot.GetMe + +suspend fun RequestsExecutor.getMe() = execute(GetMe) diff --git a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/bot/GetMyCommands.kt b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/bot/GetMyCommands.kt new file mode 100644 index 0000000000..41a9bef0f7 --- /dev/null +++ b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/bot/GetMyCommands.kt @@ -0,0 +1,6 @@ +package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.bot + +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor +import com.github.insanusmokrassar.TelegramBotAPI.requests.bot.GetMyCommands + +suspend fun RequestsExecutor.getMyCommands() = execute(GetMyCommands) diff --git a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/bot/SetMyCommands.kt b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/bot/SetMyCommands.kt new file mode 100644 index 0000000000..5347510a5f --- /dev/null +++ b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/bot/SetMyCommands.kt @@ -0,0 +1,9 @@ +package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.bot + +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor +import com.github.insanusmokrassar.TelegramBotAPI.requests.bot.SetMyCommands +import com.github.insanusmokrassar.TelegramBotAPI.types.BotCommand + +suspend fun RequestsExecutor.setMyCommands( + commands: List +) = execute(SetMyCommands(commands)) diff --git a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/send/SendDice.kt b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/send/SendDice.kt new file mode 100644 index 0000000000..c0e7f89442 --- /dev/null +++ b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/send/SendDice.kt @@ -0,0 +1,24 @@ +package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.send + +import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor +import com.github.insanusmokrassar.TelegramBotAPI.requests.send.SendDice +import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier +import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier +import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat + +suspend fun RequestsExecutor.sendDice( + chatId: ChatIdentifier, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = execute( + SendDice(chatId, disableNotification, replyToMessageId, replyMarkup) +) + +suspend fun RequestsExecutor.sendDice( + chat: Chat, + disableNotification: Boolean = false, + replyToMessageId: MessageIdentifier? = null, + replyMarkup: KeyboardMarkup? = null +) = sendDice(chat.id, disableNotification, replyToMessageId, replyMarkup) diff --git a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/AddAnimatedStickerToSet.kt b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/AddAnimatedStickerToSet.kt new file mode 100644 index 0000000000..f9d32b0727 --- /dev/null +++ b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/AddAnimatedStickerToSet.kt @@ -0,0 +1,90 @@ +package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.stickers + +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.AddAnimatedStickerToSet +import com.github.insanusmokrassar.TelegramBotAPI.types.CommonUser +import com.github.insanusmokrassar.TelegramBotAPI.types.UserId +import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition +import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.StickerSet + +suspend fun RequestsExecutor.addAnimatedStickerToSet( + userId: UserId, + stickerSetName: String, + sticker: FileId, + emojis: String, + maskPosition: MaskPosition? = null +) = execute( + AddAnimatedStickerToSet(userId, stickerSetName, sticker, emojis, maskPosition) +) + +suspend fun RequestsExecutor.addAnimatedStickerToSet( + userId: UserId, + stickerSetName: String, + sticker: MultipartFile, + emojis: String, + maskPosition: MaskPosition? = null +) = execute( + AddAnimatedStickerToSet(userId, stickerSetName, sticker, emojis, maskPosition) +) + +suspend fun RequestsExecutor.addAnimatedStickerToSet( + user: CommonUser, + stickerSetName: String, + sticker: FileId, + emojis: String, + maskPosition: MaskPosition? = null +) = addAnimatedStickerToSet( + user.id, stickerSetName, sticker, emojis, maskPosition +) + +suspend fun RequestsExecutor.addAnimatedStickerToSet( + user: CommonUser, + stickerSetName: String, + sticker: MultipartFile, + emojis: String, + maskPosition: MaskPosition? = null +) = addAnimatedStickerToSet( + user.id, stickerSetName, sticker, emojis, maskPosition +) + +suspend fun RequestsExecutor.addAnimatedStickerToSet( + userId: UserId, + stickerSet: StickerSet, + sticker: FileId, + emojis: String, + maskPosition: MaskPosition? = null +) = addAnimatedStickerToSet( + userId, stickerSet.name, sticker, emojis, maskPosition +) + +suspend fun RequestsExecutor.addAnimatedStickerToSet( + userId: UserId, + stickerSet: StickerSet, + sticker: MultipartFile, + emojis: String, + maskPosition: MaskPosition? = null +) = addAnimatedStickerToSet( + userId, stickerSet.name, sticker, emojis, maskPosition +) + +suspend fun RequestsExecutor.addAnimatedStickerToSet( + user: CommonUser, + stickerSet: StickerSet, + sticker: FileId, + emojis: String, + maskPosition: MaskPosition? = null +) = addAnimatedStickerToSet( + user.id, stickerSet.name, sticker, emojis, maskPosition +) + +suspend fun RequestsExecutor.addAnimatedStickerToSet( + user: CommonUser, + stickerSet: StickerSet, + sticker: MultipartFile, + emojis: String, + maskPosition: MaskPosition? = null +) = addAnimatedStickerToSet( + user.id, stickerSet.name, sticker, emojis, maskPosition +) diff --git a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/AddStickerToSet.kt b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/AddStaticStickerToSet.kt similarity index 73% rename from TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/AddStickerToSet.kt rename to TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/AddStaticStickerToSet.kt index e2436eb245..2d09222784 100644 --- a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/AddStickerToSet.kt +++ b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/AddStaticStickerToSet.kt @@ -3,88 +3,88 @@ package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.stickers 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.AddStickerToSet +import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.AddStaticStickerToSet import com.github.insanusmokrassar.TelegramBotAPI.types.CommonUser import com.github.insanusmokrassar.TelegramBotAPI.types.UserId import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.StickerSet -suspend fun RequestsExecutor.addStickerToSet( +suspend fun RequestsExecutor.addStaticStickerToSet( userId: UserId, stickerSetName: String, sticker: FileId, emojis: String, maskPosition: MaskPosition? = null ) = execute( - AddStickerToSet(userId, stickerSetName, sticker, emojis, maskPosition) + AddStaticStickerToSet(userId, stickerSetName, sticker, emojis, maskPosition) ) -suspend fun RequestsExecutor.addStickerToSet( +suspend fun RequestsExecutor.addStaticStickerToSet( userId: UserId, stickerSetName: String, sticker: MultipartFile, emojis: String, maskPosition: MaskPosition? = null ) = execute( - AddStickerToSet(userId, stickerSetName, sticker, emojis, maskPosition) + AddStaticStickerToSet(userId, stickerSetName, sticker, emojis, maskPosition) ) -suspend fun RequestsExecutor.addStickerToSet( +suspend fun RequestsExecutor.addStaticStickerToSet( user: CommonUser, stickerSetName: String, sticker: FileId, emojis: String, maskPosition: MaskPosition? = null -) = addStickerToSet( +) = addStaticStickerToSet( user.id, stickerSetName, sticker, emojis, maskPosition ) -suspend fun RequestsExecutor.addStickerToSet( +suspend fun RequestsExecutor.addStaticStickerToSet( user: CommonUser, stickerSetName: String, sticker: MultipartFile, emojis: String, maskPosition: MaskPosition? = null -) = addStickerToSet( +) = addStaticStickerToSet( user.id, stickerSetName, sticker, emojis, maskPosition ) -suspend fun RequestsExecutor.addStickerToSet( +suspend fun RequestsExecutor.addStaticStickerToSet( userId: UserId, stickerSet: StickerSet, sticker: FileId, emojis: String, maskPosition: MaskPosition? = null -) = addStickerToSet( +) = addStaticStickerToSet( userId, stickerSet.name, sticker, emojis, maskPosition ) -suspend fun RequestsExecutor.addStickerToSet( +suspend fun RequestsExecutor.addStaticStickerToSet( userId: UserId, stickerSet: StickerSet, sticker: MultipartFile, emojis: String, maskPosition: MaskPosition? = null -) = addStickerToSet( +) = addStaticStickerToSet( userId, stickerSet.name, sticker, emojis, maskPosition ) -suspend fun RequestsExecutor.addStickerToSet( +suspend fun RequestsExecutor.addStaticStickerToSet( user: CommonUser, stickerSet: StickerSet, sticker: FileId, emojis: String, maskPosition: MaskPosition? = null -) = addStickerToSet( +) = addStaticStickerToSet( user.id, stickerSet.name, sticker, emojis, maskPosition ) -suspend fun RequestsExecutor.addStickerToSet( +suspend fun RequestsExecutor.addStaticStickerToSet( user: CommonUser, stickerSet: StickerSet, sticker: MultipartFile, emojis: String, maskPosition: MaskPosition? = null -) = addStickerToSet( +) = addStaticStickerToSet( user.id, stickerSet.name, sticker, emojis, maskPosition ) diff --git a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/CreateNewAnimatedStickerSet.kt b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/CreateNewAnimatedStickerSet.kt new file mode 100644 index 0000000000..f1d2e14de0 --- /dev/null +++ b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/CreateNewAnimatedStickerSet.kt @@ -0,0 +1,54 @@ +package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.stickers + +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.CreateNewAnimatedStickerSet +import com.github.insanusmokrassar.TelegramBotAPI.types.CommonUser +import com.github.insanusmokrassar.TelegramBotAPI.types.UserId +import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition + +suspend fun RequestsExecutor.createNewAnimatedStickerSet( + userId: UserId, + name: String, + sticker: FileId, + emojis: String, + containsMasks: Boolean? = null, + maskPosition: MaskPosition? = null +) = execute( + CreateNewAnimatedStickerSet(userId, name, sticker, emojis, containsMasks, maskPosition) +) + +suspend fun RequestsExecutor.createNewAnimatedStickerSet( + userId: UserId, + name: String, + sticker: MultipartFile, + emojis: String, + containsMasks: Boolean? = null, + maskPosition: MaskPosition? = null +) = execute( + CreateNewAnimatedStickerSet(userId, name, sticker, emojis, containsMasks, maskPosition) +) + + +suspend fun RequestsExecutor.createNewAnimatedStickerSet( + user: CommonUser, + name: String, + sticker: FileId, + emojis: String, + containsMasks: Boolean? = null, + maskPosition: MaskPosition? = null +) = createNewAnimatedStickerSet( + user.id, name, sticker, emojis, containsMasks, maskPosition +) + +suspend fun RequestsExecutor.createNewAnimatedStickerSet( + user: CommonUser, + name: String, + sticker: MultipartFile, + emojis: String, + containsMasks: Boolean? = null, + maskPosition: MaskPosition? = null +) = createNewAnimatedStickerSet( + user.id, name, sticker, emojis, containsMasks, maskPosition +) diff --git a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/CreateNewStickerSet.kt b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/CreateNewStaticStickerSet.kt similarity index 73% rename from TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/CreateNewStickerSet.kt rename to TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/CreateNewStaticStickerSet.kt index b65acc0f0a..9234137195 100644 --- a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/CreateNewStickerSet.kt +++ b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/CreateNewStaticStickerSet.kt @@ -3,12 +3,12 @@ package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.stickers 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.CreateNewStickerSet +import com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.CreateNewStaticStickerSet import com.github.insanusmokrassar.TelegramBotAPI.types.CommonUser import com.github.insanusmokrassar.TelegramBotAPI.types.UserId import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition -suspend fun RequestsExecutor.createNewStickerSet( +suspend fun RequestsExecutor.createNewStaticStickerSet( userId: UserId, name: String, sticker: FileId, @@ -16,10 +16,10 @@ suspend fun RequestsExecutor.createNewStickerSet( containsMasks: Boolean? = null, maskPosition: MaskPosition? = null ) = execute( - CreateNewStickerSet(userId, name, sticker, emojis, containsMasks, maskPosition) + CreateNewStaticStickerSet(userId, name, sticker, emojis, containsMasks, maskPosition) ) -suspend fun RequestsExecutor.createNewStickerSet( +suspend fun RequestsExecutor.createNewStaticStickerSet( userId: UserId, name: String, sticker: MultipartFile, @@ -27,28 +27,28 @@ suspend fun RequestsExecutor.createNewStickerSet( containsMasks: Boolean? = null, maskPosition: MaskPosition? = null ) = execute( - CreateNewStickerSet(userId, name, sticker, emojis, containsMasks, maskPosition) + CreateNewStaticStickerSet(userId, name, sticker, emojis, containsMasks, maskPosition) ) -suspend fun RequestsExecutor.createNewStickerSet( +suspend fun RequestsExecutor.createNewStaticStickerSet( user: CommonUser, name: String, sticker: FileId, emojis: String, containsMasks: Boolean? = null, maskPosition: MaskPosition? = null -) = createNewStickerSet( +) = createNewStaticStickerSet( user.id, name, sticker, emojis, containsMasks, maskPosition ) -suspend fun RequestsExecutor.createNewStickerSet( +suspend fun RequestsExecutor.createNewStaticStickerSet( user: CommonUser, name: String, sticker: MultipartFile, emojis: String, containsMasks: Boolean? = null, maskPosition: MaskPosition? = null -) = createNewStickerSet( +) = createNewStaticStickerSet( user.id, name, sticker, emojis, containsMasks, maskPosition ) diff --git a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/SetStickerSetThumb.kt b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/SetStickerSetThumb.kt new file mode 100644 index 0000000000..45fad6497a --- /dev/null +++ b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/stickers/SetStickerSetThumb.kt @@ -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 +) + diff --git a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/updates/UpdatesPolling.kt b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/updates/UpdatesPolling.kt index bd4e99f8ab..fe2fba5f2e 100644 --- a/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/updates/UpdatesPolling.kt +++ b/TelegramBotAPI-extensions-api/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/api/updates/UpdatesPolling.kt @@ -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.lastUpdateIdentifier import com.github.insanusmokrassar.TelegramBotAPI.extensions.api.getUpdates -import com.github.insanusmokrassar.TelegramBotAPI.types.Seconds -import com.github.insanusmokrassar.TelegramBotAPI.types.UpdateIdentifier +import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.update.* import com.github.insanusmokrassar.TelegramBotAPI.types.update.MediaGroupUpdates.* import com.github.insanusmokrassar.TelegramBotAPI.types.update.abstracts.Update @@ -30,7 +29,20 @@ fun RequestsExecutor.startGettingOfUpdates( offset = lastUpdateIdentifier?.plus(1), timeout = timeoutSeconds, 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 { for (update in updates) { diff --git a/TelegramBotAPI/README.md b/TelegramBotAPI/README.md index b93ed650f8..d255e585bf 100644 --- a/TelegramBotAPI/README.md +++ b/TelegramBotAPI/README.md @@ -12,11 +12,10 @@ moments are describing by official [Telegram Bot API](https://core.telegram.org/ ## Compatibility -This version compatible with [23th of January 2020 update of TelegramBotAPI (version 4.6)](https://core.telegram.org/bots/api#january-23-2020). -There is Telegram Passport API exception of implemented functionality, which was presented in +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 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 -as soon as possible. All APIs that are not included are presented -[wiki](https://github.com/InsanusMokrassar/TelegramBotAPI/wiki/Not-included-API). +as soon as possible. ## How to implement library? diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetMe.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetMe.kt index b0cd428c8c..4c4dab284b 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetMe.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetMe.kt @@ -1,14 +1,11 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests -import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest -import com.github.insanusmokrassar.TelegramBotAPI.types.ExtendedBot -import kotlinx.serialization.* +import com.github.insanusmokrassar.TelegramBotAPI.requests.bot.GetMe -@Serializable -class GetMe : SimpleRequest { - override fun method(): String = "getMe" - override val resultDeserializer: DeserializationStrategy - get() = ExtendedBot.serializer() - override val requestSerializer: SerializationStrategy<*> - get() = serializer() -} +@Deprecated( + "Replaced", + ReplaceWith( + "GetMe", "com.github.insanusmokrassar.TelegramBotAPI.requests.bot.GetMe" + ) +) +typealias GetMe = GetMe diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetUpdates.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetUpdates.kt index 5f89bcc368..3169c63936 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetUpdates.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/GetUpdates.kt @@ -14,7 +14,7 @@ private val updatesListSerializer = ListSerializer( @Serializable data class GetUpdates( 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 allowed_updates: List? = ALL_UPDATES_LIST ): SimpleRequest> { @@ -25,4 +25,10 @@ data class GetUpdates( override val requestSerializer: SerializationStrategy<*> get() = serializer() + + init { + if (limit !in getUpdatesLimit) { + error("GetUpdates request can be called only with limit in range $getUpdatesLimit (actual value is $limit)") + } + } } diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/bot/GetMe.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/bot/GetMe.kt new file mode 100644 index 0000000000..b200c34dbd --- /dev/null +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/bot/GetMe.kt @@ -0,0 +1,14 @@ +package com.github.insanusmokrassar.TelegramBotAPI.requests.bot + +import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest +import com.github.insanusmokrassar.TelegramBotAPI.types.ExtendedBot +import kotlinx.serialization.* + +@Serializable +object GetMe : SimpleRequest { + override fun method(): String = "getMe" + override val resultDeserializer: DeserializationStrategy + get() = ExtendedBot.serializer() + override val requestSerializer: SerializationStrategy<*> + get() = serializer() +} diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/bot/GetMyCommands.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/bot/GetMyCommands.kt new file mode 100644 index 0000000000..a7a3c764bb --- /dev/null +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/bot/GetMyCommands.kt @@ -0,0 +1,17 @@ +package com.github.insanusmokrassar.TelegramBotAPI.requests.bot + +import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest +import com.github.insanusmokrassar.TelegramBotAPI.types.BotCommand +import kotlinx.serialization.* +import kotlinx.serialization.builtins.ListSerializer + +private val getMyCommandsSerializer = ListSerializer(BotCommand.serializer()) + +@Serializable +object GetMyCommands : SimpleRequest> { + override fun method(): String = "getMyCommands" + override val resultDeserializer: DeserializationStrategy> + get() = getMyCommandsSerializer + override val requestSerializer: SerializationStrategy<*> + get() = serializer() +} diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/bot/SetMyCommands.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/bot/SetMyCommands.kt new file mode 100644 index 0000000000..44456d5787 --- /dev/null +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/bot/SetMyCommands.kt @@ -0,0 +1,24 @@ +package com.github.insanusmokrassar.TelegramBotAPI.requests.bot + +import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest +import com.github.insanusmokrassar.TelegramBotAPI.types.* +import kotlinx.serialization.* +import kotlinx.serialization.builtins.serializer + +@Serializable +class SetMyCommands( + @SerialName(botCommandsField) + val commands: List +) : SimpleRequest { + override fun method(): String = "setMyCommands" + override val resultDeserializer: DeserializationStrategy + get() = Boolean.serializer() + override val requestSerializer: SerializationStrategy<*> + get() = serializer() + + init { + if (commands.size !in botCommandsLimit) { + error("Bot commands list size able to be in range $botCommandsLimit, but incoming size is ${commands.size}") + } + } +} diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendDice.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendDice.kt new file mode 100644 index 0000000000..a6537de89d --- /dev/null +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/send/SendDice.kt @@ -0,0 +1,34 @@ +package com.github.insanusmokrassar.TelegramBotAPI.requests.send + +import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.DisableNotification +import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ReplyMessageId +import com.github.insanusmokrassar.TelegramBotAPI.requests.send.abstracts.ReplyingMarkupSendMessageRequest +import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup +import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage +import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.TelegramBotAPIMessageDeserializationStrategyClass +import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.DiceContent +import kotlinx.serialization.* + +internal val DiceContentMessageResultDeserializer: DeserializationStrategy> + = TelegramBotAPIMessageDeserializationStrategyClass() + +@Serializable +data class SendDice( + @SerialName(chatIdField) + override val chatId: ChatIdentifier, + @SerialName(disableNotificationField) + override val disableNotification: Boolean = false, + @SerialName(replyToMessageIdField) + override val replyToMessageId: MessageIdentifier? = null, + @SerialName(replyMarkupField) + override val replyMarkup: KeyboardMarkup? = null +) : ReplyingMarkupSendMessageRequest>, ReplyMessageId, DisableNotification { + override val requestSerializer: SerializationStrategy<*> + get() = serializer() + + override fun method(): String = "sendDice" + + override val resultDeserializer: DeserializationStrategy> + get() = DiceContentMessageResultDeserializer +} \ No newline at end of file diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddStickerToSet.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddAnimatedStickerToSet.kt similarity index 82% rename from TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddStickerToSet.kt rename to TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddAnimatedStickerToSet.kt index 113ad5966e..105cf9e12b 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddStickerToSet.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddAnimatedStickerToSet.kt @@ -2,19 +2,19 @@ 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.requests.stickers.abstracts.StandardStickerSetAction import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition import kotlinx.serialization.* -fun AddStickerToSet( +fun AddAnimatedStickerToSet( userId: UserId, stickerSetName: String, sticker: InputFile, emojis: String, maskPosition: MaskPosition? = null ): Request { - val data = AddStickerToSet(userId, stickerSetName, emojis, sticker as? FileId, maskPosition) + val data = AddAnimatedStickerToSet(userId, stickerSetName, emojis, sticker as? FileId, maskPosition) return when (sticker) { is MultipartFile -> CommonMultipartFileRequest( data, @@ -25,18 +25,18 @@ fun AddStickerToSet( } @Serializable -data class AddStickerToSet internal constructor( +data class AddAnimatedStickerToSet internal constructor( @SerialName(userIdField) override val userId: UserId, @SerialName(nameField) override val name: String, @SerialName(emojisField) override val emojis: String, - @SerialName(pngStickerField) + @SerialName(tgsStickerField) val sticker: FileId? = null, @SerialName(maskPositionField) override val maskPosition: MaskPosition? = null -) : StickerSetAction { +) : StandardStickerSetAction { init { if(emojis.isEmpty()) { throw IllegalArgumentException("Emojis must not be empty") diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddStaticStickerToSet.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddStaticStickerToSet.kt new file mode 100644 index 0000000000..769cd69e55 --- /dev/null +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/AddStaticStickerToSet.kt @@ -0,0 +1,68 @@ +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.StandardStickerSetAction +import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition +import kotlinx.serialization.* + +fun AddStaticStickerToSet( + userId: UserId, + stickerSetName: String, + sticker: InputFile, + emojis: String, + maskPosition: MaskPosition? = null +): Request { + val data = AddStaticStickerToSet(userId, stickerSetName, emojis, sticker as? FileId, maskPosition) + return when (sticker) { + is MultipartFile -> CommonMultipartFileRequest( + data, + mapOf(pngStickerField to sticker) + ) + is FileId -> data + } +} + +@Deprecated( + "Renamed", + ReplaceWith("AddStaticStickerToSet", "com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.AddStaticStickerToSet") +) +fun AddStickerToSet( + userId: UserId, + stickerSetName: String, + sticker: InputFile, + emojis: String, + maskPosition: MaskPosition? = null +) = AddStaticStickerToSet(userId, stickerSetName, sticker, emojis, maskPosition) + +@Deprecated( + "Renamed", + ReplaceWith("AddStaticStickerToSet", "com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.AddStaticStickerToSet") +) +typealias AddStickerToSet = AddStaticStickerToSet + +@Serializable +data class AddStaticStickerToSet internal constructor( + @SerialName(userIdField) + override val userId: UserId, + @SerialName(nameField) + override val name: String, + @SerialName(emojisField) + override val emojis: String, + @SerialName(pngStickerField) + val sticker: FileId? = null, + @SerialName(maskPositionField) + override val maskPosition: MaskPosition? = null +) : StandardStickerSetAction { + init { + if(emojis.isEmpty()) { + throw IllegalArgumentException("Emojis must not be empty") + } + } + + override val requestSerializer: SerializationStrategy<*> + get() = serializer() + + override fun method(): String = "addStickerToSet" +} diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewStickerSet.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewAnimatedStickerSet.kt similarity index 82% rename from TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewStickerSet.kt rename to TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewAnimatedStickerSet.kt index b02b967fc3..d512b88acf 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewStickerSet.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewAnimatedStickerSet.kt @@ -2,12 +2,12 @@ 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.requests.stickers.abstracts.StandardStickerSetAction import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition import kotlinx.serialization.* -fun CreateNewStickerSet( +fun CreateNewAnimatedStickerSet( userId: UserId, name: String, sticker: InputFile, @@ -15,7 +15,7 @@ fun CreateNewStickerSet( containsMasks: Boolean? = null, maskPosition: MaskPosition? = null ): Request { - val data = CreateNewStickerSet(userId, name, emojis, sticker as? FileId, containsMasks, maskPosition) + val data = CreateNewAnimatedStickerSet(userId, name, emojis, sticker as? FileId, containsMasks, maskPosition) return when (sticker) { is MultipartFile -> CommonMultipartFileRequest( data, @@ -26,20 +26,20 @@ fun CreateNewStickerSet( } @Serializable -data class CreateNewStickerSet internal constructor( +data class CreateNewAnimatedStickerSet internal constructor( @SerialName(userIdField) override val userId: UserId, @SerialName(nameField) override val name: String, @SerialName(emojisField) override val emojis: String, - @SerialName(pngStickerField) + @SerialName(tgsStickerField) val sticker: FileId? = null, @SerialName(containsMasksField) val containsMasks: Boolean? = null, @SerialName(maskPositionField) override val maskPosition: MaskPosition? = null -) : StickerSetAction { +) : StandardStickerSetAction { init { if(emojis.isEmpty()) { throw IllegalArgumentException("Emojis must not be empty") diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewStaticStickerSet.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewStaticStickerSet.kt new file mode 100644 index 0000000000..2fda4511cc --- /dev/null +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/CreateNewStaticStickerSet.kt @@ -0,0 +1,68 @@ +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.StandardStickerSetAction +import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition +import kotlinx.serialization.* + +fun CreateNewStaticStickerSet( + userId: UserId, + name: String, + sticker: InputFile, + emojis: String, + containsMasks: Boolean? = null, + maskPosition: MaskPosition? = null +): Request { + val data = CreateNewStaticStickerSet(userId, name, emojis, sticker as? FileId, containsMasks, maskPosition) + return when (sticker) { + is MultipartFile -> CommonMultipartFileRequest( + data, + mapOf(pngStickerField to sticker) + ) + is FileId -> data + } +} + +fun CreateNewStickerSet( + userId: UserId, + name: String, + sticker: InputFile, + emojis: String, + containsMasks: Boolean? = null, + maskPosition: MaskPosition? = null +): Request = CreateNewStaticStickerSet(userId, name, sticker, emojis, containsMasks, maskPosition) + +@Deprecated( + "Renamed", + ReplaceWith("CreateNewStaticStickerSet", "com.github.insanusmokrassar.TelegramBotAPI.requests.stickers.CreateNewStaticStickerSet") +) +typealias CreateNewStickerSet = CreateNewStaticStickerSet + +@Serializable +data class CreateNewStaticStickerSet internal constructor( + @SerialName(userIdField) + override val userId: UserId, + @SerialName(nameField) + override val name: String, + @SerialName(emojisField) + override val emojis: String, + @SerialName(pngStickerField) + val sticker: FileId? = null, + @SerialName(containsMasksField) + val containsMasks: Boolean? = null, + @SerialName(maskPositionField) + override val maskPosition: MaskPosition? = null +) : StandardStickerSetAction { + init { + if(emojis.isEmpty()) { + throw IllegalArgumentException("Emojis must not be empty") + } + } + + override val requestSerializer: SerializationStrategy<*> + get() = serializer() + + override fun method(): String = "createNewStickerSet" +} diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/SetStickerSetThumb.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/SetStickerSetThumb.kt new file mode 100644 index 0000000000..5f8cfe7186 --- /dev/null +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/SetStickerSetThumb.kt @@ -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 { + 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" +} diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/abstracts/StandardStickerSetAction.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/abstracts/StandardStickerSetAction.kt new file mode 100644 index 0000000000..a4720e4a6c --- /dev/null +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/abstracts/StandardStickerSetAction.kt @@ -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? +} \ No newline at end of file diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/abstracts/StickerSetAction.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/abstracts/StickerSetAction.kt index 7563fb0752..7f051ebfc3 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/abstracts/StickerSetAction.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/stickers/abstracts/StickerSetAction.kt @@ -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.types.UserId -import com.github.insanusmokrassar.TelegramBotAPI.types.stickers.MaskPosition import kotlinx.serialization.KSerializer import kotlinx.serialization.builtins.serializer interface StickerSetAction : SimpleRequest { val userId: UserId val name: String - val emojis: String // must be more than one - val maskPosition: MaskPosition? override val resultDeserializer: KSerializer get() = Boolean.serializer() diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/BotCommand.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/BotCommand.kt new file mode 100644 index 0000000000..1e3e9ee01d --- /dev/null +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/BotCommand.kt @@ -0,0 +1,12 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class BotCommand( + @SerialName(botCommandField) + val command: String, + @SerialName(descriptionField) + val description: String +) diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt index f460b7b9e8..97b58db5d1 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt @@ -19,9 +19,11 @@ typealias InlineMessageIdentifier = String typealias PollIdentifier = String typealias StickerSetName = String typealias FileUniqueId = String +typealias DiceResult = Int typealias Seconds = Int +val getUpdatesLimit = 1 .. 100 val callbackQueryAnswerLength = 0 until 200 val captionLength = 0 until 1024 val textLength = 0 until 4096 @@ -45,6 +47,12 @@ val inlineQueryAnswerResultsLimit = 0 .. 50 val customTitleLength = 0 .. 16 +val diceResultLimit = 1 .. 6 + +val botCommandLimit = 1 .. 32 +val botCommandDescriptionLimit = 3 .. 256 +val botCommandsLimit = 0 .. 100 + const val chatIdField = "chat_id" const val messageIdField = "message_id" const val updateIdField = "update_id" @@ -164,6 +172,8 @@ const val thumbHeightField = "thumb_height" const val inputMessageContentField = "input_message_content" const val hideUrlField = "hide_url" +const val botCommandField = "command" +const val botCommandsField = "commands" const val isMemberField = "is_member" const val canSendMessagesField = "can_send_messages" @@ -183,6 +193,7 @@ const val canRestrictMembersField = "can_restrict_members" const val canPinMessagesField = "can_pin_messages" const val canPromoteMembersField = "can_promote_members" const val pngStickerField = "png_sticker" +const val tgsStickerField = "tgs_sticker" const val okField = "ok" const val captionField = "caption" @@ -230,6 +241,7 @@ const val optionsField = "options" const val payField = "pay" const val permissionsField = "permissions" const val typeField = "type" +const val valueField = "value" const val pointField = "point" const val xShiftField = "x_shift" diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Dice.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Dice.kt new file mode 100644 index 0000000000..00dd3f28ca --- /dev/null +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Dice.kt @@ -0,0 +1,10 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class Dice( + @SerialName(valueField) + val value: DiceResult +) diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt index 8e4ff44663..ae8efe3dbc 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt @@ -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.SuccessfulPayment import com.github.insanusmokrassar.TelegramBotAPI.types.polls.Poll -import kotlinx.serialization.* +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable import kotlin.reflect.KClass // TODO:: add PassportData type @@ -74,6 +75,7 @@ internal data class RawMessage( private val migrate_from_chat_id: ChatIdentifier? = null, private val pinned_message: RawMessage? = null, private val invoice: Invoice? = null, + private val dice: Dice? = null, private val successful_payment: SuccessfulPayment? = null, // login property @@ -123,6 +125,7 @@ internal data class RawMessage( adaptedCaptionEntities ) sticker != null -> StickerContent(sticker) + dice != null -> DiceContent(dice) game != null -> GameContent(game.asGame) video_note != null -> VideoNoteContent(video_note) contact != null -> ContactContent(contact) diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/DiceContent.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/DiceContent.kt new file mode 100644 index 0000000000..cafd35d3b8 --- /dev/null +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/content/DiceContent.kt @@ -0,0 +1,19 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.message.content + +import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.Request +import com.github.insanusmokrassar.TelegramBotAPI.requests.send.SendDice +import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.KeyboardMarkup +import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ContentMessage +import com.github.insanusmokrassar.TelegramBotAPI.types.message.content.abstracts.MessageContent + +data class DiceContent( + val dice: Dice +) : MessageContent { + override fun createResend( + chatId: ChatIdentifier, + disableNotification: Boolean, + replyToMessageId: MessageIdentifier?, + replyMarkup: KeyboardMarkup? + ): Request> = SendDice(chatId, disableNotification, replyToMessageId, replyMarkup) +} diff --git a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/stickers/StickerSet.kt b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/stickers/StickerSet.kt index b36fbc4016..bee7cfad1c 100644 --- a/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/stickers/StickerSet.kt +++ b/TelegramBotAPI/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/stickers/StickerSet.kt @@ -1,6 +1,7 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.stickers import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.files.PhotoSize import com.github.insanusmokrassar.TelegramBotAPI.types.files.Sticker import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -16,5 +17,7 @@ data class StickerSet( @SerialName(isAnimatedField) val isAnimated: Boolean = false, @SerialName(containsMasksField) - val containsMasks: Boolean = false + val containsMasks: Boolean = false, + @SerialName(thumbField) + val thumb: PhotoSize? = null ) diff --git a/gradle.properties b/gradle.properties index 87bf45babc..139532f266 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,11 +2,11 @@ kotlin.code.style=official kotlin_version=1.3.71 kotlin_coroutines_version=1.3.5 kotlin_serialisation_runtime_version=0.20.0 -klock_version=1.10.0 +klock_version=1.10.3 uuid_version=0.1.0 ktor_version=1.3.2 library_group=com.github.insanusmokrassar -library_version=0.25.1 +library_version=0.26.0 gradle_bintray_plugin_version=1.8.4