1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-22 16:47:13 +00:00

*MyCommands actualization

This commit is contained in:
InsanusMokrassar 2021-06-26 01:42:35 +06:00
parent b60fab4871
commit 7f69052dea
9 changed files with 79 additions and 9 deletions

View File

@ -14,6 +14,7 @@
* `Bot API 5.3`:
* Add type `BotCommandScope`, its serializer `BotCommandScopeSerializer` and all its children
* New request `DeleteMyCommands` and updates in `GetMyCommands` and `SetMyCommands`
## 0.35.0

View File

@ -0,0 +1,9 @@
package dev.inmo.tgbotapi.requests.bot
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
import dev.inmo.tgbotapi.types.commands.BotCommandScope
sealed interface MyCommandsRequest<T : Any> : SimpleRequest<T> {
val scope: BotCommandScope
val languageCode: String?
}

View File

@ -0,0 +1,22 @@
package dev.inmo.tgbotapi.requests.bot
import dev.inmo.tgbotapi.types.commands.*
import dev.inmo.tgbotapi.types.languageCodeField
import dev.inmo.tgbotapi.types.scopeField
import kotlinx.serialization.*
import kotlinx.serialization.builtins.serializer
@Serializable
data class DeleteMyCommands(
@SerialName(scopeField)
@Serializable(BotCommandScopeSerializer::class)
override val scope: BotCommandScope = BotCommandScopeDefault,
@SerialName(languageCodeField)
override val languageCode: String? = null
) : MyCommandsRequest<Boolean> {
override fun method(): String = "deleteMyCommands"
override val requestSerializer: SerializationStrategy<DeleteMyCommands> = serializer()
override val resultDeserializer: DeserializationStrategy<Boolean> = Boolean.serializer()
companion object : MyCommandsRequest<Boolean> by DeleteMyCommands()
}

View File

@ -1,17 +1,26 @@
package dev.inmo.tgbotapi.requests.bot
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
import dev.inmo.tgbotapi.types.BotCommand
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.commands.*
import kotlinx.serialization.*
import kotlinx.serialization.builtins.ListSerializer
private val getMyCommandsSerializer = ListSerializer(BotCommand.serializer())
@Serializable
object GetMyCommands : SimpleRequest<List<BotCommand>> {
data class GetMyCommands(
@SerialName(scopeField)
@Serializable(BotCommandScopeSerializer::class)
override val scope: BotCommandScope = BotCommandScopeDefault,
@SerialName(languageCodeField)
override val languageCode: String? = null
) : MyCommandsRequest<List<BotCommand>> {
override fun method(): String = "getMyCommands"
override val resultDeserializer: DeserializationStrategy<List<BotCommand>>
get() = getMyCommandsSerializer
override val requestSerializer: SerializationStrategy<*>
get() = serializer()
companion object : MyCommandsRequest<List<BotCommand>> by GetMyCommands()
}

View File

@ -2,14 +2,20 @@ package dev.inmo.tgbotapi.requests.bot
import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest
import dev.inmo.tgbotapi.types.*
import dev.inmo.tgbotapi.types.commands.*
import kotlinx.serialization.*
import kotlinx.serialization.builtins.serializer
@Serializable
class SetMyCommands(
@SerialName(botCommandsField)
val commands: List<BotCommand>
) : SimpleRequest<Boolean> {
val commands: List<BotCommand>,
@SerialName(scopeField)
@Serializable(BotCommandScopeSerializer::class)
override val scope: BotCommandScope = BotCommandScopeDefault,
@SerialName(languageCodeField)
override val languageCode: String? = null
) : MyCommandsRequest<Boolean> {
override fun method(): String = "setMyCommands"
override val resultDeserializer: DeserializationStrategy<Boolean>
get() = Boolean.serializer()

View File

@ -234,6 +234,7 @@ const val hideUrlField = "hide_url"
const val botCommandField = "command"
const val botCommandsField = "commands"
const val scopeField = "scope"
const val isMemberField = "is_member"
const val canSendMessagesField = "can_send_messages"

View File

@ -0,0 +1,11 @@
package dev.inmo.tgbotapi.extensions.api.bot
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.bot.DeleteMyCommands
import dev.inmo.tgbotapi.types.commands.BotCommandScope
import dev.inmo.tgbotapi.types.commands.BotCommandScopeDefault
suspend fun TelegramBot.deleteMyCommands(
scope: BotCommandScope = BotCommandScopeDefault,
languageCode: String? = null
) = execute(DeleteMyCommands(scope, languageCode))

View File

@ -2,5 +2,10 @@ package dev.inmo.tgbotapi.extensions.api.bot
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.bot.GetMyCommands
import dev.inmo.tgbotapi.types.commands.BotCommandScope
import dev.inmo.tgbotapi.types.commands.BotCommandScopeDefault
suspend fun TelegramBot.getMyCommands() = execute(GetMyCommands)
suspend fun TelegramBot.getMyCommands(
scope: BotCommandScope = BotCommandScopeDefault,
languageCode: String? = null
) = execute(GetMyCommands(scope, languageCode))

View File

@ -3,11 +3,17 @@ package dev.inmo.tgbotapi.extensions.api.bot
import dev.inmo.tgbotapi.bot.TelegramBot
import dev.inmo.tgbotapi.requests.bot.SetMyCommands
import dev.inmo.tgbotapi.types.BotCommand
import dev.inmo.tgbotapi.types.commands.BotCommandScope
import dev.inmo.tgbotapi.types.commands.BotCommandScopeDefault
suspend fun TelegramBot.setMyCommands(
commands: List<BotCommand>
) = execute(SetMyCommands(commands))
commands: List<BotCommand>,
scope: BotCommandScope = BotCommandScopeDefault,
languageCode: String? = null
) = execute(SetMyCommands(commands, scope, languageCode))
suspend fun TelegramBot.setMyCommands(
vararg commands: BotCommand
) = setMyCommands(commands.toList())
vararg commands: BotCommand,
scope: BotCommandScope = BotCommandScopeDefault,
languageCode: String? = null
) = setMyCommands(commands.toList(), scope, languageCode)