mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-18 09:07:04 +08:00
Add low level api for getting group honor members list. (#501)
* Add low level api for getting group honor members list. * Remove default value for level name, unifies serialize result typing in GroupHonorTypeSerializer * Remove unnecessary commas * Remove filed 'bkn' from GroupHonorListData to prevent potential credential leak * _GetGroupHonorList support getting ACTIVE data * Add @SinceMirai("1.3.0") annotation to GroupHonorInfo * Add @JvmStatic annotation, rename GroupHonorType.fromInt to .deserializeFromInt and make it internal
This commit is contained in:
parent
19e8d8c6ed
commit
1faccc72f3
@ -622,6 +622,30 @@ internal abstract class QQAndroidBotBase constructor(
|
||||
return json.decodeFromString(GroupActiveData.serializer(), rep)
|
||||
}
|
||||
|
||||
@LowLevelAPI
|
||||
@MiraiExperimentalAPI
|
||||
override suspend fun _lowLevelGetGroupHonorListData(groupId: Long, type: GroupHonorType): GroupHonorListData? {
|
||||
val data = network.async {
|
||||
MiraiPlatformUtils.Http.get<String> {
|
||||
url("https://qun.qq.com/interactive/honorlist")
|
||||
parameter("gc", groupId)
|
||||
parameter("type", type.value)
|
||||
headers {
|
||||
append(
|
||||
"cookie",
|
||||
"uin=o${id};" +
|
||||
" skey=${client.wLoginSigInfo.sKey.data.encodeToString()};" +
|
||||
" p_uin=o${id};" +
|
||||
" p_skey=${client.wLoginSigInfo.psKeyMap["qun.qq.com"]?.data?.encodeToString()}; "
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
val rep = data.await()
|
||||
val jsonText = Regex("""window.__INITIAL_STATE__=(.+?)</script>""").find(rep)?.groupValues?.get(1)
|
||||
return jsonText?.let { json.decodeFromString(GroupHonorListData.serializer(), it) }
|
||||
}
|
||||
|
||||
@JvmSynthetic
|
||||
@LowLevelAPI
|
||||
@MiraiExperimentalAPI
|
||||
|
@ -0,0 +1,237 @@
|
||||
package net.mamoe.mirai.data
|
||||
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.descriptors.PrimitiveKind
|
||||
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
|
||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
import net.mamoe.mirai.utils.MiraiExperimentalAPI
|
||||
import net.mamoe.mirai.utils.SinceMirai
|
||||
import kotlin.jvm.JvmStatic
|
||||
|
||||
/**
|
||||
* 群荣誉信息
|
||||
*/
|
||||
@MiraiExperimentalAPI
|
||||
@SinceMirai("1.3.0")
|
||||
public enum class GroupHonorType(public val value: Int) {
|
||||
TALKATIVE(1), // 龙王
|
||||
PERFORMER(2), // 群聊之火
|
||||
LEGEND(3), // 群聊炽焰
|
||||
STRONG_NEWBIE(5), // 冒尖小春笋
|
||||
EMOTION(6), // 快乐源泉
|
||||
ACTIVE(7), // 活跃头衔
|
||||
EXCLUSIVE(8), // 特殊头衔
|
||||
MANAGE(9); // 管理头衔
|
||||
internal companion object {
|
||||
@JvmStatic
|
||||
internal fun deserializeFromInt(value: Int): GroupHonorType = values().first { it.value == value }
|
||||
}
|
||||
}
|
||||
|
||||
@MiraiExperimentalAPI
|
||||
@SinceMirai("1.3.0")
|
||||
@Serializable
|
||||
public data class GroupHonorListData(
|
||||
@SerialName("acceptLanguages")
|
||||
val acceptLanguages: List<Language?>? = null,
|
||||
|
||||
@SerialName("gc")
|
||||
val gc: String?,
|
||||
|
||||
@Serializable(with = GroupHonorTypeSerializer::class)
|
||||
@SerialName("type")
|
||||
val type: GroupHonorType?,
|
||||
|
||||
@SerialName("uin")
|
||||
val uin: String?,
|
||||
|
||||
@SerialName("talkativeList")
|
||||
val talkativeList: List<Talkative?>? = null,
|
||||
|
||||
@SerialName("currentTalkative")
|
||||
val currentTalkative: CurrentTalkative? = null,
|
||||
|
||||
@SerialName("actorList")
|
||||
val actorList: List<Actor?>? = null,
|
||||
|
||||
@SerialName("legendList")
|
||||
val legendList: List<Actor?>? = null,
|
||||
|
||||
@SerialName("newbieList")
|
||||
val newbieList: List<Actor?>? = null,
|
||||
|
||||
@SerialName("strongnewbieList")
|
||||
val strongNewbieList: List<Actor?>? = null,
|
||||
|
||||
@SerialName("emotionList")
|
||||
val emotionList: List<Actor?>? = null,
|
||||
|
||||
@SerialName("levelname")
|
||||
val levelName: LevelName? = null,
|
||||
|
||||
@SerialName("manageList")
|
||||
val manageList: List<Tag?>? = null,
|
||||
|
||||
@SerialName("exclusiveList")
|
||||
val exclusiveList: List<Tag?>? = null,
|
||||
|
||||
@SerialName("activeObj")
|
||||
val activeObj: Map<String, List<Tag?>?>? = null, // Key为活跃等级名, 如`冒泡`
|
||||
|
||||
@SerialName("showActiveObj")
|
||||
val showActiveObj: Map<String, Boolean?>? = null,
|
||||
|
||||
@SerialName("myTitle")
|
||||
val myTitle: String?,
|
||||
|
||||
@SerialName("myIndex")
|
||||
val myIndex: Int? = 0,
|
||||
|
||||
@SerialName("myAvatar")
|
||||
val myAvatar: String?,
|
||||
|
||||
@SerialName("hasServerError")
|
||||
val hasServerError: Boolean?,
|
||||
|
||||
@SerialName("hwExcellentList")
|
||||
val hwExcellentList: List<Actor?>? = null
|
||||
) {
|
||||
@Serializable
|
||||
public data class Language(
|
||||
@SerialName("code")
|
||||
val code: String? = null,
|
||||
|
||||
@SerialName("script")
|
||||
val script: String? = null,
|
||||
|
||||
@SerialName("region")
|
||||
val region: String? = null,
|
||||
|
||||
@SerialName("quality")
|
||||
val quality: Double? = null
|
||||
)
|
||||
|
||||
@Serializable
|
||||
public data class Actor(
|
||||
@SerialName("uin")
|
||||
val uin: Long? = 0,
|
||||
|
||||
@SerialName("avatar")
|
||||
val avatar: String? = null,
|
||||
|
||||
@SerialName("name")
|
||||
val name: String? = null,
|
||||
|
||||
@SerialName("desc")
|
||||
val desc: String? = null,
|
||||
|
||||
@SerialName("btnText")
|
||||
val btnText: String? = null,
|
||||
|
||||
@SerialName("text")
|
||||
val text: String? = null,
|
||||
|
||||
@SerialName("icon")
|
||||
val icon: Int?
|
||||
)
|
||||
|
||||
@Serializable
|
||||
public data class Talkative(
|
||||
@SerialName("uin")
|
||||
val uin: Long? = 0,
|
||||
|
||||
@SerialName("avatar")
|
||||
val avatar: String? = null,
|
||||
|
||||
@SerialName("name")
|
||||
val name: String? = null,
|
||||
|
||||
@SerialName("desc")
|
||||
val desc: String? = null,
|
||||
|
||||
@SerialName("btnText")
|
||||
val btnText: String? = null,
|
||||
|
||||
@SerialName("text")
|
||||
val text: String? = null
|
||||
)
|
||||
|
||||
@Serializable
|
||||
public data class CurrentTalkative(
|
||||
@SerialName("uin")
|
||||
val uin: Long? = 0,
|
||||
|
||||
@SerialName("day_count")
|
||||
val dayCount: Int? = null,
|
||||
|
||||
@SerialName("avatar")
|
||||
val avatar: String? = null,
|
||||
|
||||
@SerialName("avatar_size")
|
||||
val avatarSize: Int? = null,
|
||||
|
||||
@SerialName("nick")
|
||||
val nick: String? = null
|
||||
)
|
||||
|
||||
@Serializable
|
||||
public data class LevelName(
|
||||
@SerialName("lvln1")
|
||||
val lv1: String? = null,
|
||||
|
||||
@SerialName("lvln2")
|
||||
val lv2: String? = null,
|
||||
|
||||
@SerialName("lvln3")
|
||||
val lv3: String? = null,
|
||||
|
||||
@SerialName("lvln4")
|
||||
val lv4: String? = null,
|
||||
|
||||
@SerialName("lvln5")
|
||||
val lv5: String? = null,
|
||||
|
||||
@SerialName("lvln6")
|
||||
val lv6: String? = null
|
||||
)
|
||||
|
||||
@Serializable
|
||||
public data class Tag(
|
||||
@SerialName("uin")
|
||||
val uin: Long? = 0,
|
||||
|
||||
@SerialName("avatar")
|
||||
val avatar: String? = null,
|
||||
|
||||
@SerialName("name")
|
||||
val name: String? = null,
|
||||
|
||||
@SerialName("btnText")
|
||||
val btnText: String? = null,
|
||||
|
||||
@SerialName("text")
|
||||
val text: String? = null,
|
||||
|
||||
@SerialName("tag")
|
||||
val tag: String? = null, // 头衔
|
||||
|
||||
@SerialName("tagColor")
|
||||
val tagColor: String? = null
|
||||
)
|
||||
|
||||
@Serializer(forClass = GroupHonorType::class)
|
||||
public object GroupHonorTypeSerializer : KSerializer<GroupHonorType> {
|
||||
override val descriptor: SerialDescriptor =
|
||||
PrimitiveSerialDescriptor("GroupHonorTypeSerializer", PrimitiveKind.INT)
|
||||
|
||||
override fun serialize(encoder: Encoder, value: GroupHonorType) {
|
||||
encoder.encodeInt(value.value)
|
||||
}
|
||||
|
||||
override fun deserialize(decoder: Decoder): GroupHonorType {
|
||||
return GroupHonorType.deserializeFromInt(decoder.decodeInt())
|
||||
}
|
||||
}
|
||||
}
|
@ -115,6 +115,14 @@ public interface LowLevelBotAPIAccessor {
|
||||
public suspend fun _lowLevelGetGroupActiveData(groupId: Long, page: Int = -1): GroupActiveData
|
||||
|
||||
|
||||
/**
|
||||
* 获取群荣誉信息
|
||||
*/
|
||||
@LowLevelAPI
|
||||
@MiraiExperimentalAPI
|
||||
public suspend fun _lowLevelGetGroupHonorListData(groupId: Long, type: GroupHonorType): GroupHonorListData?
|
||||
|
||||
|
||||
/**
|
||||
* 处理一个账号请求添加机器人为好友的事件
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user