mirror of
				https://github.com/InsanusMokrassar/TelegramBotAPI.git
				synced 2025-10-25 09:10:07 +00:00 
			
		
		
		
	*MyCommands actualization
This commit is contained in:
		| @@ -14,6 +14,7 @@ | |||||||
|      |      | ||||||
| * `Bot API 5.3`: | * `Bot API 5.3`: | ||||||
|     * Add type `BotCommandScope`, its serializer `BotCommandScopeSerializer` and all its children |     * Add type `BotCommandScope`, its serializer `BotCommandScopeSerializer` and all its children | ||||||
|  |     * New request `DeleteMyCommands` and updates in `GetMyCommands` and `SetMyCommands` | ||||||
|  |  | ||||||
| ## 0.35.0 | ## 0.35.0 | ||||||
|  |  | ||||||
|   | |||||||
| @@ -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? | ||||||
|  | } | ||||||
| @@ -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() | ||||||
|  | } | ||||||
| @@ -1,17 +1,26 @@ | |||||||
| package dev.inmo.tgbotapi.requests.bot | package dev.inmo.tgbotapi.requests.bot | ||||||
|  |  | ||||||
| import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest | 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.* | ||||||
| import kotlinx.serialization.builtins.ListSerializer | import kotlinx.serialization.builtins.ListSerializer | ||||||
|  |  | ||||||
| private val getMyCommandsSerializer = ListSerializer(BotCommand.serializer()) | private val getMyCommandsSerializer = ListSerializer(BotCommand.serializer()) | ||||||
|  |  | ||||||
| @Serializable | @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 fun method(): String = "getMyCommands" | ||||||
|     override val resultDeserializer: DeserializationStrategy<List<BotCommand>> |     override val resultDeserializer: DeserializationStrategy<List<BotCommand>> | ||||||
|         get() = getMyCommandsSerializer |         get() = getMyCommandsSerializer | ||||||
|     override val requestSerializer: SerializationStrategy<*> |     override val requestSerializer: SerializationStrategy<*> | ||||||
|         get() = serializer() |         get() = serializer() | ||||||
|  |  | ||||||
|  |     companion object : MyCommandsRequest<List<BotCommand>> by GetMyCommands() | ||||||
| } | } | ||||||
|   | |||||||
| @@ -2,14 +2,20 @@ package dev.inmo.tgbotapi.requests.bot | |||||||
|  |  | ||||||
| import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest | import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest | ||||||
| import dev.inmo.tgbotapi.types.* | import dev.inmo.tgbotapi.types.* | ||||||
|  | import dev.inmo.tgbotapi.types.commands.* | ||||||
| import kotlinx.serialization.* | import kotlinx.serialization.* | ||||||
| import kotlinx.serialization.builtins.serializer | import kotlinx.serialization.builtins.serializer | ||||||
|  |  | ||||||
| @Serializable | @Serializable | ||||||
| class SetMyCommands( | class SetMyCommands( | ||||||
|     @SerialName(botCommandsField) |     @SerialName(botCommandsField) | ||||||
|     val commands: List<BotCommand> |     val commands: List<BotCommand>, | ||||||
| ) : SimpleRequest<Boolean> { |     @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 fun method(): String = "setMyCommands" | ||||||
|     override val resultDeserializer: DeserializationStrategy<Boolean> |     override val resultDeserializer: DeserializationStrategy<Boolean> | ||||||
|         get() = Boolean.serializer() |         get() = Boolean.serializer() | ||||||
|   | |||||||
| @@ -234,6 +234,7 @@ const val hideUrlField = "hide_url" | |||||||
|  |  | ||||||
| const val botCommandField = "command" | const val botCommandField = "command" | ||||||
| const val botCommandsField = "commands" | const val botCommandsField = "commands" | ||||||
|  | const val scopeField = "scope" | ||||||
|  |  | ||||||
| const val isMemberField = "is_member" | const val isMemberField = "is_member" | ||||||
| const val canSendMessagesField = "can_send_messages" | const val canSendMessagesField = "can_send_messages" | ||||||
|   | |||||||
| @@ -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)) | ||||||
| @@ -2,5 +2,10 @@ package dev.inmo.tgbotapi.extensions.api.bot | |||||||
|  |  | ||||||
| import dev.inmo.tgbotapi.bot.TelegramBot | import dev.inmo.tgbotapi.bot.TelegramBot | ||||||
| import dev.inmo.tgbotapi.requests.bot.GetMyCommands | 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)) | ||||||
|   | |||||||
| @@ -3,11 +3,17 @@ package dev.inmo.tgbotapi.extensions.api.bot | |||||||
| import dev.inmo.tgbotapi.bot.TelegramBot | import dev.inmo.tgbotapi.bot.TelegramBot | ||||||
| import dev.inmo.tgbotapi.requests.bot.SetMyCommands | import dev.inmo.tgbotapi.requests.bot.SetMyCommands | ||||||
| import dev.inmo.tgbotapi.types.BotCommand | import dev.inmo.tgbotapi.types.BotCommand | ||||||
|  | import dev.inmo.tgbotapi.types.commands.BotCommandScope | ||||||
|  | import dev.inmo.tgbotapi.types.commands.BotCommandScopeDefault | ||||||
|  |  | ||||||
| suspend fun TelegramBot.setMyCommands( | suspend fun TelegramBot.setMyCommands( | ||||||
|     commands: List<BotCommand> |     commands: List<BotCommand>, | ||||||
| ) = execute(SetMyCommands(commands)) |     scope: BotCommandScope = BotCommandScopeDefault, | ||||||
|  |     languageCode: String? = null | ||||||
|  | ) = execute(SetMyCommands(commands, scope, languageCode)) | ||||||
|  |  | ||||||
| suspend fun TelegramBot.setMyCommands( | suspend fun TelegramBot.setMyCommands( | ||||||
|     vararg commands: BotCommand |     vararg commands: BotCommand, | ||||||
| ) = setMyCommands(commands.toList()) |     scope: BotCommandScope = BotCommandScopeDefault, | ||||||
|  |     languageCode: String? = null | ||||||
|  | ) = setMyCommands(commands.toList(), scope, languageCode) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user