mirror of
https://github.com/whitechi73/OpenShamrock.git
synced 2024-08-14 13:12:17 +08:00
fix #337
This commit is contained in:
parent
e2f27cb36a
commit
36ed55d220
@ -73,7 +73,6 @@ import moe.fuqiuluo.shamrock.tools.decodeToObject
|
|||||||
import moe.fuqiuluo.shamrock.tools.decodeToOidb
|
import moe.fuqiuluo.shamrock.tools.decodeToOidb
|
||||||
import moe.fuqiuluo.shamrock.tools.ifNullOrEmpty
|
import moe.fuqiuluo.shamrock.tools.ifNullOrEmpty
|
||||||
import moe.fuqiuluo.shamrock.tools.putBuf32Long
|
import moe.fuqiuluo.shamrock.tools.putBuf32Long
|
||||||
import moe.fuqiuluo.shamrock.tools.slice
|
|
||||||
import moe.fuqiuluo.shamrock.utils.FileUtils
|
import moe.fuqiuluo.shamrock.utils.FileUtils
|
||||||
import moe.fuqiuluo.shamrock.utils.PlatformUtils
|
import moe.fuqiuluo.shamrock.utils.PlatformUtils
|
||||||
import moe.fuqiuluo.shamrock.utils.PlatformUtils.QQ_9_0_65_VER
|
import moe.fuqiuluo.shamrock.utils.PlatformUtils.QQ_9_0_65_VER
|
||||||
@ -287,14 +286,24 @@ internal object GroupSvc: QQInterfaces() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
suspend fun setGroupUniqueTitle(groupId: Long, userId: Long, title: String) {
|
suspend fun setGroupUniqueTitle(groupId: Long, userId: Long, title: String) {
|
||||||
val localMemberInfo = getTroopMemberInfoByUin(groupId, userId, true).getOrThrow()
|
var nick = getTroopMemberInfoByUinV2(groupId, userId, true).getOrThrow().let {
|
||||||
|
it.troopnick.ifEmpty { it.troopremark.ifNullOrEmpty("") }
|
||||||
|
}
|
||||||
|
if (PlatformUtils.getQQVersionCode() > QQ_9_0_65_VER && nick == null) {
|
||||||
|
nick = getTroopMemberNickByUin(groupId, userId)?.let {
|
||||||
|
it.troopNick
|
||||||
|
.ifNullOrEmpty(it.friendNick)
|
||||||
|
.ifNullOrEmpty(it.showName)
|
||||||
|
.ifNullOrEmpty(it.autoRemark)
|
||||||
|
.ifNullOrEmpty(it.colorNick)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val req = Oidb_0x8fc.ReqBody()
|
val req = Oidb_0x8fc.ReqBody()
|
||||||
req.uint64_group_code.set(groupId)
|
req.uint64_group_code.set(groupId)
|
||||||
val memberInfo = Oidb_0x8fc.MemberInfo()
|
val memberInfo = Oidb_0x8fc.MemberInfo()
|
||||||
memberInfo.uint64_uin.set(userId)
|
memberInfo.uint64_uin.set(userId)
|
||||||
memberInfo.bytes_uin_name.set(ByteStringMicro.copyFromUtf8(localMemberInfo.troopnick.ifEmpty {
|
memberInfo.bytes_uin_name.set(ByteStringMicro.copyFromUtf8(nick))
|
||||||
localMemberInfo.troopremark.ifNullOrEmpty("")
|
|
||||||
}))
|
|
||||||
memberInfo.bytes_special_title.set(ByteStringMicro.copyFromUtf8(title))
|
memberInfo.bytes_special_title.set(ByteStringMicro.copyFromUtf8(title))
|
||||||
memberInfo.uint32_special_title_expire_time.set(-1)
|
memberInfo.uint32_special_title_expire_time.set(-1)
|
||||||
req.rpt_mem_level_info.add(memberInfo)
|
req.rpt_mem_level_info.add(memberInfo)
|
||||||
@ -573,60 +582,6 @@ internal object GroupSvc: QQInterfaces() {
|
|||||||
return body.signed_ark.get().toStringUtf8()
|
return body.signed_ark.get().toStringUtf8()
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getTroopMemberInfoByUin(
|
|
||||||
groupId: Long,
|
|
||||||
uin: Long,
|
|
||||||
refresh: Boolean = false
|
|
||||||
): Result<TroopMemberInfo> {
|
|
||||||
val service = app.getRuntimeService(ITroopMemberInfoService::class.java, "all")
|
|
||||||
var info = service.getTroopMember(groupId.toString(), uin.toString())
|
|
||||||
if (refresh || !service.isMemberInCache(groupId.toString(), uin.toString()) || info == null || info.troopnick == null) {
|
|
||||||
info = requestTroopMemberInfo(service, groupId, uin).getOrNull()
|
|
||||||
}
|
|
||||||
if (info == null) {
|
|
||||||
info = getTroopMemberInfoByUinViaNt(groupId, uin).getOrNull()?.let {
|
|
||||||
TroopMemberInfo().apply {
|
|
||||||
troopnick = it.cardName
|
|
||||||
friendnick = it.nick
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
if (info != null && (info.alias == null || info.alias.isBlank())) {
|
|
||||||
val req = group_member_info.ReqBody()
|
|
||||||
req.uint64_group_code.set(groupId)
|
|
||||||
req.uint64_uin.set(uin.toLong())
|
|
||||||
req.bool_new_client.set(true)
|
|
||||||
req.uint32_client_type.set(1)
|
|
||||||
req.uint32_rich_card_name_ver.set(1)
|
|
||||||
val respBuffer = sendBufferAW("group_member_card.get_group_member_card_info", true, req.toByteArray())
|
|
||||||
if (respBuffer != null) {
|
|
||||||
val rsp = respBuffer.decodeToObject(group_member_info.RspBody())
|
|
||||||
if (rsp.msg_meminfo.str_location.has()) {
|
|
||||||
info.alias = rsp.msg_meminfo.str_location.get().toStringUtf8()
|
|
||||||
}
|
|
||||||
if (rsp.msg_meminfo.uint32_age.has()) {
|
|
||||||
info.age = rsp.msg_meminfo.uint32_age.get().toByte()
|
|
||||||
}
|
|
||||||
if (rsp.msg_meminfo.bytes_group_honor.has()) {
|
|
||||||
val honorBytes = rsp.msg_meminfo.bytes_group_honor.get().toByteArray()
|
|
||||||
val honor = troop_honor.GroupUserCardHonor()
|
|
||||||
honor.mergeFrom(honorBytes)
|
|
||||||
info.level = honor.level.get()
|
|
||||||
// 10315: medal_id not real group level
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (err: Throwable) {
|
|
||||||
LogCenter.log(err.stackTraceToString(), Level.WARN)
|
|
||||||
}
|
|
||||||
return if (info != null) {
|
|
||||||
Result.success(info)
|
|
||||||
} else {
|
|
||||||
Result.failure(Exception("获取群成员信息失败"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getTroopMemberInfoByUinFromNt(
|
fun getTroopMemberInfoByUinFromNt(
|
||||||
groupId: Long,
|
groupId: Long,
|
||||||
uin: Long
|
uin: Long
|
||||||
@ -638,7 +593,7 @@ internal object GroupSvc: QQInterfaces() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getTroopMemberInfoByUinV3(
|
suspend fun getTroopMemberNickByUin(
|
||||||
groupId: Long,
|
groupId: Long,
|
||||||
uin: Long
|
uin: Long
|
||||||
): TroopMemberNickInfo? {
|
): TroopMemberNickInfo? {
|
||||||
|
@ -125,12 +125,12 @@ internal class ElemMaker {
|
|||||||
qq = qqStr.toLong()
|
qq = qqStr.toLong()
|
||||||
type = 0
|
type = 0
|
||||||
val name = (data["name"].asStringOrNull
|
val name = (data["name"].asStringOrNull
|
||||||
?: GroupSvc.getTroopMemberInfoByUinV3(peerId.toLong(), qq).let {
|
?: GroupSvc.getTroopMemberNickByUin(peerId.toLong(), qq)?.let {
|
||||||
it?.troopNick
|
it.troopNick
|
||||||
.ifNullOrEmpty(it?.friendNick)
|
.ifNullOrEmpty(it.friendNick)
|
||||||
.ifNullOrEmpty(it?.showName)
|
.ifNullOrEmpty(it.showName)
|
||||||
.ifNullOrEmpty(it?.autoRemark)
|
.ifNullOrEmpty(it.autoRemark)
|
||||||
.ifNullOrEmpty(it?.colorNick)
|
.ifNullOrEmpty(it.colorNick)
|
||||||
}
|
}
|
||||||
?: GroupSvc.getTroopMemberInfoByUinV2(peerId.toLong(), qq, true).let {
|
?: GroupSvc.getTroopMemberInfoByUinV2(peerId.toLong(), qq, true).let {
|
||||||
val info = it.getOrNull()
|
val info = it.getOrNull()
|
||||||
|
@ -857,12 +857,12 @@ internal object NtMsgElementMaker {
|
|||||||
}"
|
}"
|
||||||
} else {
|
} else {
|
||||||
at.content = "@${
|
at.content = "@${
|
||||||
GroupSvc.getTroopMemberInfoByUinV3(peerId.toLong(), qq).let {
|
GroupSvc.getTroopMemberNickByUin(peerId.toLong(), qq)?.let {
|
||||||
it?.troopNick
|
it.troopNick
|
||||||
.ifNullOrEmpty(it?.friendNick)
|
.ifNullOrEmpty(it.friendNick)
|
||||||
.ifNullOrEmpty(it?.showName)
|
.ifNullOrEmpty(it.showName)
|
||||||
.ifNullOrEmpty(it?.autoRemark)
|
.ifNullOrEmpty(it.autoRemark)
|
||||||
.ifNullOrEmpty(it?.colorNick)
|
.ifNullOrEmpty(it.colorNick)
|
||||||
} ?: qqStr
|
} ?: qqStr
|
||||||
}"
|
}"
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,8 @@ import moe.fuqiuluo.shamrock.remote.action.IActionHandler
|
|||||||
import moe.fuqiuluo.shamrock.remote.service.data.SimpleTroopMemberInfo
|
import moe.fuqiuluo.shamrock.remote.service.data.SimpleTroopMemberInfo
|
||||||
import moe.fuqiuluo.shamrock.tools.EmptyJsonString
|
import moe.fuqiuluo.shamrock.tools.EmptyJsonString
|
||||||
import moe.fuqiuluo.shamrock.tools.ifNullOrEmpty
|
import moe.fuqiuluo.shamrock.tools.ifNullOrEmpty
|
||||||
|
import moe.fuqiuluo.shamrock.utils.PlatformUtils
|
||||||
|
import moe.fuqiuluo.shamrock.utils.PlatformUtils.QQ_9_0_65_VER
|
||||||
import moe.fuqiuluo.symbols.OneBotHandler
|
import moe.fuqiuluo.symbols.OneBotHandler
|
||||||
|
|
||||||
@OneBotHandler("get_group_member_info")
|
@OneBotHandler("get_group_member_info")
|
||||||
@ -26,7 +28,7 @@ internal object GetTroopMemberInfo : IActionHandler() {
|
|||||||
refresh: Boolean,
|
refresh: Boolean,
|
||||||
echo: JsonElement = EmptyJsonString
|
echo: JsonElement = EmptyJsonString
|
||||||
): String {
|
): String {
|
||||||
val info = GroupSvc.getTroopMemberInfoByUin(groupId, userId, refresh).onFailure {
|
val info = GroupSvc.getTroopMemberInfoByUinV2(groupId, userId, refresh).onFailure {
|
||||||
return error(it.message ?: "unknown error", echo)
|
return error(it.message ?: "unknown error", echo)
|
||||||
}.getOrThrow()
|
}.getOrThrow()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user