From aca4d90608b84f89707759918a2261ff93ddd57f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 6 Nov 2022 15:29:48 +0600 Subject: [PATCH] add support of forum requests --- .../requests/chat/forum/CloseForumTopic.kt | 20 ++++++++++++ .../requests/chat/forum/CreateForumTopic.kt | 32 +++++++++++++++++++ .../requests/chat/forum/DeleteForumTopic.kt | 20 ++++++++++++ .../requests/chat/forum/EditForumTopic.kt | 30 +++++++++++++++++ .../requests/chat/forum/ForumRequest.kt | 6 ++++ .../requests/chat/forum/ModifyForumRequest.kt | 10 ++++++ .../requests/chat/forum/ReopenForumTopic.kt | 20 ++++++++++++ .../chat/forum/UnpinAllForumTopicMessages.kt | 20 ++++++++++++ .../chat/get/GetForumTopicIconStickers.kt | 23 +++++++++++++ .../kotlin/dev/inmo/tgbotapi/types/Common.kt | 1 + .../dev/inmo/tgbotapi/types/ForumTopic.kt | 26 +++++++++++++++ 11 files changed, 208 insertions(+) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/CloseForumTopic.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/CreateForumTopic.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/DeleteForumTopic.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/EditForumTopic.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/ForumRequest.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/ModifyForumRequest.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/ReopenForumTopic.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/UnpinAllForumTopicMessages.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/get/GetForumTopicIconStickers.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ForumTopic.kt diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/CloseForumTopic.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/CloseForumTopic.kt new file mode 100644 index 0000000000..27a1dd8234 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/CloseForumTopic.kt @@ -0,0 +1,20 @@ +package dev.inmo.tgbotapi.requests.chat.forum + +import dev.inmo.tgbotapi.abstracts.types.ChatRequest +import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.utils.RGBColor +import kotlinx.serialization.* +import kotlinx.serialization.builtins.serializer + +@Serializable +data class CloseForumTopic ( + @SerialName(chatIdField) + override val chatId: ChatIdentifier, + @SerialName(messageThreadIdField) + val messageThreadId: MessageThreadId +): ModifyForumRequest { + override fun method(): String = "closeForumTopic" + override val requestSerializer: SerializationStrategy<*> + get() = serializer() +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/CreateForumTopic.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/CreateForumTopic.kt new file mode 100644 index 0000000000..9119706218 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/CreateForumTopic.kt @@ -0,0 +1,32 @@ +package dev.inmo.tgbotapi.requests.chat.forum + +import dev.inmo.tgbotapi.abstracts.types.ChatRequest +import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.utils.RGBColor +import kotlinx.serialization.* +import kotlinx.serialization.builtins.serializer + +@Serializable +data class CreateForumTopic ( + @SerialName(chatIdField) + override val chatId: ChatIdentifier, + @SerialName(nameField) + val name: String, + @SerialName(iconColorField) + val color: RGBColor, + @SerialName(iconCustomEmojiIdField) + val iconEmojiId: CustomEmojiId? = null, +): ForumRequest { + init { + if (name.length !in threadNameLength) { + throw IllegalArgumentException("Thread name must be in $threadNameLength range") + } + } + + override fun method(): String = "createForumTopic" + override val resultDeserializer: DeserializationStrategy + get() = ForumTopic.serializer() + override val requestSerializer: SerializationStrategy<*> + get() = serializer() +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/DeleteForumTopic.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/DeleteForumTopic.kt new file mode 100644 index 0000000000..c5ee2547b9 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/DeleteForumTopic.kt @@ -0,0 +1,20 @@ +package dev.inmo.tgbotapi.requests.chat.forum + +import dev.inmo.tgbotapi.abstracts.types.ChatRequest +import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.utils.RGBColor +import kotlinx.serialization.* +import kotlinx.serialization.builtins.serializer + +@Serializable +data class DeleteForumTopic ( + @SerialName(chatIdField) + override val chatId: ChatIdentifier, + @SerialName(messageThreadIdField) + val messageThreadId: MessageThreadId +): ModifyForumRequest { + override fun method(): String = "deleteForumTopic" + override val requestSerializer: SerializationStrategy<*> + get() = serializer() +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/EditForumTopic.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/EditForumTopic.kt new file mode 100644 index 0000000000..6a1c8dc768 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/EditForumTopic.kt @@ -0,0 +1,30 @@ +package dev.inmo.tgbotapi.requests.chat.forum + +import dev.inmo.tgbotapi.abstracts.types.ChatRequest +import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.utils.RGBColor +import kotlinx.serialization.* +import kotlinx.serialization.builtins.serializer + +@Serializable +data class EditForumTopic ( + @SerialName(chatIdField) + override val chatId: ChatIdentifier, + @SerialName(messageThreadIdField) + val messageThreadId: MessageThreadId, + @SerialName(nameField) + val name: String, + @SerialName(iconCustomEmojiIdField) + val iconEmojiId: CustomEmojiId, +): ModifyForumRequest { + init { + if (name.length !in threadNameLength) { + throw IllegalArgumentException("Thread name must be in $threadNameLength range") + } + } + + override fun method(): String = "editForumTopic" + override val requestSerializer: SerializationStrategy<*> + get() = serializer() +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/ForumRequest.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/ForumRequest.kt new file mode 100644 index 0000000000..3b160b177d --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/ForumRequest.kt @@ -0,0 +1,6 @@ +package dev.inmo.tgbotapi.requests.chat.forum + +import dev.inmo.tgbotapi.abstracts.types.ChatRequest +import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest + +sealed interface ForumRequest : SimpleRequest, ChatRequest diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/ModifyForumRequest.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/ModifyForumRequest.kt new file mode 100644 index 0000000000..8e78fa0628 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/ModifyForumRequest.kt @@ -0,0 +1,10 @@ +package dev.inmo.tgbotapi.requests.chat.forum + +import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest +import kotlinx.serialization.DeserializationStrategy +import kotlinx.serialization.builtins.serializer + +sealed interface ModifyForumRequest : ForumRequest { + override val resultDeserializer: DeserializationStrategy + get() = Boolean.serializer() +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/ReopenForumTopic.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/ReopenForumTopic.kt new file mode 100644 index 0000000000..17c07b6deb --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/ReopenForumTopic.kt @@ -0,0 +1,20 @@ +package dev.inmo.tgbotapi.requests.chat.forum + +import dev.inmo.tgbotapi.abstracts.types.ChatRequest +import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.utils.RGBColor +import kotlinx.serialization.* +import kotlinx.serialization.builtins.serializer + +@Serializable +data class ReopenForumTopic ( + @SerialName(chatIdField) + override val chatId: ChatIdentifier, + @SerialName(messageThreadIdField) + val messageThreadId: MessageThreadId +): ModifyForumRequest { + override fun method(): String = "reopenForumTopic" + override val requestSerializer: SerializationStrategy<*> + get() = serializer() +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/UnpinAllForumTopicMessages.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/UnpinAllForumTopicMessages.kt new file mode 100644 index 0000000000..7a792b7548 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/forum/UnpinAllForumTopicMessages.kt @@ -0,0 +1,20 @@ +package dev.inmo.tgbotapi.requests.chat.forum + +import dev.inmo.tgbotapi.abstracts.types.ChatRequest +import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.utils.RGBColor +import kotlinx.serialization.* +import kotlinx.serialization.builtins.serializer + +@Serializable +data class UnpinAllForumTopicMessages ( + @SerialName(chatIdField) + override val chatId: ChatIdentifier, + @SerialName(messageThreadIdField) + val messageThreadId: MessageThreadId +): ModifyForumRequest { + override fun method(): String = "unpinAllForumTopicMessages" + override val requestSerializer: SerializationStrategy<*> + get() = serializer() +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/get/GetForumTopicIconStickers.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/get/GetForumTopicIconStickers.kt new file mode 100644 index 0000000000..e870191a79 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/get/GetForumTopicIconStickers.kt @@ -0,0 +1,23 @@ +package dev.inmo.tgbotapi.requests.chat.get + +import dev.inmo.tgbotapi.abstracts.types.ChatRequest +import dev.inmo.tgbotapi.abstracts.types.OptionalChatRequest +import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.files.Sticker +import dev.inmo.tgbotapi.types.files.StickerSerializer +import kotlinx.serialization.* +import kotlinx.serialization.builtins.ListSerializer +import kotlinx.serialization.builtins.serializer + +@Serializable +object GetForumTopicIconStickers : SimpleRequest> { + override val requestSerializer: SerializationStrategy<*> + get() = serializer() + private val deserializer = ListSerializer(StickerSerializer) + + override fun method(): String = "getForumTopicIconStickers" + + override val resultDeserializer: DeserializationStrategy> + get() = deserializer +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index 4ba5a7c60d..bceec5ef4c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -94,6 +94,7 @@ val captionLength = 0 .. 1024 val textLength = 1 .. 4096 val userProfilePhotosRequestLimit = 0 .. 100 val chatTitleLength = 1 until 255 +val threadNameLength = 1 until 128 val chatDescriptionLength = 0 until 256 val inlineResultQueryIdLingth = 1 until 64 val allowedConnectionsLength = 1 .. 100 diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ForumTopic.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ForumTopic.kt new file mode 100644 index 0000000000..b241e01701 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ForumTopic.kt @@ -0,0 +1,26 @@ +package dev.inmo.tgbotapi.types + +import dev.inmo.tgbotapi.utils.RGBColor +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class ForumTopic( + @SerialName(messageThreadIdField) + val messageThreadId: MessageThreadId, + @SerialName(nameField) + val name: String, + @SerialName(iconColorField) + val color: RGBColor, + @SerialName(iconCustomEmojiIdField) + val iconEmojiId: CustomEmojiId? = null +) { + companion object { + val CYAN = RGBColor(0x6FB9F0) + val YELLOW = RGBColor(0xffd67e) + val PURPLE = RGBColor(0xCB86DB) + val GREEN = RGBColor(0x8EEE98) + val PINK = RGBColor(0xFF93B2) + val RED = RGBColor(0xFB6F5F) + } +}