1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-26 03:58:44 +00:00

Merge pull request #575 from InsanusMokrassar/0.38.17

0.38.17
This commit is contained in:
InsanusMokrassar 2022-05-01 17:23:33 +06:00 committed by GitHub
commit a52f31f4c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 4 deletions

View File

@ -1,5 +1,11 @@
# TelegramBotAPI changelog # TelegramBotAPI changelog
## 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 ## 0.38.16
* `Core`: * `Core`:

View File

@ -20,6 +20,6 @@ javax_activation_version=1.1.1
dokka_version=1.6.10 dokka_version=1.6.10
library_group=dev.inmo library_group=dev.inmo
library_version=0.38.16 library_version=0.38.17
github_release_plugin_version=2.3.7 github_release_plugin_version=2.3.7

View File

@ -22,11 +22,14 @@ private class SurrogateBotCommandScope(
BotCommandScopeAllGroupChats.type -> BotCommandScopeAllGroupChats BotCommandScopeAllGroupChats.type -> BotCommandScopeAllGroupChats
BotCommandScopeAllChatAdministrators.type -> BotCommandScopeAllChatAdministrators BotCommandScopeAllChatAdministrators.type -> BotCommandScopeAllChatAdministrators
BotCommandScopeChatAdministrators.type -> BotCommandScopeChatAdministrators( 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( BotCommandScopeChatMember.type -> BotCommandScopeChatMember(
chatId ?: error("chat_administrators type must have $chatIdField field, but have no"), chatId ?: error("${BotCommandScopeChatMember.type} type must have $chatIdField field, but have no"),
userId ?: error("chat_administrators type must have $userIdField 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) else -> UnknownBotCommandScope(type)
} }
@ -40,6 +43,7 @@ private class SurrogateBotCommandScope(
BotCommandScopeAllChatAdministrators -> SurrogateBotCommandScope(scope.type) BotCommandScopeAllChatAdministrators -> SurrogateBotCommandScope(scope.type)
is BotCommandScopeChatAdministrators -> SurrogateBotCommandScope(scope.type, scope.chatId) is BotCommandScopeChatAdministrators -> SurrogateBotCommandScope(scope.type, scope.chatId)
is BotCommandScopeChatMember -> SurrogateBotCommandScope(scope.type, scope.chatId, scope.userId) 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) @Serializable(BotCommandScopeSerializer::class)
sealed interface BotCommandScope { sealed interface BotCommandScope {
val type: String 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 @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 @Serializable
data class BotCommandScopeChatMember( data class BotCommandScopeChatMember(
override val chatId: ChatIdentifier, override val chatId: ChatIdentifier,