mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 08:13:47 +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 `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`
|
||||
* `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`
|
||||
|
||||
### 0.25.1
|
||||
|
||||
|
@ -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())
|
||||
@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
|
||||
|
||||
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<ExtendedBot> {
|
||||
override fun method(): String = "getMe"
|
||||
override val resultDeserializer: DeserializationStrategy<ExtendedBot>
|
||||
get() = ExtendedBot.serializer()
|
||||
override val requestSerializer: SerializationStrategy<*>
|
||||
get() = serializer()
|
||||
}
|
||||
@Deprecated(
|
||||
"Replaced",
|
||||
ReplaceWith(
|
||||
"GetMe", "com.github.insanusmokrassar.TelegramBotAPI.requests.bot.GetMe"
|
||||
)
|
||||
)
|
||||
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 botCommandDescriptionLimit = 3 .. 256
|
||||
val botCommandsLimit = 0 .. 100
|
||||
|
||||
const val chatIdField = "chat_id"
|
||||
const val messageIdField = "message_id"
|
||||
@ -171,6 +172,7 @@ 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"
|
||||
|
Loading…
Reference in New Issue
Block a user