From 21d5031e4226580264ee08ae4ce5aed27aae1ab1 Mon Sep 17 00:00:00 2001 From: ForteScarlet Date: Mon, 22 Jul 2024 17:49:46 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat(api):=20=E6=94=AF=E6=8C=81=20`setMyCom?= =?UTF-8?q?mands`=20=E5=8E=9F=E5=A7=8BAPI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/bot/command/SetMyCommandsApi.kt | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 simbot-component-telegram-api/src/commonMain/kotlin/love/forte/simbot/telegram/api/bot/command/SetMyCommandsApi.kt diff --git a/simbot-component-telegram-api/src/commonMain/kotlin/love/forte/simbot/telegram/api/bot/command/SetMyCommandsApi.kt b/simbot-component-telegram-api/src/commonMain/kotlin/love/forte/simbot/telegram/api/bot/command/SetMyCommandsApi.kt new file mode 100644 index 0000000..7f67184 --- /dev/null +++ b/simbot-component-telegram-api/src/commonMain/kotlin/love/forte/simbot/telegram/api/bot/command/SetMyCommandsApi.kt @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2024. ForteScarlet. + * + * This file is part of simbot-component-telegram. + * + * simbot-component-telegram is free software: you can redistribute it and/or modify it under the terms + * of the GNU Lesser General Public License as published by the Free Software Foundation, + * either version 3 of the License, or (at your option) any later version. + * + * simbot-component-telegram is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with simbot-component-telegram. + * If not, see . + */ + +package love.forte.simbot.telegram.api.bot.command + +import kotlinx.serialization.DeserializationStrategy +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +import kotlinx.serialization.builtins.serializer +import love.forte.simbot.telegram.api.SimpleBodyTelegramApi +import love.forte.simbot.telegram.api.TelegramApiResult +import love.forte.simbot.telegram.type.BotCommand +import love.forte.simbot.telegram.type.BotCommandScope +import kotlin.jvm.JvmOverloads +import kotlin.jvm.JvmStatic + + +/** + * [setMyCommands](https://core.telegram.org/bots/api#setmycommands) + * Use this method to change the list of the bot's commands. + * See this manual for more details about bot commands. Returns True on success. + * + * @author ForteScarlet + */ +public class SetMyCommandsApi +private constructor(body: Body) : SimpleBodyTelegramApi() { + public companion object Factory { + private const val NAME = "setMyCommands" + + /** + * Create an instance of [SetMyCommandsApi]. + * + * @param commands A JSON-serialized list of bot commands to be set as the list of the bot's commands. + * At most 100 commands can be specified. + * @param scope A JSON-serialized object, describing scope of users for which the commands are relevant. + * Defaults to BotCommandScopeDefault. + * @param languageCode A two-letter ISO 639-1 language code. + * If empty, commands will be applied to all users from the given scope, + * for whose language there are no dedicated commands + */ + @JvmStatic + @JvmOverloads + public fun create( + commands: List, + scope: BotCommandScope? = null, + languageCode: String? = null, + ): SetMyCommandsApi = SetMyCommandsApi( + Body( + commands = commands, + scope = scope, + languageCode = languageCode + ) + ) + } + + /** + * Request body for [SetMyCommandsApi] + * @property commands A JSON-serialized list of bot commands to be set as the list of the bot's commands. + * At most 100 commands can be specified. + * @property scope A JSON-serialized object, describing scope of users for which the commands are relevant. + * Defaults to BotCommandScopeDefault. + * @property languageCode A two-letter ISO 639-1 language code. + * If empty, commands will be applied to all users from the given scope, + * for whose language there are no dedicated commands + */ + @Serializable + public data class Body( + val commands: List = emptyList(), + val scope: BotCommandScope? = null, + @SerialName("language_code") + val languageCode: String? = null, + ) + + override val name: String + get() = NAME + + override val body: Any = body + + override val responseDeserializer: DeserializationStrategy + get() = Boolean.serializer() + + override val resultDeserializer: DeserializationStrategy> + get() = TelegramApiResult.BooleanSerializer +} + +/* +Parameter Type Required Description + */ From c7790e182433113abb7d3e794df36209be899f8d Mon Sep 17 00:00:00 2001 From: ForteScarlet Date: Mon, 22 Jul 2024 17:52:40 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat(api):=20=E6=94=AF=E6=8C=81=20`deleteMy?= =?UTF-8?q?Commands`=20=E5=8E=9F=E5=A7=8BAPI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/bot/command/DeleteMyCommandsApi.kt | 102 ++++++++++++++++++ simbot-component-telegram-api/supports.md | 4 +- 2 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 simbot-component-telegram-api/src/commonMain/kotlin/love/forte/simbot/telegram/api/bot/command/DeleteMyCommandsApi.kt diff --git a/simbot-component-telegram-api/src/commonMain/kotlin/love/forte/simbot/telegram/api/bot/command/DeleteMyCommandsApi.kt b/simbot-component-telegram-api/src/commonMain/kotlin/love/forte/simbot/telegram/api/bot/command/DeleteMyCommandsApi.kt new file mode 100644 index 0000000..4665532 --- /dev/null +++ b/simbot-component-telegram-api/src/commonMain/kotlin/love/forte/simbot/telegram/api/bot/command/DeleteMyCommandsApi.kt @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2024. ForteScarlet. + * + * This file is part of simbot-component-telegram. + * + * simbot-component-telegram is free software: you can redistribute it and/or modify it under the terms + * of the GNU Lesser General Public License as published by the Free Software Foundation, + * either version 3 of the License, or (at your option) any later version. + * + * simbot-component-telegram is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License along with simbot-component-telegram. + * If not, see . + */ + +package love.forte.simbot.telegram.api.bot.command + +import kotlinx.serialization.DeserializationStrategy +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +import kotlinx.serialization.builtins.serializer +import love.forte.simbot.telegram.api.SimpleBodyTelegramApi +import love.forte.simbot.telegram.api.TelegramApiResult +import love.forte.simbot.telegram.type.BotCommandScope +import kotlin.jvm.JvmOverloads +import kotlin.jvm.JvmStatic + + +/** + * [deleteMyCommands](https://core.telegram.org/bots/api#deletemycommands) + * + * Use this method to delete the list of the bot's commands for the given scope and user language. + * After deletion, higher level commands will be shown to affected users. Returns True on success. + * + * @author ForteScarlet + */ +public class DeleteMyCommandsApi +private constructor(body: Body) : SimpleBodyTelegramApi() { + public companion object Factory { + private const val NAME = "deleteMyCommands" + private val EMPTY = DeleteMyCommandsApi(Body()) + + /** + * Create an instance of [DeleteMyCommandsApi]. + * + * @param scope A JSON-serialized object, describing scope of users for which the commands are relevant. + * Defaults to BotCommandScopeDefault. + * @param languageCode A two-letter ISO 639-1 language code. + * If empty, commands will be applied to all users from the given scope, + * for whose language there are no dedicated commands + */ + @JvmStatic + @JvmOverloads + public fun create( + scope: BotCommandScope? = null, + languageCode: String? = null, + ): DeleteMyCommandsApi { + return if (scope == null && languageCode == null) { + EMPTY + } else { + DeleteMyCommandsApi( + Body( + scope = scope, + languageCode = languageCode + ) + ) + } + } + } + + /** + * Request body for [DeleteMyCommandsApi] + * @property scope A JSON-serialized object, describing scope of users for which the commands are relevant. + * Defaults to BotCommandScopeDefault. + * @property languageCode A two-letter ISO 639-1 language code. + * If empty, commands will be applied to all users from the given scope, + * for whose language there are no dedicated commands + */ + @Serializable + public data class Body( + val scope: BotCommandScope? = null, + @SerialName("language_code") + val languageCode: String? = null, + ) + + override val name: String + get() = NAME + + override val body: Any = body + + override val responseDeserializer: DeserializationStrategy + get() = Boolean.serializer() + + override val resultDeserializer: DeserializationStrategy> + get() = TelegramApiResult.BooleanSerializer +} + +/* +Parameter Type Required Description + */ diff --git a/simbot-component-telegram-api/supports.md b/simbot-component-telegram-api/supports.md index fbca720..a4322d4 100644 --- a/simbot-component-telegram-api/supports.md +++ b/simbot-component-telegram-api/supports.md @@ -3,7 +3,9 @@ - [bot](src/commonMain/kotlin/love/forte/simbot/telegram/api/bot) - [x] [CloseApi](src/commonMain/kotlin/love/forte/simbot/telegram/api/bot/CloseApi.kt) - [command](src/commonMain/kotlin/love/forte/simbot/telegram/api/bot/command) + - [x] [DeleteMyCommandsApi](src/commonMain/kotlin/love/forte/simbot/telegram/api/bot/command/DeleteMyCommandsApi.kt) - [x] [GetMyCommandsApi](src/commonMain/kotlin/love/forte/simbot/telegram/api/bot/command/GetMyCommandsApi.kt) + - [x] [SetMyCommandsApi](src/commonMain/kotlin/love/forte/simbot/telegram/api/bot/command/SetMyCommandsApi.kt) - [x] [GetChatMenuButtonApi](src/commonMain/kotlin/love/forte/simbot/telegram/api/bot/GetChatMenuButtonApi.kt) - [x] [GetMeApi](src/commonMain/kotlin/love/forte/simbot/telegram/api/bot/GetMeApi.kt) - [x] [GetMyDefaultAdministratorRightsApi](src/commonMain/kotlin/love/forte/simbot/telegram/api/bot/GetMyDefaultAdministratorRightsApi.kt) @@ -38,4 +40,4 @@ - [x] [SetWebhookApi](src/commonMain/kotlin/love/forte/simbot/telegram/api/update/SetWebhookApi.kt) - [user](src/commonMain/kotlin/love/forte/simbot/telegram/api/user) - [x] [GetUserProfilePhotosApi](src/commonMain/kotlin/love/forte/simbot/telegram/api/user/GetUserProfilePhotosApi.kt) -- [ ] **Others not listed** +- [ ] **Others aren’t listed**