1+ /*
2+ * Copyright (c) 2021-2025. ForteScarlet.
3+ *
4+ * This file is part of simbot-component-kook.
5+ *
6+ * simbot-component-kook is free software: you can redistribute it and/or modify
7+ * it under the terms of the GNU Lesser General Public License as published by
8+ * the Free Software Foundation, either version 3 of the License, or
9+ * (at your option) any later version.
10+ *
11+ * simbot-component-kook is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ * GNU Lesser General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU Lesser General Public License
17+ * along with simbot-component-kook,
18+ * If not, see <https://www.gnu.org/licenses/>.
19+ */
20+
21+ package love.forte.simbot.kook.api.thread
22+
23+ import kotlinx.serialization.DeserializationStrategy
24+ import kotlinx.serialization.SerialName
25+ import kotlinx.serialization.Serializable
26+ import love.forte.simbot.kook.api.KookPostApi
27+ import kotlin.jvm.JvmStatic
28+
29+ /* *
30+ * [创建帖子](https://developer.kookapp.cn/doc/http/thread#%E5%88%9B%E5%BB%BA%E5%B8%96%E5%AD%90)
31+ *
32+ * @since 4.3.0
33+ * @author Forte
34+ */
35+ public class CreateThreadApi private constructor(public override val body : Body ) : KookPostApi<ThreadView>() {
36+ /* *
37+ * 用于创建帖子的请求体。
38+ *
39+ * @since 4.3.0
40+ */
41+ @Serializable
42+ public class Body internal constructor(
43+ /* * 频道 id */
44+ @SerialName(" channel_id" )
45+ public val channelId : String ,
46+
47+ /* * 服务器 id */
48+ @SerialName(" guild_id" )
49+ public val guildId : String ,
50+
51+ /* * 标题 */
52+ public val title : String ,
53+
54+ /* * 卡片消息内容 */
55+ public val content : String ,
56+
57+ /* * 帖子分区 id(若无默认为综合分区) */
58+ @SerialName(" category_id" )
59+ public val categoryId : String? = null ,
60+
61+ /* * 封面url */
62+ public val cover : String? = null ,
63+ ) {
64+ override fun toString (): String {
65+ return " CreateThreadApi.Body(" +
66+ " channelId='$channelId ', " +
67+ " guildId='$guildId ', " +
68+ " title='$title ', " +
69+ " content='$content ', " +
70+ " categoryId=$categoryId , " +
71+ " cover=$cover )"
72+ }
73+
74+ override fun equals (other : Any? ): Boolean {
75+ if (this == = other) return true
76+ if (other !is Body ) return false
77+
78+ if (channelId != other.channelId) return false
79+ if (guildId != other.guildId) return false
80+ if (title != other.title) return false
81+ if (content != other.content) return false
82+ if (categoryId != other.categoryId) return false
83+ if (cover != other.cover) return false
84+
85+ return true
86+ }
87+
88+ override fun hashCode (): Int {
89+ var result = channelId.hashCode()
90+ result = 31 * result + guildId.hashCode()
91+ result = 31 * result + title.hashCode()
92+ result = 31 * result + content.hashCode()
93+ result = 31 * result + (categoryId?.hashCode() ? : 0 )
94+ result = 31 * result + (cover?.hashCode() ? : 0 )
95+ return result
96+ }
97+ }
98+
99+ /* *
100+ * 用于构建 [CreateThreadApi.Body] 的构建器。
101+ *
102+ * @since 4.3.0
103+ */
104+ public class Builder internal constructor(
105+ private var channelId : String ,
106+ private var guildId : String ,
107+ private var title : String ,
108+ private var content : String
109+ ) {
110+ private var categoryId: String? = null
111+ private var cover: String? = null
112+
113+ /* *
114+ * 设置帖子分区 id。
115+ */
116+ public fun categoryId (categoryId : String? ): Builder = apply {
117+ this .categoryId = categoryId
118+ }
119+
120+ /* *
121+ * 设置封面 URL。
122+ */
123+ public fun cover (cover : String? ): Builder = apply {
124+ this .cover = cover
125+ }
126+
127+ /* *
128+ * 构建 [CreateThreadApi.Body]。
129+ */
130+ public fun build (): Body = Body (
131+ channelId = channelId,
132+ guildId = guildId,
133+ title = title,
134+ content = content,
135+ categoryId = categoryId,
136+ cover = cover
137+ )
138+ }
139+
140+ public companion object Factory {
141+ private val PATH = ApiPath .create(" thread" , " create" )
142+
143+ private val serializer = ThreadView .serializer()
144+
145+ /* *
146+ * 构造 [创建帖子][CreateThreadApi] 请求。
147+ *
148+ * @param body 请求体
149+ */
150+ @JvmStatic
151+ public fun create (body : Body ): CreateThreadApi = CreateThreadApi (body)
152+
153+ /* *
154+ * 构造 [创建帖子][CreateThreadApi] 请求。
155+ *
156+ * @param channelId 频道 id
157+ * @param guildId 服务器 id
158+ * @param title 标题
159+ * @param content 卡片消息内容
160+ */
161+ @JvmStatic
162+ public fun create (
163+ channelId : String ,
164+ guildId : String ,
165+ title : String ,
166+ content : String
167+ ): CreateThreadApi = CreateThreadApi (
168+ Body (
169+ channelId = channelId,
170+ guildId = guildId,
171+ title = title,
172+ content = content
173+ )
174+ )
175+
176+ /* *
177+ * 创建 [CreateThreadApi.Builder] 用于构建请求体。
178+ *
179+ * @param channelId 频道 id
180+ * @param guildId 服务器 id
181+ * @param title 标题
182+ * @param content 卡片消息内容
183+ */
184+ @JvmStatic
185+ public fun builder (
186+ channelId : String ,
187+ guildId : String ,
188+ title : String ,
189+ content : String
190+ ): Builder = Builder (channelId, guildId, title, content)
191+ }
192+
193+ override val apiPath: ApiPath
194+ get() = PATH
195+
196+ override val resultDeserializationStrategy: DeserializationStrategy <ThreadView >
197+ get() = serializer
198+ }
0 commit comments