diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f414ba703..17e9100d37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,12 @@ __All the `tgbotapi.extensions.*` packages have been removed__ * `BehaviourBuilder`: * `SimpleFilter` now is a `fun interface` instead of just callback (fix of [#546](https://github.com/InsanusMokrassar/TelegramBotAPI/issues/546)) +## 0.38.17 + +* `Core`: + * Add `BotCommandScopeChat` as new `BotCommandScope` (fix of [#574](https://github.com/InsanusMokrassar/TelegramBotAPI/issues/574)) + * `BotCommandScope` companion got several properties and functions for more useful scope creation + ## 0.38.16 * `Core`: diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/commands/BotCommandScope.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/commands/BotCommandScope.kt index 9fa0b953d2..ce1aa93bee 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/commands/BotCommandScope.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/commands/BotCommandScope.kt @@ -22,11 +22,14 @@ private class SurrogateBotCommandScope( BotCommandScopeAllGroupChats.type -> BotCommandScopeAllGroupChats BotCommandScopeAllChatAdministrators.type -> BotCommandScopeAllChatAdministrators BotCommandScopeChatAdministrators.type -> BotCommandScopeChatAdministrators( - chatId ?: error("chat_administrators type must have $chatIdField field, but have no") + chatId ?: error("${BotCommandScopeChatAdministrators.type} type must have $chatIdField field, but have no") ) BotCommandScopeChatMember.type -> BotCommandScopeChatMember( - chatId ?: error("chat_administrators type must have $chatIdField field, but have no"), - userId ?: error("chat_administrators type must have $userIdField field, but have no") + chatId ?: error("${BotCommandScopeChatMember.type} type must have $chatIdField field, but have no"), + userId ?: error("${BotCommandScopeChatMember.type} type must have $userIdField field, but have no") + ) + BotCommandScopeChat.type -> BotCommandScopeChat( + chatId ?: error("${BotCommandScopeChat.type} type must have $chatIdField field, but have no") ) else -> UnknownBotCommandScope(type) } @@ -40,6 +43,7 @@ private class SurrogateBotCommandScope( BotCommandScopeAllChatAdministrators -> SurrogateBotCommandScope(scope.type) is BotCommandScopeChatAdministrators -> SurrogateBotCommandScope(scope.type, scope.chatId) is BotCommandScopeChatMember -> SurrogateBotCommandScope(scope.type, scope.chatId, scope.userId) + is BotCommandScopeChat -> SurrogateBotCommandScope(scope.type, scope.chatId) } } } @@ -47,6 +51,16 @@ private class SurrogateBotCommandScope( @Serializable(BotCommandScopeSerializer::class) sealed interface BotCommandScope { val type: String + + companion object { + val Default = BotCommandScopeDefault + val AllPrivateChats = BotCommandScopeAllPrivateChats + val AllGroupChats = BotCommandScopeAllGroupChats + val AllChatAdministrators = BotCommandScopeAllChatAdministrators + fun ChatAdministrators(chatId: ChatIdentifier) = BotCommandScopeChatAdministrators(chatId) + fun Chat(chatId: ChatIdentifier) = BotCommandScopeChat(chatId) + fun ChatMember(chatId: ChatIdentifier, userId: UserId) = BotCommandScopeChatMember(chatId, userId) + } } @Serializable @@ -94,6 +108,17 @@ data class BotCommandScopeChatAdministrators( } } +@Serializable +data class BotCommandScopeChat( + override val chatId: ChatIdentifier +) : ChatBotCommandScope { + @Required + override val type: String = BotCommandScopeChat.type + companion object { + const val type = "chat" + } +} + @Serializable data class BotCommandScopeChatMember( override val chatId: ChatIdentifier,