Skip to content

Commit a7ae14c

Browse files
authored
Merge pull request #298 from simple-robot/dev/support-thread
feat(api): add Thread API support
2 parents 9607299 + 80e6866 commit a7ae14c

File tree

16 files changed

+3614
-0
lines changed

16 files changed

+3614
-0
lines changed

simbot-component-kook-api/api/simbot-component-kook-api.api

Lines changed: 590 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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.category
22+
23+
import io.ktor.http.*
24+
import kotlinx.serialization.DeserializationStrategy
25+
import kotlinx.serialization.Serializable
26+
import love.forte.simbot.kook.api.ApiResultType
27+
import love.forte.simbot.kook.api.KookGetApi
28+
import love.forte.simbot.kook.api.thread.Category
29+
import love.forte.simbot.kook.util.parameters
30+
import kotlin.jvm.JvmStatic
31+
32+
/**
33+
* [获取帖子分区列表](https://developer.kookapp.cn/doc/http/thread#%E8%8E%B7%E5%8F%96%E5%B8%96%E5%AD%90%E5%88%86%E5%8C%BA%E5%88%97%E8%A1%A8)
34+
*
35+
* @since 4.3.0
36+
* @author Forte
37+
*/
38+
public class GetCategoryListApi private constructor(
39+
/**
40+
* 帖子频道 id
41+
*/
42+
private val channelId: String
43+
) : KookGetApi<CategoryListData>() {
44+
public companion object Factory {
45+
private val PATH = ApiPath.create("category", "list")
46+
47+
private val serializer = CategoryListData.serializer()
48+
49+
/**
50+
* 构造 [获取帖子分区列表][GetCategoryListApi] 请求。
51+
*
52+
* @param channelId 帖子频道 id
53+
*/
54+
@JvmStatic
55+
public fun create(channelId: String): GetCategoryListApi =
56+
GetCategoryListApi(channelId)
57+
}
58+
59+
override val apiPath: ApiPath
60+
get() = PATH
61+
62+
override val resultDeserializationStrategy: DeserializationStrategy<CategoryListData>
63+
get() = serializer
64+
65+
override fun urlBuild(builder: URLBuilder) {
66+
builder.parameters {
67+
append("channel_id", channelId)
68+
}
69+
}
70+
}
71+
72+
/**
73+
* [GetCategoryListApi] 的响应结果。
74+
*
75+
* @since 4.3.0
76+
* @author Forte
77+
*/
78+
@Serializable
79+
public data class CategoryListData @ApiResultType constructor(
80+
/**
81+
* 帖子分区列表
82+
*/
83+
public val list: List<Category>
84+
)
Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
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

Comments
 (0)