From 9014cdbc99b01e7144c421959bc5e63a6c3ab377 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 1 May 2022 16:41:47 +0600 Subject: [PATCH 1/4] start 0.38.17 --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73e15253e5..139208d678 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # TelegramBotAPI changelog +## 0.38.17 + ## 0.38.16 * `Core`: diff --git a/gradle.properties b/gradle.properties index b09681206c..6d60aca2f8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -20,6 +20,6 @@ javax_activation_version=1.1.1 dokka_version=1.6.10 library_group=dev.inmo -library_version=0.38.16 +library_version=0.38.17 github_release_plugin_version=2.3.7 From 92b4ba2ff05211e1510cc2456518c07922cef07d Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 1 May 2022 16:50:03 +0600 Subject: [PATCH 2/4] fix of #574 --- CHANGELOG.md | 3 +++ .../types/commands/BotCommandScope.kt | 21 ++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 139208d678..c29570f310 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 0.38.17 +* `Core`: + * Add `BotCommandScopeChat` as new `BotCommandScope` (fix of [#574](https://github.com/InsanusMokrassar/TelegramBotAPI/issues/574)) + ## 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..681a1c6baa 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) } } } @@ -94,6 +98,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, From 87fff2e5d094e86ff69687bb4d420c66b10e64f3 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 1 May 2022 17:18:44 +0600 Subject: [PATCH 3/4] add BotCommandScope helper extensions --- .../inmo/tgbotapi/types/commands/BotCommandScope.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 681a1c6baa..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 @@ -51,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 From 682f696866a1b5a1299ccb584080b44360824efd Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 1 May 2022 17:23:12 +0600 Subject: [PATCH 4/4] fill changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c29570f310..9ee4d9ba98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * `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