mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-26 03:58:44 +00:00
commands handling added
This commit is contained in:
parent
54589ed17b
commit
ec70813e49
@ -32,8 +32,15 @@
|
|||||||
* Class `Dice` was added (type [dice](https://core.telegram.org/bots/api#dice))
|
* 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)
|
* Class `DiceContent` was added (for including it in [message](https://core.telegram.org/bots/api#message) object)
|
||||||
* `BotCommand` was added
|
* `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`
|
||||||
* `TelegramBotAPI-extensions-api`:
|
* `TelegramBotAPI-extensions-api`:
|
||||||
* Extensions `sendDice` was added
|
* 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`
|
||||||
|
|
||||||
### 0.25.1
|
### 0.25.1
|
||||||
|
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.extensions.api
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.api
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.bot.RequestsExecutor
|
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())
|
@Deprecated(
|
||||||
|
"Replaced",
|
||||||
|
ReplaceWith("getMe", "com.github.insanusmokrassar.TelegramBotAPI.extensions.api.bot.GetMeKt.getMe")
|
||||||
|
)
|
||||||
|
suspend fun RequestsExecutor.getMe() = getMe()
|
@ -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)
|
@ -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)
|
@ -0,0 +1,10 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.extensions.api.bot
|
||||||
|
|
||||||
|
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.types.BotCommand
|
||||||
|
|
||||||
|
suspend fun RequestsExecutor.setMyCommands(
|
||||||
|
commands: List<BotCommand>
|
||||||
|
) = execute(SetMyCommands(commands))
|
@ -1,14 +1,11 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.requests
|
package com.github.insanusmokrassar.TelegramBotAPI.requests
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.bot.GetMe
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ExtendedBot
|
|
||||||
import kotlinx.serialization.*
|
|
||||||
|
|
||||||
@Serializable
|
@Deprecated(
|
||||||
class GetMe : SimpleRequest<ExtendedBot> {
|
"Replaced",
|
||||||
override fun method(): String = "getMe"
|
ReplaceWith(
|
||||||
override val resultDeserializer: DeserializationStrategy<ExtendedBot>
|
"GetMe", "com.github.insanusmokrassar.TelegramBotAPI.requests.bot.GetMe"
|
||||||
get() = ExtendedBot.serializer()
|
)
|
||||||
override val requestSerializer: SerializationStrategy<*>
|
)
|
||||||
get() = serializer()
|
typealias GetMe = GetMe
|
||||||
}
|
|
||||||
|
@ -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<ExtendedBot> {
|
||||||
|
override fun method(): String = "getMe"
|
||||||
|
override val resultDeserializer: DeserializationStrategy<ExtendedBot>
|
||||||
|
get() = ExtendedBot.serializer()
|
||||||
|
override val requestSerializer: SerializationStrategy<*>
|
||||||
|
get() = serializer()
|
||||||
|
}
|
@ -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<List<BotCommand>> {
|
||||||
|
override fun method(): String = "getMyCommands"
|
||||||
|
override val resultDeserializer: DeserializationStrategy<List<BotCommand>>
|
||||||
|
get() = getMyCommandsSerializer
|
||||||
|
override val requestSerializer: SerializationStrategy<*>
|
||||||
|
get() = serializer()
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
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.ListSerializer
|
||||||
|
import kotlinx.serialization.builtins.serializer
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
class SetMyCommands(
|
||||||
|
@SerialName(botCommandsField)
|
||||||
|
val commands: List<BotCommand>
|
||||||
|
) : SimpleRequest<Boolean> {
|
||||||
|
override fun method(): String = "getMyCommands"
|
||||||
|
override val resultDeserializer: DeserializationStrategy<Boolean>
|
||||||
|
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}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -50,6 +50,7 @@ val diceResultLimit = 1 .. 6
|
|||||||
|
|
||||||
val botCommandLimit = 1 .. 32
|
val botCommandLimit = 1 .. 32
|
||||||
val botCommandDescriptionLimit = 3 .. 256
|
val botCommandDescriptionLimit = 3 .. 256
|
||||||
|
val botCommandsLimit = 0 .. 100
|
||||||
|
|
||||||
const val chatIdField = "chat_id"
|
const val chatIdField = "chat_id"
|
||||||
const val messageIdField = "message_id"
|
const val messageIdField = "message_id"
|
||||||
@ -171,6 +172,7 @@ const val inputMessageContentField = "input_message_content"
|
|||||||
const val hideUrlField = "hide_url"
|
const val hideUrlField = "hide_url"
|
||||||
|
|
||||||
const val botCommandField = "command"
|
const val botCommandField = "command"
|
||||||
|
const val botCommandsField = "commands"
|
||||||
|
|
||||||
const val isMemberField = "is_member"
|
const val isMemberField = "is_member"
|
||||||
const val canSendMessagesField = "can_send_messages"
|
const val canSendMessagesField = "can_send_messages"
|
||||||
|
Loading…
Reference in New Issue
Block a user