Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
whitechi73 committed Nov 21, 2023
2 parents b9ef0ca + 040b132 commit 4266afd
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 6 deletions.
49 changes: 49 additions & 0 deletions xposed/src/main/java/moe/fuqiuluo/qqinterface/servlet/GroupSvc.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ import kotlinx.coroutines.suspendCancellableCoroutine
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlinx.coroutines.withTimeoutOrNull
import moe.fuqiuluo.proto.ProtoUtils
import moe.fuqiuluo.proto.asUtf8String
import moe.fuqiuluo.proto.protobufOf
import moe.fuqiuluo.shamrock.helper.LogCenter
import moe.fuqiuluo.shamrock.tools.ifNullOrEmpty
import moe.fuqiuluo.shamrock.tools.putBuf32Long
import moe.fuqiuluo.shamrock.tools.slice
Expand All @@ -32,6 +35,7 @@ import mqq.app.MobileQQ
import tencent.im.oidb.cmd0x89a.oidb_0x89a
import tencent.im.oidb.cmd0x8a0.oidb_0x8a0
import tencent.im.oidb.cmd0x8fc.Oidb_0x8fc
import tencent.im.oidb.oidb_sso
import java.lang.reflect.Method
import java.lang.reflect.Modifier
import java.nio.ByteBuffer
Expand Down Expand Up @@ -139,6 +143,51 @@ internal object GroupSvc: BaseSvc() {
return true
}

suspend fun setEssenceMessage(groupId: Long, seq: Long, rand: Long): Pair<Boolean, String> {
val array = protobufOf(
1 to groupId,
2 to seq,
3 to rand
).toByteArray()
val buffer = sendOidbAW("OidbSvc.0xeac_1", 3756, 1, array)
val body = oidb_sso.OIDBSSOPkg()
if (buffer == null) {
return Pair(false, "unknown error")
}
body.mergeFrom(buffer.slice(4))
val result = ProtoUtils.decodeFromByteArray(body.bytes_bodybuffer.get().toByteArray())
return if (result.has(1)) {
LogCenter.log("设置群精华失败: ${result[1].asUtf8String}")
Pair(false, "设置群精华失败: ${result[1].asUtf8String}")
} else {
LogCenter.log("设置群精华 -> $groupId:$seq")
Pair(true, "ok")
}
}

suspend fun deleteEssenceMessage(groupId: Long, seq: Long, rand: Long): Pair<Boolean, String> {
val array = protobufOf(
1 to groupId,
2 to seq,
3 to rand
).toByteArray()
val buffer = sendOidbAW("OidbSvc.0xeac_2", 3756, 2, array)
val body = oidb_sso.OIDBSSOPkg()
if (buffer == null) {
return Pair(false, "unknown error")
}
body.mergeFrom(buffer.slice(4))
val result = ProtoUtils.decodeFromByteArray(body.bytes_bodybuffer.get().toByteArray())
return if (result.has(1)) {
LogCenter.log("移除群精华失败: ${result[1].asUtf8String}")
Pair(false, "移除群精华失败: ${result[1].asUtf8String}")
} else {
LogCenter.log("移除群精华 -> $groupId:$seq")
Pair(true, "ok")
}

}

fun setGroupAdmin(groupId: Long, userId: Long, enable: Boolean) {
val buffer = ByteBuffer.allocate(9)
buffer.putBuf32Long(groupId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal object ActionManager {

// GroupActions
ModifyTroopName, LeaveTroop, KickTroopMember, BanTroopMember, SetGroupWholeBan, SetGroupAdmin,
ModifyTroopMemberName, SetGroupUnique, GetTroopHonor, GroupPoke,
ModifyTroopMemberName, SetGroupUnique, GetTroopHonor, GroupPoke, SetEssenceMessage, DeleteEssenceMessage,

// MSG ACTIONS
SendMessage, DeleteMessage, GetMsg, GetForwardMsg, SendGroupForwardMsg, SendGroupMessage, SendPrivateMessage,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package moe.fuqiuluo.shamrock.remote.action.handlers

import com.tencent.qqnt.kernel.nativeinterface.MsgConstant
import kotlinx.serialization.json.JsonElement
import moe.fuqiuluo.qqinterface.servlet.GroupSvc
import moe.fuqiuluo.qqinterface.servlet.MsgSvc
import moe.fuqiuluo.shamrock.remote.action.ActionSession
import moe.fuqiuluo.shamrock.remote.action.IActionHandler
import moe.fuqiuluo.shamrock.tools.EmptyJsonString

internal object DeleteEssenceMessage: IActionHandler() {
override suspend fun internalHandle(session: ActionSession): String {
val messageId = session.getInt("message_id")
return invoke(messageId, session.echo)
}

suspend operator fun invoke(messageId: Int, echo: JsonElement = EmptyJsonString): String {
val msg = MsgSvc.getMsg(messageId).onFailure {
return logic("Obtain msg failed, please check your msg_id.", echo)
}.getOrThrow()
val (success, tip) = GroupSvc.deleteEssenceMessage(
if (msg.chatType == MsgConstant.KCHATTYPEGROUP) msg.peerUin else 0,
msg.msgSeq,
msg.msgRandom
)
return if (success) {
ok("成功", echo)
} else {
logic(tip, echo)
}
}

override val alias: Array<String> = arrayOf("delete_essence_message")
override fun path(): String = "delete_essence_msg"
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal object GetMsg: IActionHandler() {
val msg = MsgSvc.getMsg(msgHash).onFailure {
return logic("Obtain msg failed, please check your msg_id.", echo)
}.getOrThrow()
val seq = msg.clientSeq.toInt()
val seq = msg.msgSeq.toInt()
return ok(MessageDetail(
time = msg.msgTime.toInt(),
msgType = MessageHelper.obtainDetailTypeByMsgType(msg.chatType),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ internal object SendMessage: IActionHandler() {
}
return ok(MessageResult(
msgId = result.second,
time = result.first * 0.001
time = (result.first * 0.001).toLong()
), echo = echo)
}

Expand All @@ -103,7 +103,7 @@ internal object SendMessage: IActionHandler() {
}
return ok(MessageResult(
msgId = result.second,
time = result.first * 0.001
time = (result.first * 0.001).toLong()
), echo)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package moe.fuqiuluo.shamrock.remote.action.handlers

import com.tencent.qqnt.kernel.nativeinterface.MsgConstant
import kotlinx.serialization.json.JsonElement
import moe.fuqiuluo.qqinterface.servlet.GroupSvc
import moe.fuqiuluo.qqinterface.servlet.MsgSvc
import moe.fuqiuluo.shamrock.remote.action.ActionSession
import moe.fuqiuluo.shamrock.remote.action.IActionHandler
import moe.fuqiuluo.shamrock.tools.EmptyJsonString

internal object SetEssenceMessage: IActionHandler() {
override suspend fun internalHandle(session: ActionSession): String {
val messageId = session.getInt("message_id")
return invoke(messageId, session.echo)
}

suspend operator fun invoke(messageId: Int, echo: JsonElement = EmptyJsonString): String {
val msg = MsgSvc.getMsg(messageId).onFailure {
return logic("Obtain msg failed, please check your msg_id.", echo)
}.getOrThrow()
val (success, tip) = GroupSvc.setEssenceMessage(
if (msg.chatType == MsgConstant.KCHATTYPEGROUP) msg.peerUin else 0,
msg.msgSeq,
msg.msgRandom
)
return if (success) {
ok("成功", echo)
} else {
logic(tip, echo)
}

}

override val alias: Array<String> = arrayOf("set_essence_message")
override fun path(): String = "set_essence_msg"
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,15 @@ fun Routing.troopAction() {
val groupId = fetchOrThrow("group_id").toLong()
call.respondText(KickTroopMember(groupId, userId), ContentType.Application.Json)
}

getOrPost("/set_essence_msg") {
val messageId = fetchOrThrow("message_id").toInt()
call.respondText(SetEssenceMessage(messageId), ContentType.Application.Json)
}

getOrPost("/delete_essence_msg") {
val messageId = fetchOrThrow("message_id").toInt()
call.respondText(DeleteEssenceMessage(messageId), ContentType.Application.Json)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ internal object GlobalEventTransmitter: BaseSvc() {
type = noticeType,
subType = noticeSubType,
operatorId = operation,
userId = operation,
userId = target,
senderId = operation,
target = target,
groupId = groupCode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import kotlinx.serialization.json.JsonElement
@Serializable
internal data class MessageResult(
@SerialName("message_id") val msgId: Int,
@SerialName("time") val time: Double
@SerialName("time") val time: Long
)

@Serializable
Expand Down

0 comments on commit 4266afd

Please sign in to comment.