Skip to content

Commit 3b92180

Browse files
committed
feat: flag and docs
1 parent 049dd90 commit 3b92180

File tree

9 files changed

+111
-17
lines changed

9 files changed

+111
-17
lines changed

mirai-core-api/src/commonMain/kotlin/contact/Member.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ package net.mamoe.mirai.contact
1414

1515
import me.him188.kotlin.jvm.blocking.bridge.JvmBlockingBridge
1616
import net.mamoe.mirai.Bot
17-
import net.mamoe.mirai.data.GroupHonorType
17+
import net.mamoe.mirai.contact.active.GroupHonorFlag
1818
import net.mamoe.mirai.event.events.*
1919
import net.mamoe.mirai.message.MessageReceipt
2020
import net.mamoe.mirai.message.action.MemberNudge
@@ -87,14 +87,14 @@ public interface Member : User {
8787
/**
8888
* 群荣誉标识.
8989
*/
90-
public val honor: Set<GroupHonorType>
90+
public val honor: Set<GroupHonorFlag>
9191

9292
/**
9393
* 群荣誉等级. 取值为 0~100
9494
*
9595
* 这个等级是在 手机端 群荣誉功能中显示的等级
9696
*/
97-
public val active: Int
97+
public val temperature: Int
9898

9999
/**
100100
* 禁言这个群成员 [durationSeconds] 秒, 在机器人无权限操作时抛出 [PermissionDeniedException].

mirai-core-api/src/commonMain/kotlin/contact/active/Active.kt

+43-1
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,46 @@
1010
package net.mamoe.mirai.contact.active
1111

1212
import kotlinx.coroutines.flow.Flow
13+
import net.mamoe.mirai.contact.Group
1314
import net.mamoe.mirai.utils.MiraiExperimentalApi
1415
import net.mamoe.mirai.contact.Member
16+
import net.mamoe.mirai.contact.announcement.OfflineAnnouncement
17+
import net.mamoe.mirai.contact.announcement.OnlineAnnouncement
18+
import net.mamoe.mirai.utils.NotStableForInheritance
1519
import java.util.stream.Stream
1620

21+
/**
22+
* 表示一个群活跃度管理.
23+
*
24+
* ## 获取 [Active] 实例
25+
*
26+
* 只可以通过 [Group.active] 获取一个群的活跃度管理, 即 [Active] 实例.
27+
*
28+
* ### 等级头衔列表
29+
*
30+
* 通过 [rankTitles] 可以获取和设置一个群的等级头衔列表,
31+
* 通过 [rankShow] 可以获取和设置一个群的等级头衔是否显示
32+
*
33+
* 设置时,修改将异步发送到服务器
34+
*
35+
* ### 活跃度记录
36+
*
37+
* 通过 [asFlow] 或 [asStream] 可以获取群活跃度记录*惰性*流,
38+
* 在从流中收集数据时才会请求服务器获取数据. 通常建议在 Kotlin 使用协程的 [asFlow], 在 Java 使用 [asStream].
39+
*
40+
* 若要获取全部活跃度记录, 可使用 [toList].
41+
*
42+
* ### 活跃度图表
43+
*
44+
* 通过 [getChart] 可以获取活跃度图表,
45+
* 包括
46+
* * 每日总人数 [ActiveChart.members]
47+
* * 每日活跃人数 [ActiveChart.actives]
48+
* * 每日申请人数 [ActiveChart.sentences]
49+
* * 每日入群人数 [ActiveChart.join]
50+
* * 每日退群人数 [ActiveChart.exit]
51+
*/
52+
@NotStableForInheritance
1753
public interface Active {
1854

1955
/**
@@ -37,17 +73,23 @@ public interface Active {
3773
public var rankShow: Boolean
3874

3975
/**
76+
* 创建一个能获取该群内所有群活跃度记录的 [Flow]. 在 [Flow] 被使用时才会分页下载 [OnlineAnnouncement].
4077
*
78+
* 异常不会抛出, 只会记录到网络日志. 当获取发生异常时将会终止获取, 不影响已经成功获取的 [ActiveRecord] 和 [Flow] 的[收集][Flow.collect].
4179
*/
4280
public fun asFlow(): Flow<ActiveRecord>
4381

4482
/**
83+
* 创建一个能获取该群内所有群活跃度记录的 [Stream]. 在 [Stream] 被使用时才会分页下载 [OnlineAnnouncement].
84+
*
85+
* 异常不会抛出, 只会记录到网络日志. 当获取发生异常时将会终止获取, 不影响已经成功获取的 [ActiveRecord] 和 [Stream] 的[收集][Stream.collect].
4586
*
87+
* 实现细节: 为了适合 Java 调用, 实现类似为阻塞式的 [asFlow], 因此不建议在 Kotlin 使用. 在 Kotlin 请使用 [asFlow].
4688
*/
4789
public fun asStream(): Stream<ActiveRecord>
4890

4991
/**
50-
*
92+
* 获取活跃度图表数据
5193
*/
5294
public suspend fun getChart(): ActiveChart?
5395
}

mirai-core-api/src/commonMain/kotlin/contact/active/ActiveChart.kt

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
package net.mamoe.mirai.contact.active
1111

12+
/**
13+
* 活跃度数据图表
14+
*/
1215
public interface ActiveChart {
1316
public val actives: Map<String, Int>
1417
public val sentences: Map<String, Int>

mirai-core-api/src/commonMain/kotlin/contact/active/ActiveRecord.kt

+22
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,32 @@ package net.mamoe.mirai.contact.active
1111

1212
import net.mamoe.mirai.contact.NormalMember
1313

14+
/**
15+
* 活跃数据记录
16+
*/
1417
public interface ActiveRecord {
18+
/**
19+
* 发言者名称
20+
*/
1521
public val senderName: String
22+
23+
/**
24+
* 发言者 ID
25+
*/
1626
public val senderId: Long
27+
28+
/**
29+
* 发言者的群员实例
30+
*/
1731
public val sender: NormalMember?
32+
33+
/**
34+
* 活跃连续天数
35+
*/
1836
public val continuation: Int
37+
38+
/**
39+
* 发言条数
40+
*/
1941
public val sentences: Int
2042
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2019-2022 Mamoe Technologies and contributors.
3+
*
4+
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
5+
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
6+
*
7+
* https://github.com/mamoe/mirai/blob/dev/LICENSE
8+
*/
9+
10+
package net.mamoe.mirai.contact.active
11+
12+
/**
13+
* 群荣誉标志
14+
*/
15+
public enum class GroupHonorFlag(private val value: Int) {
16+
TALKATIVE(1), // 龙王
17+
PERFORMER(2), // 群聊之火
18+
LEGEND(3), // 群聊炽焰
19+
STRONG_NEWBIE(5), // 冒尖小春笋
20+
EMOTION(6); // 快乐源泉
21+
22+
public companion object {
23+
@JvmStatic
24+
public fun deserializeFromInt(value: Int): GroupHonorFlag? = values().find { it.value == value }
25+
}
26+
}

mirai-core-api/src/commonMain/kotlin/data/GroupHonorListData.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ public enum class GroupHonorType(public val value: Int) {
3434
EXCLUSIVE(8), // 特殊头衔
3535
MANAGE(9); // 管理头衔
3636

37-
public companion object {
37+
internal companion object {
3838
@JvmStatic
39-
public fun deserializeFromInt(value: Int): GroupHonorType = values().first { it.value == value }
39+
internal fun deserializeFromInt(value: Int): GroupHonorType = values().first { it.value == value }
4040
}
4141
}
4242

mirai-core-api/src/commonMain/kotlin/data/MemberInfo.kt

+4-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ package net.mamoe.mirai.data
1111

1212
import net.mamoe.mirai.LowLevelApi
1313
import net.mamoe.mirai.contact.MemberPermission
14+
import net.mamoe.mirai.contact.active.GroupHonorFlag
1415

1516
@LowLevelApi
1617
public interface MemberInfo : UserInfo {
@@ -52,12 +53,12 @@ public interface MemberInfo : UserInfo {
5253
public val point: Int
5354

5455
/**
55-
* 群荣誉
56+
* 群荣誉标志
5657
*/
57-
public val honor: Set<GroupHonorType>
58+
public val honor: Set<GroupHonorFlag>
5859

5960
/**
6061
* 活跃度
6162
*/
62-
public val active: Int
63+
public val temperature: Int
6364
}

mirai-core/src/commonMain/kotlin/contact/AbstractMember.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ package net.mamoe.mirai.internal.contact
1111

1212
import net.mamoe.mirai.contact.Member
1313
import net.mamoe.mirai.contact.MemberPermission
14-
import net.mamoe.mirai.data.GroupHonorType
14+
import net.mamoe.mirai.contact.active.GroupHonorFlag
1515
import net.mamoe.mirai.data.MemberInfo
1616
import net.mamoe.mirai.internal.contact.info.MemberInfoImpl
1717
import net.mamoe.mirai.utils.cast
@@ -32,8 +32,8 @@ internal sealed class AbstractMember(
3232
override val specialTitle: String get() = info.specialTitle
3333
override val rank: Int get() = info.rank
3434
override val point: Int get() = info.point
35-
override val honor: Set<GroupHonorType> get() = info.honor
36-
override val active: Int get() = info.active
35+
override val honor: Set<GroupHonorFlag> get() = info.honor
36+
override val temperature: Int get() = info.temperature
3737

3838
override var permission: MemberPermission by info::permission
3939
}

mirai-core/src/commonMain/kotlin/contact/info/MemberInfoImpl.kt

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ package net.mamoe.mirai.internal.contact.info
1111

1212
import kotlinx.serialization.Serializable
1313
import net.mamoe.mirai.contact.MemberPermission
14-
import net.mamoe.mirai.data.GroupHonorType
14+
import net.mamoe.mirai.contact.active.GroupHonorFlag
1515
import net.mamoe.mirai.data.MemberInfo
1616
import net.mamoe.mirai.internal.network.QQAndroidClient
1717
import net.mamoe.mirai.internal.network.protocol.data.jce.StTroopMemberInfo
@@ -33,8 +33,8 @@ internal data class MemberInfoImpl(
3333
override val isOfficialBot: Boolean = false,
3434
override val rank: Int = 1,
3535
override val point: Int = 0,
36-
override val honor: Set<GroupHonorType> = emptySet(),
37-
override val active: Int = 0
36+
override val honor: Set<GroupHonorFlag> = emptySet(),
37+
override val temperature: Int = 0
3838
) : MemberInfo {
3939
constructor(
4040
client: QQAndroidClient,
@@ -75,11 +75,11 @@ internal data class MemberInfoImpl(
7575
val type = bytes[index]
7676
if (type.toInt() == 8) {
7777
val value = bytes.getOrNull(index + 1) ?: break
78-
add(GroupHonorType.deserializeFromInt(value.toInt()))
78+
add(GroupHonorFlag.deserializeFromInt(value.toInt()) ?: continue)
7979
}
8080
}
8181
},
82-
active = jceInfo.vecGroupHonor?.let { bytes ->
82+
temperature = jceInfo.vecGroupHonor?.let { bytes ->
8383
for (index in bytes.indices step 2) {
8484
val type = bytes[index]
8585
if (type.toInt() == 16) {

0 commit comments

Comments
 (0)