From d6bb14e3424734f920d3d620edaf4a76725c823a Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 12 Aug 2019 15:15:22 +0600 Subject: [PATCH] total rework of chats --- CHANGELOG.md | 13 +++- .../bot/exceptions/HandleException.kt | 15 ++++ .../chat/stickers/SetChatStickerSet.kt | 2 +- .../TelegramBotAPI/types/Common.kt | 1 + .../{PrivateChat.kt => ChannelChatImpl.kt} | 15 ++-- .../TelegramBotAPI/types/chat/Chat.kt | 9 --- .../TelegramBotAPI/types/chat/GroupChat.kt | 9 --- .../types/chat/GroupChatImpl.kt | 7 +- .../types/chat/PrivateChatImpl.kt | 11 +++ .../TelegramBotAPI/types/chat/PublicChat.kt | 9 --- .../TelegramBotAPI/types/chat/RawChat.kt | 73 ++++++++++++++----- .../types/chat/SupergroupChat.kt | 19 ----- .../{ChannelChat.kt => SupergroupChatImpl.kt} | 15 ++-- .../{DescriptionChat.kt => ChannelChat.kt} | 4 +- .../types/chat/abstracts/Chat.kt | 1 - .../types/chat/abstracts/GroupChat.kt | 6 +- .../types/chat/abstracts/PrivateChat.kt | 6 ++ .../types/chat/abstracts/PublicChat.kt | 6 +- .../types/chat/abstracts/SuperPublicChat.kt | 3 + .../types/chat/abstracts/SupergroupChat.kt | 3 + .../abstracts/extended/ExtendedChannelChat.kt | 5 ++ .../chat/abstracts/extended/ExtendedChat.kt | 8 ++ .../abstracts/extended/ExtendedGroupChat.kt | 8 ++ .../abstracts/extended/ExtendedPrivateChat.kt | 5 ++ .../abstracts/extended/ExtendedPublicChat.kt | 10 +++ .../extended/ExtendedSupergroupChat.kt | 9 +++ .../chat/extended/ExtendedChannelChatImpl.kt | 15 ++++ .../chat/extended/ExtendedGroupChatImpl.kt | 17 +++++ .../chat/extended/ExtendedPrivateChatImpl.kt | 12 +++ .../extended/ExtendedSupergroupChatImpl.kt | 19 +++++ .../TelegramBotAPI/types/files/Sticker.kt | 2 +- .../types/message/ChannelEventMessage.kt | 3 +- .../types/message/RawMessage.kt | 14 ++-- .../types/message/SupergroupEventMessage.kt | 3 +- 34 files changed, 240 insertions(+), 117 deletions(-) create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/exceptions/HandleException.kt rename src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/{PrivateChat.kt => ChannelChatImpl.kt} (53%) delete mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/Chat.kt delete mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChat.kt create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PrivateChatImpl.kt delete mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PublicChat.kt delete mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChat.kt rename src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/{ChannelChat.kt => SupergroupChatImpl.kt} (50%) rename src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/{DescriptionChat.kt => ChannelChat.kt} (50%) create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/PrivateChat.kt create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/SuperPublicChat.kt create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/SupergroupChat.kt create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedChannelChat.kt create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedChat.kt create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedGroupChat.kt create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedPrivateChat.kt create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedPublicChat.kt create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedSupergroupChat.kt create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedChannelChatImpl.kt create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedGroupChatImpl.kt create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedPrivateChatImpl.kt create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedSupergroupChatImpl.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 1176d6f5cc..586dbea97f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,16 +2,14 @@ ## 0.17.0 +Libraries updates: + * Kotlin version `1.3.31` -> `1.3.41` * Kotlin Coroutines version `1.2.1` -> `1.2.2` * Kotlin Serialization version `0.11.0` -> `0.11.1` * Joda Time version `2.10.1` -> `2.10.3` * Ktor version `1.1.4` -> `1.2.2` -* `RequestsExecutor` now is `Closeable` -* `TelegramAPIUrlsKeeper` was added to provide more comfortable work with file urls and other things -like this - Changes according to [July 29, 2019 Telegram Bot API update](https://core.telegram.org/bots/api#july-29-2019): * `Sticker` and `StickerSet` now have field `isAnimated` @@ -22,6 +20,13 @@ was replaced into `abstracts` package and available permissions was updated * `RestrictChatMember` request now accept `permissions` object instead of separated permissions * All `GroupChat` instances have description +Other important changes: + +* Totally reworked chats hierarchy. `Extended` abstractions was added for cases when called `GetChat` request +* `RequestsExecutor` now is `Closeable` +* `TelegramAPIUrlsKeeper` was added to provide more comfortable work with file urls and other things +like this + ## 0.16.0 Bot API 4.3 * `LoginURL` and `LoginURLInlineKeyboardButton` has been added diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/exceptions/HandleException.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/exceptions/HandleException.kt new file mode 100644 index 0000000000..9c147a59b5 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/exceptions/HandleException.kt @@ -0,0 +1,15 @@ +package com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions + +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.RawChat + +sealed class HandleException ( + message: String +) : IllegalArgumentException( + message +) + +class IllegalChatRawObjectException( + rawChat: RawChat +) : HandleException( + "One of the fields in raw chat object is incorrect" +) diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/SetChatStickerSet.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/SetChatStickerSet.kt index 4e0d4519fa..3452572914 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/SetChatStickerSet.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/stickers/SetChatStickerSet.kt @@ -11,7 +11,7 @@ data class SetChatStickerSet( @SerialName(chatIdField) override val chatId: ChatIdentifier, @SerialName(stickerSetNameField) - val stickerSetName: String + val stickerSetName: StickerSetName ): ChatRequest, SimpleRequest { override fun method(): String = "setChatStickerSet" override fun resultSerializer(): KSerializer = BooleanSerializer diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt index cc73690882..2c2cf8c768 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt @@ -17,6 +17,7 @@ typealias ShippingOptionIdentifier = String typealias StartParameter = String typealias InlineMessageIdentifier = String typealias PollIdentifier = String +typealias StickerSetName = String val callbackQueryAnswerLength = 0 until 200 val captionLength = 0 until 1024 diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PrivateChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChannelChatImpl.kt similarity index 53% rename from src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PrivateChat.kt rename to src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChannelChatImpl.kt index 0f7f79fd7b..c10fc3ab98 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PrivateChat.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChannelChatImpl.kt @@ -1,13 +1,12 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat import com.github.insanusmokrassar.TelegramBotAPI.types.* -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.UsernameChat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.* +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat +import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage -data class PrivateChat( +data class ChannelChatImpl( override val id: ChatId, - override val username: Username? = null, - val firstName: String? = null, - val lastName: String? = null, - override val chatPhoto: ChatPhoto? = null -) : Chat, UsernameChat + override val title: String, + override val username: Username? = null +) : ChannelChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/Chat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/Chat.kt deleted file mode 100644 index 9f38f83d41..0000000000 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/Chat.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.github.insanusmokrassar.TelegramBotAPI.types.chat - -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat - -@Deprecated( - "Replaced into another package", - ReplaceWith("Chat", "com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat") -) -typealias Chat = Chat \ No newline at end of file diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChat.kt deleted file mode 100644 index 570d671d1a..0000000000 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChat.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.github.insanusmokrassar.TelegramBotAPI.types.chat - -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat - -@Deprecated( - "Replaced into another package", - ReplaceWith("GroupChat", "com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat") -) -typealias GroupChat = GroupChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChatImpl.kt index 38e5cd5d7c..4959f2077a 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChatImpl.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChatImpl.kt @@ -7,10 +7,5 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage data class GroupChatImpl( override val id: ChatId, - override val title: String? = null, - override val description: String? = null, - override val inviteLink: String? = null, - override val chatPhoto: ChatPhoto? = null, - override val pinnedMessage: RawMessage? = null, - override val permissions: ChatPermissions? = null + override val title: String ) : GroupChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PrivateChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PrivateChatImpl.kt new file mode 100644 index 0000000000..c8a8f837f1 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PrivateChatImpl.kt @@ -0,0 +1,11 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.chat + +import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.* + +data class PrivateChatImpl( + override val id: ChatId, + override val username: Username? = null, + override val firstName: String = "", + override val lastName: String = "" +) : PrivateChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PublicChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PublicChat.kt deleted file mode 100644 index fbfb55226d..0000000000 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PublicChat.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.github.insanusmokrassar.TelegramBotAPI.types.chat - -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat - -@Deprecated( - "Replaced into another package", - ReplaceWith("PublicChat", "com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat") -) -typealias PublicChat = PublicChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/RawChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/RawChat.kt index cd00c25e6c..e04894c535 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/RawChat.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/RawChat.kt @@ -1,7 +1,10 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat +import com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.IllegalChatRawObjectException import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.extended.* import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -20,43 +23,75 @@ data class RawChat( private val sticker_set_name: String? = null, private val can_set_sticker_set: Boolean? = null, @SerialName("photo") - override val chatPhoto: ChatPhoto? = null, + private val chatPhoto: ChatPhoto? = null, private val permissions: ChatPermissions? = null ) : Chat { - fun extractChat(): Chat { + private fun extractExtendedChat(): ExtendedChat { return when (type) { - "private" -> PrivateChat(id, username, first_name, last_name, chatPhoto) - "group" -> GroupChatImpl( + "private" -> ExtendedPrivateChatImpl(id, username, first_name ?: "", last_name ?: "", chatPhoto!!) + "group" -> ExtendedGroupChatImpl( id, - title, - description, + title!!, + chatPhoto!!, + description ?: "", invite_link, - chatPhoto, - pinned_message, - permissions + permissions!!, + pinned_message ) - "supergroup" -> SupergroupChat( + "supergroup" -> ExtendedSupergroupChatImpl( id, - title, + title!!, username, - description, + chatPhoto!!, + description ?: "", invite_link, - chatPhoto, + permissions!!, pinned_message, sticker_set_name, - can_set_sticker_set ?: false, - permissions + can_set_sticker_set ?: false ) - "channel" -> ChannelChat( + "channel" -> ExtendedChannelChatImpl( id, - title, + title!!, username, - description, + chatPhoto!!, + description ?: "", invite_link, - chatPhoto, pinned_message ) else -> throw IllegalArgumentException("Unknown type of chat") } } + + private fun extractPreviewChat(): Chat { + return when (type) { + "private" -> PrivateChatImpl(id, username, first_name ?: "", last_name ?: "") + "group" -> GroupChatImpl( + id, + title!! + ) + "supergroup" -> SupergroupChatImpl( + id, + title!!, + username + ) + "channel" -> ChannelChatImpl( + id, + title!!, + username + ) + else -> throw IllegalArgumentException("Unknown type of chat") + } + } + + fun extractChat(): Chat { + return try { + when (chatPhoto) { + null -> extractPreviewChat() + else -> extractExtendedChat() + } + } catch (e: NullPointerException) { + throw IllegalChatRawObjectException(this) + } + } } diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChat.kt deleted file mode 100644 index c32bdd6e7c..0000000000 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChat.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.github.insanusmokrassar.TelegramBotAPI.types.chat - -import com.github.insanusmokrassar.TelegramBotAPI.types.* -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.* -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat -import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage - -data class SupergroupChat( - override val id: ChatId, - override val title: String? = null, - override val username: Username? = null, - override val description: String? = null, - override val inviteLink: String? = null, - override val chatPhoto: ChatPhoto? = null, - override val pinnedMessage: RawMessage? = null, - val stickerSetName: String? = null, - val canSetStickerSet: Boolean = false, - override val permissions: ChatPermissions? = null -) : GroupChat, UsernameChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChannelChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChatImpl.kt similarity index 50% rename from src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChannelChat.kt rename to src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChatImpl.kt index 598b991822..d492647dd8 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChannelChat.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChatImpl.kt @@ -2,15 +2,12 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.* -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.SupergroupChat import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage -data class ChannelChat( +data class SupergroupChatImpl( override val id: ChatId, - override val title: String? = null, - override val username: Username? = null, - override val description: String? = null, - override val inviteLink: String? = null, - override val chatPhoto: ChatPhoto? = null, - override val pinnedMessage: RawMessage? -) : PublicChat, UsernameChat, DescriptionChat + override val title: String, + override val username: Username? = null +) : SupergroupChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/DescriptionChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/ChannelChat.kt similarity index 50% rename from src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/DescriptionChat.kt rename to src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/ChannelChat.kt index f572b5fcd5..43c612ac1e 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/DescriptionChat.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/ChannelChat.kt @@ -1,5 +1,3 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts -interface DescriptionChat : PublicChat { - val description: String? -} +interface ChannelChat : SuperPublicChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/Chat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/Chat.kt index 7b84aa73b7..2f208fa270 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/Chat.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/Chat.kt @@ -5,5 +5,4 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.ChatPhoto interface Chat { val id: ChatId - val chatPhoto: ChatPhoto? } \ No newline at end of file diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/GroupChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/GroupChat.kt index c4c02a2f6e..06efb55190 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/GroupChat.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/GroupChat.kt @@ -1,7 +1,3 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions - -interface GroupChat : PublicChat, DescriptionChat { - val permissions: ChatPermissions? -} +interface GroupChat : PublicChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/PrivateChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/PrivateChat.kt new file mode 100644 index 0000000000..0c2286f85d --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/PrivateChat.kt @@ -0,0 +1,6 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts + +interface PrivateChat : Chat, UsernameChat { + val firstName: String + val lastName: String +} diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/PublicChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/PublicChat.kt index de874bb339..d72876149b 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/PublicChat.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/PublicChat.kt @@ -1,9 +1,5 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts -import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage - interface PublicChat : Chat { - val title: String? - val inviteLink: String? - val pinnedMessage: RawMessage? + val title: String } diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/SuperPublicChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/SuperPublicChat.kt new file mode 100644 index 0000000000..236af28116 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/SuperPublicChat.kt @@ -0,0 +1,3 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts + +interface SuperPublicChat : PublicChat, UsernameChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/SupergroupChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/SupergroupChat.kt new file mode 100644 index 0000000000..52c0ea464e --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/SupergroupChat.kt @@ -0,0 +1,3 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts + +interface SupergroupChat : GroupChat, SuperPublicChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedChannelChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedChannelChat.kt new file mode 100644 index 0000000000..5601782e7c --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedChannelChat.kt @@ -0,0 +1,5 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended + +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.ChannelChat + +interface ExtendedChannelChat : ChannelChat, ExtendedPublicChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedChat.kt new file mode 100644 index 0000000000..5a11195175 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedChat.kt @@ -0,0 +1,8 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended + +import com.github.insanusmokrassar.TelegramBotAPI.types.ChatPhoto +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat + +interface ExtendedChat : Chat { + val chatPhoto: ChatPhoto +} \ No newline at end of file diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedGroupChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedGroupChat.kt new file mode 100644 index 0000000000..283b89d96b --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedGroupChat.kt @@ -0,0 +1,8 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended + +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat + +interface ExtendedGroupChat : GroupChat, ExtendedPublicChat { + val permissions: ChatPermissions +} \ No newline at end of file diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedPrivateChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedPrivateChat.kt new file mode 100644 index 0000000000..67e00a46d7 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedPrivateChat.kt @@ -0,0 +1,5 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended + +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PrivateChat + +interface ExtendedPrivateChat : PrivateChat, ExtendedChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedPublicChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedPublicChat.kt new file mode 100644 index 0000000000..5f10a77528 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedPublicChat.kt @@ -0,0 +1,10 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended + +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat +import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage + +interface ExtendedPublicChat : ExtendedChat, PublicChat { + val description: String + val inviteLink: String? + val pinnedMessage: RawMessage? +} \ No newline at end of file diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedSupergroupChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedSupergroupChat.kt new file mode 100644 index 0000000000..5dd9f3d8ca --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedSupergroupChat.kt @@ -0,0 +1,9 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended + +import com.github.insanusmokrassar.TelegramBotAPI.types.StickerSetName +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.SupergroupChat + +interface ExtendedSupergroupChat : SupergroupChat, ExtendedGroupChat { + val stickerSetName: StickerSetName? + val canSetStickerSet: Boolean +} diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedChannelChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedChannelChatImpl.kt new file mode 100644 index 0000000000..66fa32a89b --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedChannelChatImpl.kt @@ -0,0 +1,15 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.chat.extended + +import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChannelChat +import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage + +data class ExtendedChannelChatImpl( + override val id: ChatId, + override val title: String, + override val username: Username?, + override val chatPhoto: ChatPhoto, + override val description: String, + override val inviteLink: String?, + override val pinnedMessage: RawMessage? +) : ExtendedChannelChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedGroupChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedGroupChatImpl.kt new file mode 100644 index 0000000000..58ee8695bb --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedGroupChatImpl.kt @@ -0,0 +1,17 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.chat.extended + +import com.github.insanusmokrassar.TelegramBotAPI.types.ChatId +import com.github.insanusmokrassar.TelegramBotAPI.types.ChatPhoto +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedGroupChat +import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage + +data class ExtendedGroupChatImpl( + override val id: ChatId, + override val title: String, + override val chatPhoto: ChatPhoto, + override val description: String, + override val inviteLink: String?, + override val permissions: ChatPermissions, + override val pinnedMessage: RawMessage? +) : ExtendedGroupChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedPrivateChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedPrivateChatImpl.kt new file mode 100644 index 0000000000..3469146856 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedPrivateChatImpl.kt @@ -0,0 +1,12 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.chat.extended + +import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedPrivateChat + +data class ExtendedPrivateChatImpl( + override val id: ChatId, + override val username: Username? = null, + override val firstName: String = "", + override val lastName: String = "", + override val chatPhoto: ChatPhoto +) : ExtendedPrivateChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedSupergroupChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedSupergroupChatImpl.kt new file mode 100644 index 0000000000..bd40e28001 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedSupergroupChatImpl.kt @@ -0,0 +1,19 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.chat.extended + +import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedSupergroupChat +import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage + +data class ExtendedSupergroupChatImpl( + override val id: ChatId, + override val title: String, + override val username: Username? = null, + override val chatPhoto: ChatPhoto, + override val description: String, + override val inviteLink: String?, + override val permissions: ChatPermissions, + override val pinnedMessage: RawMessage?, + override val stickerSetName: StickerSetName?, + override val canSetStickerSet: Boolean +) : ExtendedSupergroupChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/files/Sticker.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/files/Sticker.kt index 93d9b56272..fd779dad0e 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/files/Sticker.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/files/Sticker.kt @@ -20,7 +20,7 @@ data class Sticker( @SerialName(emojiField) val emoji: String? = null, @SerialName(stickerSetNameField) - val stickerSetName: String? = null, + val stickerSetName: StickerSetName? = null, @SerialName(isAnimatedField) val isAnimated: Boolean = false, @SerialName(maskPositionField) diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/ChannelEventMessage.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/ChannelEventMessage.kt index 63fb4df00e..5a08484965 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/ChannelEventMessage.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/ChannelEventMessage.kt @@ -1,7 +1,8 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChannelChat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChannelChatImpl +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.ChannelChat import com.github.insanusmokrassar.TelegramBotAPI.types.message.ChatEvents.abstracts.ChannelEvent import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ChatEventMessage import org.joda.time.DateTime diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt index 8b76a1d96a..3145aff30a 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt @@ -5,7 +5,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.RawMessage import com.github.insanusmokrassar.TelegramBotAPI.types.MessageEntity.RawMessageEntitiesSerializer import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup import com.github.insanusmokrassar.TelegramBotAPI.types.chat.* -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.types.files.* import com.github.insanusmokrassar.TelegramBotAPI.types.games.Game import com.github.insanusmokrassar.TelegramBotAPI.types.message.ChatEvents.* @@ -199,18 +199,18 @@ data class RawMessage( chatEvent ?.let { chatEvent -> when (chat) { - is GroupChat -> GroupEventMessage( - messageId, - chat, - chatEvent as? GroupEvent ?: throwWrongChatEvent(GroupChat::class, chatEvent), - date.asDate - ) is SupergroupChat -> SupergroupEventMessage( messageId, chat, chatEvent as? SupergroupEvent ?: throwWrongChatEvent(SupergroupEvent::class, chatEvent), date.asDate ) + is GroupChat -> GroupEventMessage( + messageId, + chat, + chatEvent as? GroupEvent ?: throwWrongChatEvent(GroupChat::class, chatEvent), + date.asDate + ) is ChannelChat -> ChannelEventMessage( messageId, chat, diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/SupergroupEventMessage.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/SupergroupEventMessage.kt index d767299b35..372be34470 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/SupergroupEventMessage.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/SupergroupEventMessage.kt @@ -1,7 +1,8 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.message import com.github.insanusmokrassar.TelegramBotAPI.types.MessageIdentifier -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.SupergroupChat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.SupergroupChatImpl +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.SupergroupChat import com.github.insanusmokrassar.TelegramBotAPI.types.message.ChatEvents.abstracts.SupergroupEvent import com.github.insanusmokrassar.TelegramBotAPI.types.message.abstracts.ChatEventMessage import org.joda.time.DateTime