Skip to content

Commit 8990514

Browse files
committed
feat(core): (WIP) 增加blacklist的上层API
1 parent 29f997b commit 8990514

File tree

5 files changed

+297
-1
lines changed

5 files changed

+297
-1
lines changed

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
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
public interface KookBlacklistItem : DeleteSupport {
39+
/**
40+
* 用户 ID
41+
*/
42+
public val userId: ID
43+
44+
/**
45+
* 服务器 ID
46+
*/
47+
public val guildId: ID
48+
49+
/**
50+
* 加入黑名单的时间
51+
*/
52+
public val createdTime: Timestamp
53+
54+
/**
55+
* 加入黑名单的原因
56+
*/
57+
public val remark: String
58+
59+
/**
60+
* 用户信息。
61+
*/
62+
public val userInfo: User
63+
64+
/**
65+
* 将此人移出黑名单列表。
66+
*
67+
* @throws RuntimeException 如果在请求API过程中出现任何非预期异常,
68+
* 并且没有提供 [StandardDeleteOption.IGNORE_ON_FAILURE]
69+
*/
70+
@ST
71+
override suspend fun delete(vararg options: DeleteOption)
72+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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+
public interface KookBlacklistOperator {
40+
/**
41+
* 获取黑名单的分页列表。
42+
*
43+
* @param page 页码
44+
* @param size 每页大小
45+
* @return 分页列表
46+
*/
47+
@ST
48+
public suspend fun list(guildId: ID, page: Int?, size: Int?): ListData<KookBlacklistItem>
49+
50+
/**
51+
* 获取全量列表数据。
52+
*/
53+
@ST
54+
public suspend fun all(guildId: ID): List<KookBlacklistItem> =
55+
flow(guildId).toList()
56+
57+
/**
58+
* 获取黑名单列表元素的 Flow。
59+
*
60+
* @param batchSize 每批次大小
61+
*/
62+
public fun flow(guildId: ID, batchSize: Int? = null): Flow<KookBlacklistItem>
63+
64+
/**
65+
* 添加一个目标到黑名单。
66+
*
67+
* @param guildId 服务器id
68+
* @param targetId 目标用户id
69+
* @param remark 加入黑名单的原因
70+
* @param delMsgDays 删除最近几天的消息,最大 7 天, 默认 0
71+
* @see CreateBlacklistApi
72+
*/
73+
@ST
74+
public suspend fun add(guildId: ID, targetId: ID, remark: String?, delMsgDays: Int?)
75+
76+
/**
77+
* 添加一个目标到黑名单。
78+
*
79+
* @param guildId 服务器id
80+
* @param targetId 目标用户id
81+
* @see CreateBlacklistApi
82+
*/
83+
@ST
84+
public suspend fun add(guildId: ID, targetId: ID) {
85+
add(guildId, targetId, null, null)
86+
}
87+
88+
/**
89+
* 删除指定黑名单内的目标。
90+
*
91+
* @throws RuntimeException 如果在请求API过程中出现任何非预期异常,
92+
* 并且没有提供 [StandardDeleteOption.IGNORE_ON_FAILURE]
93+
*/
94+
@ST
95+
public suspend fun delete(guildId: ID, targetId: ID, vararg options: DeleteOption)
96+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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.kook.api.blacklist.BlacklistItem
29+
import love.forte.simbot.kook.objects.User
30+
31+
/**
32+
*
33+
* @author ForteScarlet
34+
*/
35+
internal class KookBlacklistItemImpl(
36+
private val source: BlacklistItem,
37+
override val guildId: ID
38+
) : KookBlacklistItem {
39+
override val userId: ID
40+
get() = source.userId.ID
41+
override val remark: String
42+
get() = source.remark
43+
override val userInfo: User
44+
get() = source.user
45+
46+
override val createdTime: Timestamp = Timestamp.ofMilliseconds(source.createdTime)
47+
48+
override suspend fun delete(vararg options: DeleteOption) {
49+
TODO("Not yet implemented")
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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 kotlinx.coroutines.ExperimentalCoroutinesApi
24+
import kotlinx.coroutines.flow.Flow
25+
import kotlinx.coroutines.flow.asFlow
26+
import kotlinx.coroutines.flow.flatMapConcat
27+
import kotlinx.coroutines.flow.map
28+
import love.forte.simbot.ability.DeleteOption
29+
import love.forte.simbot.common.id.ID
30+
import love.forte.simbot.common.id.literal
31+
import love.forte.simbot.component.kook.blacklist.KookBlacklistItem
32+
import love.forte.simbot.component.kook.blacklist.KookBlacklistOperator
33+
import love.forte.simbot.component.kook.bot.KookBot
34+
import love.forte.simbot.component.kook.util.requestData
35+
import love.forte.simbot.kook.api.ListData
36+
import love.forte.simbot.kook.api.blacklist.GetBlacklistListApi
37+
import love.forte.simbot.kook.api.blacklist.createFlow
38+
39+
/**
40+
*
41+
* @author ForteScarlet
42+
*/
43+
internal class KookBlacklistOperatorImpl(private val bot: KookBot) : KookBlacklistOperator {
44+
override suspend fun list(
45+
guildId: ID,
46+
page: Int?,
47+
size: Int?
48+
): ListData<KookBlacklistItem> {
49+
TODO("Not yet implemented")
50+
}
51+
52+
@OptIn(ExperimentalCoroutinesApi::class)
53+
override fun flow(guildId: ID, batchSize: Int?): Flow<KookBlacklistItem> {
54+
return GetBlacklistListApi.createFlow { page ->
55+
val api = GetBlacklistListApi.create(guildId = guildId.literal, page = page, pageSize = batchSize)
56+
bot.requestData(api)
57+
}.flatMapConcat { it.items.asFlow() }
58+
.map { TODO("Not yet implemented") }
59+
}
60+
61+
override suspend fun add(
62+
guildId: ID,
63+
targetId: ID,
64+
remark: String?,
65+
delMsgDays: Int?
66+
) {
67+
TODO("Not yet implemented")
68+
}
69+
70+
override suspend fun delete(
71+
guildId: ID,
72+
targetId: ID,
73+
vararg options: DeleteOption
74+
) {
75+
TODO("Not yet implemented")
76+
}
77+
}

0 commit comments

Comments
 (0)