Skip to content

Commit 3fd6a72

Browse files
authored
Merge pull request #314 from simple-robot/dev/blacklist-operator
支持频道服务器黑名单相关上层API
2 parents 29f997b + 370cc61 commit 3fd6a72

File tree

15 files changed

+974
-14
lines changed

15 files changed

+974
-14
lines changed

build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ apiValidation {
7979
"love.forte.simbot.annotations.InternalSimbotAPI",
8080
"love.forte.simbot.kook.ExperimentalKookApi",
8181
"love.forte.simbot.kook.InternalKookApi",
82-
"love.forte.simbot.kook.api.template.ExperimentalTemplateApi"
82+
"love.forte.simbot.kook.api.template.ExperimentalTemplateApi",
83+
// blacklist APIs
84+
"love.forte.simbot.component.kook.blacklist.ExperimentalBlacklistApi"
8385
),
8486
)
8587

buildSrc/src/main/kotlin/P.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ object P : ProjectDetail() {
3535
get() = HOMEPAGE
3636

3737
const val VERSION = "4.3.0"
38-
const val NEXT_VERSION = "4.3.1"
38+
const val NEXT_VERSION = "4.4.0"
3939

4040
override val snapshotVersion = "$NEXT_VERSION-SNAPSHOT"
4141
override val version = if (isSnapshot()) snapshotVersion else VERSION

simbot-component-kook-api/src/jvmMain/java/module-info.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,19 @@
1616
exports love.forte.simbot.kook;
1717
exports love.forte.simbot.kook.api;
1818
exports love.forte.simbot.kook.api.asset;
19+
exports love.forte.simbot.kook.api.blacklist;
20+
exports love.forte.simbot.kook.api.category;
1921
exports love.forte.simbot.kook.api.channel;
2022
exports love.forte.simbot.kook.api.guild;
2123
exports love.forte.simbot.kook.api.invite;
2224
exports love.forte.simbot.kook.api.member;
2325
exports love.forte.simbot.kook.api.message;
2426
exports love.forte.simbot.kook.api.role;
27+
exports love.forte.simbot.kook.api.template;
28+
exports love.forte.simbot.kook.api.thread;
2529
exports love.forte.simbot.kook.api.user;
2630
exports love.forte.simbot.kook.api.userchat;
31+
exports love.forte.simbot.kook.api.voice;
2732
exports love.forte.simbot.kook.event;
2833
exports love.forte.simbot.kook.messages;
2934
exports love.forte.simbot.kook.objects;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,9 @@ public abstract interface class love/forte/simbot/component/kook/KookVoiceMember
318318
public fun moveReserve (Llove/forte/simbot/common/id/ID;)Llove/forte/simbot/suspendrunner/reserve/SuspendReserve;
319319
}
320320

321+
public abstract interface annotation class love/forte/simbot/component/kook/blacklist/ExperimentalBlacklistApi : java/lang/annotation/Annotation {
322+
}
323+
321324
public abstract interface class love/forte/simbot/component/kook/bot/KookBot : kotlinx/coroutines/CoroutineScope, love/forte/simbot/bot/Bot {
322325
public fun cancel (Ljava/lang/Throwable;)V
323326
public fun getAvatar ()Ljava/lang/String;

simbot-component-kook-core/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ kotlin {
4848
optIn.addAll(
4949
"love.forte.simbot.kook.ExperimentalKookApi",
5050
"love.forte.simbot.kook.InternalKookApi",
51+
"love.forte.simbot.component.kook.blacklist.ExperimentalBlacklistApi"
5152
)
5253
}
5354

@@ -80,6 +81,7 @@ kotlin {
8081
implementation(libs.simbot.api)
8182
implementation(libs.simbot.core)
8283
implementation(libs.simbot.common.core)
84+
implementation(libs.ktor.client.mock)
8385
}
8486

8587
jvmTest.dependencies {

simbot-component-kook-core/src/commonMain/kotlin/love/forte/simbot/component/kook/KookGuild.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import love.forte.simbot.annotations.ExperimentalSimbotAPI
2525
import love.forte.simbot.common.collectable.Collectable
2626
import love.forte.simbot.common.id.ID
2727
import love.forte.simbot.common.id.StringID.Companion.ID
28+
import love.forte.simbot.component.kook.blacklist.ExperimentalBlacklistApi
29+
import love.forte.simbot.component.kook.blacklist.KookGuildBlacklistOperator
2830
import love.forte.simbot.component.kook.role.KookGuildRole
2931
import love.forte.simbot.component.kook.role.KookGuildRoleCreator
3032
import love.forte.simbot.component.kook.role.KookRole
@@ -207,4 +209,15 @@ public interface KookGuild : Guild, CoroutineScope, KookRoleOperator {
207209
@ExperimentalSimbotAPI
208210
override fun roleCreator(): KookGuildRoleCreator
209211
//endregion
212+
213+
// Blacklist
214+
215+
/**
216+
* 获取针对当前频道服务器的黑名单操作器。
217+
*
218+
* @since 4.4.0
219+
* @see KookGuildBlacklistOperator
220+
*/
221+
@ExperimentalBlacklistApi
222+
public val blacklist: KookGuildBlacklistOperator
210223
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (c) 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.component.kook.blacklist
22+
23+
/**
24+
* 与频道服务器黑名单列表相关的试验性 API。
25+
* 这些 API 仍处于试验性阶段,可能会随时被更改、删除,不保证稳定性。
26+
*
27+
* @since 4.4.0
28+
* @author ForteScarlet
29+
*/
30+
@Retention(AnnotationRetention.BINARY)
31+
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY)
32+
@MustBeDocumented
33+
@RequiresOptIn(
34+
message = "与频道服务器黑名单列表相关的试验性 API。" +
35+
"这些 API 仍处于试验性阶段,可能会随时被更改、删除,不保证稳定性。",
36+
level = RequiresOptIn.Level.WARNING
37+
)
38+
public annotation class ExperimentalBlacklistApi
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (c) 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.component.kook.blacklist
22+
23+
import love.forte.simbot.ability.DeleteOption
24+
import love.forte.simbot.ability.DeleteSupport
25+
import love.forte.simbot.ability.StandardDeleteOption
26+
import love.forte.simbot.common.id.ID
27+
import love.forte.simbot.common.time.Timestamp
28+
import love.forte.simbot.kook.objects.User
29+
import love.forte.simbot.suspendrunner.ST
30+
31+
/**
32+
* KOOK 服务器黑名单列表中的一个元素。
33+
*
34+
* @since 4.4.0
35+
*
36+
* @author ForteScarlet
37+
*/
38+
@ExperimentalBlacklistApi
39+
public interface KookBlacklistItem : DeleteSupport {
40+
/**
41+
* 用户 ID
42+
*/
43+
public val userId: ID
44+
45+
/**
46+
* 服务器 ID
47+
*/
48+
public val guildId: ID
49+
50+
/**
51+
* 加入黑名单的时间
52+
*/
53+
public val createdTime: Timestamp
54+
55+
/**
56+
* 加入黑名单的原因
57+
*/
58+
public val remark: String
59+
60+
/**
61+
* 用户信息。
62+
*/
63+
public val userInfo: User
64+
65+
/**
66+
* 将此人移出黑名单列表。
67+
*
68+
* @throws RuntimeException 如果在请求API过程中出现任何非预期异常,
69+
* 并且没有提供 [StandardDeleteOption.IGNORE_ON_FAILURE]
70+
*/
71+
@ST
72+
override suspend fun delete(vararg options: DeleteOption)
73+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* Copyright (c) 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.component.kook.blacklist
22+
23+
import kotlinx.coroutines.flow.Flow
24+
import kotlinx.coroutines.flow.toList
25+
import love.forte.simbot.ability.DeleteOption
26+
import love.forte.simbot.ability.StandardDeleteOption
27+
import love.forte.simbot.common.id.ID
28+
import love.forte.simbot.kook.api.ListData
29+
import love.forte.simbot.kook.api.blacklist.CreateBlacklistApi
30+
import love.forte.simbot.suspendrunner.ST
31+
32+
/**
33+
* KOOK 服务器黑名单相关内容的操作器。
34+
*
35+
* @since 4.4.0
36+
*
37+
* @author ForteScarlet
38+
*/
39+
@ExperimentalBlacklistApi
40+
public interface KookGuildBlacklistOperator {
41+
/**
42+
* 服务器ID
43+
*/
44+
public val guildId: ID
45+
46+
/**
47+
* 获取黑名单的分页列表。
48+
*
49+
* @param page 页码
50+
* @param size 每页大小
51+
* @return 分页列表
52+
*/
53+
@ST
54+
public suspend fun list(page: Int?, size: Int?): ListData<KookBlacklistItem>
55+
56+
/**
57+
* 获取全量列表数据。
58+
*/
59+
@ST
60+
public suspend fun all(): List<KookBlacklistItem> = flow().toList()
61+
62+
/**
63+
* 获取黑名单列表元素的 Flow。
64+
*
65+
* @param batchSize 每批次大小
66+
*/
67+
public fun flow(batchSize: Int? = null): Flow<KookBlacklistItem>
68+
69+
/**
70+
* 添加一个目标到黑名单。
71+
*
72+
* @param guildId 服务器id
73+
* @param targetId 目标用户id
74+
* @param remark 加入黑名单的原因
75+
* @param delMsgDays 删除最近几天的消息,最大 7 天, 默认 0
76+
* @see CreateBlacklistApi
77+
*/
78+
@ST
79+
public suspend fun add(targetId: ID, remark: String?, delMsgDays: Int?)
80+
81+
/**
82+
* 添加一个目标到黑名单。
83+
*
84+
* @param guildId 服务器id
85+
* @param targetId 目标用户id
86+
* @see CreateBlacklistApi
87+
*/
88+
@ST
89+
public suspend fun add(targetId: ID) {
90+
add(targetId, null, null)
91+
}
92+
93+
/**
94+
* 删除指定黑名单内的目标。
95+
*
96+
* @throws RuntimeException 如果在请求API过程中出现任何非预期异常,
97+
* 并且没有提供 [StandardDeleteOption.IGNORE_ON_FAILURE]
98+
*/
99+
@ST
100+
public suspend fun delete(targetId: ID, vararg options: DeleteOption)
101+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (c) 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.component.kook.blacklist.internal
22+
23+
import love.forte.simbot.ability.DeleteOption
24+
import love.forte.simbot.common.id.ID
25+
import love.forte.simbot.common.id.StringID.Companion.ID
26+
import love.forte.simbot.common.time.Timestamp
27+
import love.forte.simbot.component.kook.blacklist.KookBlacklistItem
28+
import love.forte.simbot.component.kook.blacklist.KookGuildBlacklistOperator
29+
import love.forte.simbot.kook.api.blacklist.BlacklistItem
30+
import love.forte.simbot.kook.objects.User
31+
32+
/**
33+
*
34+
* @author ForteScarlet
35+
*/
36+
internal class KookBlacklistItemImpl(
37+
private val source: BlacklistItem,
38+
override val guildId: ID,
39+
private val operator: KookGuildBlacklistOperator
40+
) : KookBlacklistItem {
41+
override val userId: ID
42+
get() = source.userId.ID
43+
override val remark: String
44+
get() = source.remark
45+
override val userInfo: User
46+
get() = source.user
47+
48+
override val createdTime: Timestamp = Timestamp.ofMilliseconds(source.createdTime)
49+
50+
override suspend fun delete(vararg options: DeleteOption) {
51+
operator.delete(targetId = userId, options = options)
52+
}
53+
54+
override fun toString(): String {
55+
return "KookBlacklistItemImpl(source=$source, guildId=$guildId, userId=$userId)"
56+
}
57+
}
58+
59+
internal fun BlacklistItem.toKookBlacklistItem(guildId: ID, operator: KookGuildBlacklistOperator): KookBlacklistItem =
60+
KookBlacklistItemImpl(this, guildId, operator)

0 commit comments

Comments
 (0)