Skip to content

Commit 21d5031

Browse files
committed
feat(api): 支持 setMyCommands 原始API
1 parent 31bad7b commit 21d5031

File tree

1 file changed

+102
-0
lines changed
  • simbot-component-telegram-api/src/commonMain/kotlin/love/forte/simbot/telegram/api/bot/command

1 file changed

+102
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* Copyright (c) 2024. ForteScarlet.
3+
*
4+
* This file is part of simbot-component-telegram.
5+
*
6+
* simbot-component-telegram is free software: you can redistribute it and/or modify it under the terms
7+
* of the GNU Lesser General Public License as published by the Free Software Foundation,
8+
* either version 3 of the License, or (at your option) any later version.
9+
*
10+
* simbot-component-telegram is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
11+
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
* See the GNU Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public License along with simbot-component-telegram.
15+
* If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
package love.forte.simbot.telegram.api.bot.command
19+
20+
import kotlinx.serialization.DeserializationStrategy
21+
import kotlinx.serialization.SerialName
22+
import kotlinx.serialization.Serializable
23+
import kotlinx.serialization.builtins.serializer
24+
import love.forte.simbot.telegram.api.SimpleBodyTelegramApi
25+
import love.forte.simbot.telegram.api.TelegramApiResult
26+
import love.forte.simbot.telegram.type.BotCommand
27+
import love.forte.simbot.telegram.type.BotCommandScope
28+
import kotlin.jvm.JvmOverloads
29+
import kotlin.jvm.JvmStatic
30+
31+
32+
/**
33+
* [setMyCommands](https://core.telegram.org/bots/api#setmycommands)
34+
* Use this method to change the list of the bot's commands.
35+
* See this manual for more details about bot commands. Returns True on success.
36+
*
37+
* @author ForteScarlet
38+
*/
39+
public class SetMyCommandsApi
40+
private constructor(body: Body) : SimpleBodyTelegramApi<Boolean>() {
41+
public companion object Factory {
42+
private const val NAME = "setMyCommands"
43+
44+
/**
45+
* Create an instance of [SetMyCommandsApi].
46+
*
47+
* @param commands A JSON-serialized list of bot commands to be set as the list of the bot's commands.
48+
* At most 100 commands can be specified.
49+
* @param scope A JSON-serialized object, describing scope of users for which the commands are relevant.
50+
* Defaults to BotCommandScopeDefault.
51+
* @param languageCode A two-letter ISO 639-1 language code.
52+
* If empty, commands will be applied to all users from the given scope,
53+
* for whose language there are no dedicated commands
54+
*/
55+
@JvmStatic
56+
@JvmOverloads
57+
public fun create(
58+
commands: List<BotCommand>,
59+
scope: BotCommandScope? = null,
60+
languageCode: String? = null,
61+
): SetMyCommandsApi = SetMyCommandsApi(
62+
Body(
63+
commands = commands,
64+
scope = scope,
65+
languageCode = languageCode
66+
)
67+
)
68+
}
69+
70+
/**
71+
* Request body for [SetMyCommandsApi]
72+
* @property commands A JSON-serialized list of bot commands to be set as the list of the bot's commands.
73+
* At most 100 commands can be specified.
74+
* @property scope A JSON-serialized object, describing scope of users for which the commands are relevant.
75+
* Defaults to BotCommandScopeDefault.
76+
* @property languageCode A two-letter ISO 639-1 language code.
77+
* If empty, commands will be applied to all users from the given scope,
78+
* for whose language there are no dedicated commands
79+
*/
80+
@Serializable
81+
public data class Body(
82+
val commands: List<BotCommand> = emptyList(),
83+
val scope: BotCommandScope? = null,
84+
@SerialName("language_code")
85+
val languageCode: String? = null,
86+
)
87+
88+
override val name: String
89+
get() = NAME
90+
91+
override val body: Any = body
92+
93+
override val responseDeserializer: DeserializationStrategy<Boolean>
94+
get() = Boolean.serializer()
95+
96+
override val resultDeserializer: DeserializationStrategy<TelegramApiResult<Boolean>>
97+
get() = TelegramApiResult.BooleanSerializer
98+
}
99+
100+
/*
101+
Parameter Type Required Description
102+
*/

0 commit comments

Comments
 (0)