mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-09-03 07:09:23 +00:00
commands handling added
This commit is contained in:
@@ -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"
|
||||
|
Reference in New Issue
Block a user