Skip to content

Commit 632dace

Browse files
committed
feat(core): 增加新的 KookVoiceChannel 来描述一个语音频道的信息
1 parent 765fba9 commit 632dace

File tree

14 files changed

+468
-268
lines changed

14 files changed

+468
-268
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import love.forte.simbot.ability.DeleteSupport
2222
import love.forte.simbot.ability.StandardDeleteOption
2323
import love.forte.simbot.common.id.ID
2424
import love.forte.simbot.common.id.StringID.Companion.ID
25+
import love.forte.simbot.component.kook.bot.KookBot
2526
import love.forte.simbot.definition.Channel
2627
import love.forte.simbot.suspendrunner.ST
2728
import kotlin.coroutines.CoroutineContext
@@ -37,6 +38,12 @@ import love.forte.simbot.kook.objects.Channel as KChannel
3738
* @author ForteScarlet
3839
*/
3940
public interface KookChannel : Channel, DeleteSupport {
41+
/**
42+
* Channel 所属 bot
43+
* @since 4.2.0
44+
*/
45+
public val bot: KookBot
46+
4047
override val coroutineContext: CoroutineContext
4148

4249
override val category: KookCategory?
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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
22+
23+
import kotlinx.coroutines.CoroutineScope
24+
import love.forte.simbot.common.id.ID
25+
import love.forte.simbot.common.id.literal
26+
import love.forte.simbot.component.kook.message.KookMessageReceipt
27+
import love.forte.simbot.definition.ChatChannel
28+
import love.forte.simbot.kook.api.message.SendChannelMessageApi
29+
import love.forte.simbot.kook.messages.MessageType
30+
import love.forte.simbot.message.Message
31+
import love.forte.simbot.message.MessageContent
32+
import love.forte.simbot.suspendrunner.ST
33+
import kotlin.coroutines.CoroutineContext
34+
35+
/**
36+
* 代表一个 KOOK 中可以发送消息(有聊天能力的)的频道。
37+
*
38+
* @see KookChatChannel
39+
* @see KookVoiceChannel
40+
*
41+
* @since 4.2.0
42+
* @author ForteScarlet
43+
*/
44+
public interface KookChatCapableChannel : KookChannel, ChatChannel, CoroutineScope {
45+
/**
46+
* 源于 bot 的上下文,但是没有 Job。
47+
*/
48+
override val coroutineContext: CoroutineContext
49+
50+
override val name: String
51+
get() = source.name
52+
53+
/**
54+
* 此频道的分组。
55+
*
56+
* 如果当前频道是属于“顶层分类”的频道(即没有分类、 [source.parentId][love.forte.simbot.kook.objects.Channel.parentId] 为空),
57+
* 则 [category] 结果为null。
58+
*
59+
* @see KookCategory
60+
*/
61+
override val category: KookCategory?
62+
63+
// region send api
64+
65+
/**
66+
* 根据 [SendChannelMessageApi] api 构建并发送消息。
67+
*/
68+
@ST
69+
public suspend fun send(request: SendChannelMessageApi): KookMessageReceipt
70+
71+
/**
72+
* 根据 [SendChannelMessageApi] api 构建并发送消息。
73+
*/
74+
@ST
75+
public suspend fun send(
76+
type: Int,
77+
content: String,
78+
quote: ID?,
79+
nonce: String?,
80+
tempTargetId: ID?,
81+
): KookMessageReceipt {
82+
val request =
83+
SendChannelMessageApi.create(type, source.id, content, quote?.literal, nonce, tempTargetId?.literal)
84+
return send(request)
85+
}
86+
87+
88+
/**
89+
* 发送纯文本消息,并指定 [tempTargetId].
90+
*
91+
* @see SendChannelMessageApi.tempTargetId
92+
*/
93+
@ST
94+
public suspend fun send(text: String, quote: ID? = null, tempTargetId: ID? = null): KookMessageReceipt {
95+
return send(
96+
MessageType.TEXT.type,
97+
text,
98+
quote, null, tempTargetId
99+
)
100+
}
101+
102+
/**
103+
* 发送消息,并可选的指定 [quote] 和 [tempTargetId].
104+
*
105+
* @see SendChannelMessageApi.tempTargetId
106+
* @see SendChannelMessageApi.quote
107+
*/
108+
@ST
109+
public suspend fun send(message: Message, quote: ID? = null, tempTargetId: ID? = null): KookMessageReceipt
110+
111+
/**
112+
* 发送消息,并可选的指定 [quote] 和 [tempTargetId].
113+
*
114+
* @see SendChannelMessageApi.tempTargetId
115+
* @see SendChannelMessageApi.quote
116+
*/
117+
@ST
118+
public suspend fun send(
119+
message: MessageContent,
120+
quote: ID? = null,
121+
tempTargetId: ID? = null,
122+
): KookMessageReceipt
123+
124+
125+
/**
126+
* 发送纯文本消息。
127+
*/
128+
@ST
129+
override suspend fun send(text: String): KookMessageReceipt =
130+
send(
131+
MessageType.TEXT.type,
132+
text,
133+
null, null, null
134+
)
135+
136+
/**
137+
* 发送消息。
138+
*/
139+
@ST
140+
override suspend fun send(message: Message): KookMessageReceipt =
141+
send(message, null)
142+
143+
/**
144+
* 发送消息。
145+
*/
146+
@ST
147+
override suspend fun send(messageContent: MessageContent): KookMessageReceipt =
148+
send(messageContent, null)
149+
150+
// endregion
151+
}

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

Lines changed: 1 addition & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -17,133 +17,9 @@
1717

1818
package love.forte.simbot.component.kook
1919

20-
import kotlinx.coroutines.CoroutineScope
21-
import love.forte.simbot.*
22-
import love.forte.simbot.common.id.ID
23-
import love.forte.simbot.common.id.StringID.Companion.ID
24-
import love.forte.simbot.common.id.literal
25-
import love.forte.simbot.component.kook.message.KookMessageReceipt
26-
import love.forte.simbot.definition.ChatChannel
27-
import love.forte.simbot.kook.api.message.SendChannelMessageApi
28-
import love.forte.simbot.kook.messages.MessageType
29-
import love.forte.simbot.kook.objects.Channel
30-
import love.forte.simbot.message.Message
31-
import love.forte.simbot.message.MessageContent
32-
import love.forte.simbot.suspendrunner.ST
33-
import kotlin.coroutines.CoroutineContext
34-
35-
3620
/**
3721
* 一个 KOOK 中的聊天子频道。
3822
*
3923
* @author ForteScarlet
4024
*/
41-
public interface KookChatChannel : KookChannel, ChatChannel, CoroutineScope {
42-
/**
43-
* 源于 bot 的上下文,但是没有 Job。
44-
*/
45-
override val coroutineContext: CoroutineContext
46-
47-
override val name: String
48-
get() = source.name
49-
50-
/**
51-
* 此频道的分组。
52-
*
53-
* 如果当前频道是属于“顶层分类”的频道(即没有分类、 [source.parentId][love.forte.simbot.kook.objects.Channel.parentId] 为空),
54-
* 则 [category] 结果为null。
55-
*
56-
* @see KookCategory
57-
*/
58-
override val category: KookCategory?
59-
60-
// region send api
61-
/**
62-
* 根据 [SendChannelMessageApi] api 构建并发送消息。
63-
*/
64-
@ST
65-
public suspend fun send(request: SendChannelMessageApi): KookMessageReceipt
66-
67-
// return request.requestDataBy(bot).asReceipt(false, bot)
68-
69-
/**
70-
* 根据 [SendChannelMessageApi] api 构建并发送消息。
71-
*/
72-
@ST
73-
public suspend fun send(
74-
type: Int,
75-
content: String,
76-
quote: ID?,
77-
nonce: String?,
78-
tempTargetId: ID?,
79-
): KookMessageReceipt {
80-
val request =
81-
SendChannelMessageApi.create(type, source.id, content, quote?.literal, nonce, tempTargetId?.literal)
82-
return send(request)
83-
}
84-
85-
86-
/**
87-
* 发送纯文本消息,并指定 [tempTargetId].
88-
*
89-
* @see SendChannelMessageApi.tempTargetId
90-
*/
91-
@ST
92-
public suspend fun send(text: String, quote: ID? = null, tempTargetId: ID? = null): KookMessageReceipt {
93-
return send(
94-
MessageType.TEXT.type,
95-
text,
96-
quote, null, tempTargetId
97-
)
98-
}
99-
100-
/**
101-
* 发送消息,并可选的指定 [quote] 和 [tempTargetId].
102-
*
103-
* @see SendChannelMessageApi.tempTargetId
104-
* @see SendChannelMessageApi.quote
105-
*/
106-
@ST
107-
public suspend fun send(message: Message, quote: ID? = null, tempTargetId: ID? = null): KookMessageReceipt
108-
109-
/**
110-
* 发送消息,并可选的指定 [quote] 和 [tempTargetId].
111-
*
112-
* @see SendChannelMessageApi.tempTargetId
113-
* @see SendChannelMessageApi.quote
114-
*/
115-
@ST
116-
public suspend fun send(
117-
message: MessageContent,
118-
quote: ID? = null,
119-
tempTargetId: ID? = null,
120-
): KookMessageReceipt
121-
122-
123-
/**
124-
* 发送纯文本消息。
125-
*/
126-
@ST
127-
override suspend fun send(text: String): KookMessageReceipt =
128-
send(
129-
MessageType.TEXT.type,
130-
text,
131-
null, null, null
132-
)
133-
134-
/**
135-
* 发送消息。
136-
*/
137-
@ST
138-
override suspend fun send(message: Message): KookMessageReceipt =
139-
send(message, null)
140-
141-
/**
142-
* 发送消息。
143-
*/
144-
@ST
145-
override suspend fun send(messageContent: MessageContent): KookMessageReceipt =
146-
send(messageContent, null)
147-
148-
// endregion
149-
}
25+
public interface KookChatChannel : KookChatCapableChannel
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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
22+
23+
/**
24+
* 一个 KOOK 中的语音子频道。
25+
*
26+
* @since 4.2.0
27+
* @author ForteScarlet
28+
*/
29+
public interface KookVoiceChannel : KookChatChannel {
30+
// TODO 相关整合
31+
}

simbot-component-kook-core/src/commonMain/kotlin/love/forte/simbot/component/kook/bot/internal/KookBotEvents.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ internal fun KookBotImpl.registerEvent() {
334334
)
335335
} else {
336336
val channel = inCacheModify {
337-
KookChatChannelImpl(bot = thisBot, source = channelBody).also {
337+
channelBody.toChatChannel(thisBot).also {
338338
channels[channelBody.id] = it
339339
}
340340
}
@@ -380,7 +380,7 @@ internal fun KookBotImpl.registerEvent() {
380380
)
381381
} else {
382382
val channel = inCacheModify {
383-
KookChatChannelImpl(thisBot, channelBody).also {
383+
channelBody.toChatChannel(thisBot).also {
384384
channels[channelBody.id] = it
385385
}
386386
}
@@ -540,7 +540,7 @@ internal fun KookBotImpl.registerEvent() {
540540
event.doAs(),
541541
guild,
542542
newMember,
543-
oldMember!!,
543+
oldMember,
544544
rawEvent
545545
)
546546
)

0 commit comments

Comments
 (0)