mirror of
https://github.com/whitechi73/OpenShamrock.git
synced 2024-08-14 13:12:17 +08:00
Shamrock
: 連結転送のサポート(去勢)
This commit is contained in:
parent
5200a4d8d4
commit
ce1e850c78
@ -43,6 +43,10 @@ internal object TicketSvc: BaseSvc() {
|
|||||||
return app.currentUin.ifBlank { "0" }
|
return app.currentUin.ifBlank { "0" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getLongUin(): Long {
|
||||||
|
return app.longAccountUin
|
||||||
|
}
|
||||||
|
|
||||||
fun getCookie(): String {
|
fun getCookie(): String {
|
||||||
val uin = getUin()
|
val uin = getUin()
|
||||||
val skey = getRealSkey(uin)
|
val skey = getRealSkey(uin)
|
||||||
|
@ -33,7 +33,7 @@ internal object ActionManager {
|
|||||||
|
|
||||||
// MSG ACTIONS
|
// MSG ACTIONS
|
||||||
SendMessage, DeleteMessage, GetMsg, GetForwardMsg, SendGroupForwardMsg, SendGroupMessage, SendPrivateMessage,
|
SendMessage, DeleteMessage, GetMsg, GetForwardMsg, SendGroupForwardMsg, SendGroupMessage, SendPrivateMessage,
|
||||||
ClearMsgs, GetHistoryMsg, GetGroupMsgHistory,
|
ClearMsgs, GetHistoryMsg, GetGroupMsgHistory, SendPrivateForwardMsg,
|
||||||
|
|
||||||
// RESOURCE ACTION
|
// RESOURCE ACTION
|
||||||
GetRecord, GetImage, UploadGroupFile, CreateGroupFileFolder, DeleteGroupFolder,
|
GetRecord, GetImage, UploadGroupFile, CreateGroupFileFolder, DeleteGroupFolder,
|
||||||
|
@ -18,6 +18,7 @@ import moe.fuqiuluo.shamrock.tools.EmptyJsonString
|
|||||||
import moe.fuqiuluo.shamrock.tools.asInt
|
import moe.fuqiuluo.shamrock.tools.asInt
|
||||||
import moe.fuqiuluo.shamrock.tools.asJsonObject
|
import moe.fuqiuluo.shamrock.tools.asJsonObject
|
||||||
import moe.fuqiuluo.shamrock.tools.asString
|
import moe.fuqiuluo.shamrock.tools.asString
|
||||||
|
import moe.fuqiuluo.shamrock.tools.asStringOrNull
|
||||||
import moe.fuqiuluo.shamrock.tools.json
|
import moe.fuqiuluo.shamrock.tools.json
|
||||||
import moe.fuqiuluo.shamrock.xposed.helper.NTServiceFetcher
|
import moe.fuqiuluo.shamrock.xposed.helper.NTServiceFetcher
|
||||||
|
|
||||||
@ -43,10 +44,13 @@ internal object SendGroupForwardMsg: IActionHandler() {
|
|||||||
val selfUin = TicketSvc.getUin()
|
val selfUin = TicketSvc.getUin()
|
||||||
|
|
||||||
val msgs = message.map {
|
val msgs = message.map {
|
||||||
it.asJsonObject["data"].asJsonObject.let {
|
it.asJsonObject["data"].asJsonObject.let { data ->
|
||||||
if (it.containsKey("content"))
|
if (data.containsKey("content"))
|
||||||
MessageNode(it["name"].asString, it["content"])
|
MessageNode(
|
||||||
else MessageIdNode(it["id"].asInt)
|
name = data["name"].asStringOrNull ?: "",
|
||||||
|
content = data["content"]
|
||||||
|
)
|
||||||
|
else MessageIdNode(data["id"].asInt)
|
||||||
}
|
}
|
||||||
}.map {
|
}.map {
|
||||||
if (it is MessageIdNode) {
|
if (it is MessageIdNode) {
|
||||||
@ -72,14 +76,18 @@ internal object SendGroupForwardMsg: IActionHandler() {
|
|||||||
it.content != null
|
it.content != null
|
||||||
}
|
}
|
||||||
|
|
||||||
var forwardMsgCallback: (() -> Unit)? = null
|
lateinit var forwardMsgCallback: (() -> Unit)
|
||||||
val availableMsgSize = atomic(0)
|
val availableMsgSize = atomic(0)
|
||||||
val msgIds = msgs.map {
|
val msgIds = msgs.map {
|
||||||
it.name to MessageHelper.sendMessageWithMsgId(MsgConstant.KCHATTYPEC2C, selfUin, it.content!!.let { msg ->
|
it.name to MessageHelper.sendMessageWithMsgId(MsgConstant.KCHATTYPEC2C, selfUin, it.content!!.let { msg ->
|
||||||
if (msg is JsonArray) msg else MessageHelper.decodeCQCode(msg.asString)
|
if (msg is JsonArray) msg else MessageHelper.decodeCQCode(msg.asString)
|
||||||
}, { _, _ ->
|
}, { code, why ->
|
||||||
|
if (code != 0) {
|
||||||
|
availableMsgSize.incrementAndGet()
|
||||||
|
LogCenter.log("合并转发消息节点消息发送失败:$code($why)", Level.WARN)
|
||||||
|
}
|
||||||
if (availableMsgSize.incrementAndGet() == msgs.size) {
|
if (availableMsgSize.incrementAndGet() == msgs.size) {
|
||||||
forwardMsgCallback?.invoke()
|
forwardMsgCallback.invoke()
|
||||||
}
|
}
|
||||||
}).first
|
}).first
|
||||||
}
|
}
|
||||||
@ -87,7 +95,7 @@ internal object SendGroupForwardMsg: IActionHandler() {
|
|||||||
val from = MessageHelper.generateContact(MsgConstant.KCHATTYPEC2C, selfUin)
|
val from = MessageHelper.generateContact(MsgConstant.KCHATTYPEC2C, selfUin)
|
||||||
val to = MessageHelper.generateContact(MsgConstant.KCHATTYPEGROUP, groupId)
|
val to = MessageHelper.generateContact(MsgConstant.KCHATTYPEGROUP, groupId)
|
||||||
forwardMsgCallback = {
|
forwardMsgCallback = {
|
||||||
msgService.multiForwardMsg(ArrayList<MultiMsgInfo>(msgIds.size).apply {
|
msgService.multiForwardMsg(ArrayList<MultiMsgInfo>().apply {
|
||||||
msgIds.forEach { add(MultiMsgInfo(it.second, it.first)) }
|
msgIds.forEach { add(MultiMsgInfo(it.second, it.first)) }
|
||||||
}.also { it.reverse() }, from, to) { code, why ->
|
}.also { it.reverse() }, from, to) { code, why ->
|
||||||
if (code != 0)
|
if (code != 0)
|
||||||
|
@ -0,0 +1,125 @@
|
|||||||
|
package moe.fuqiuluo.shamrock.remote.action.handlers
|
||||||
|
|
||||||
|
import com.tencent.qqnt.kernel.nativeinterface.MsgConstant
|
||||||
|
import com.tencent.qqnt.kernel.nativeinterface.MultiMsgInfo
|
||||||
|
import kotlinx.atomicfu.atomic
|
||||||
|
import kotlinx.serialization.json.JsonArray
|
||||||
|
import kotlinx.serialization.json.JsonElement
|
||||||
|
import moe.fuqiuluo.qqinterface.servlet.MsgSvc
|
||||||
|
import moe.fuqiuluo.shamrock.remote.action.ActionSession
|
||||||
|
import moe.fuqiuluo.shamrock.remote.action.IActionHandler
|
||||||
|
import moe.fuqiuluo.qqinterface.servlet.TicketSvc
|
||||||
|
import moe.fuqiuluo.qqinterface.servlet.msg.convert.toSegments
|
||||||
|
import moe.fuqiuluo.shamrock.helper.Level
|
||||||
|
import moe.fuqiuluo.shamrock.helper.LogCenter
|
||||||
|
import moe.fuqiuluo.shamrock.helper.MessageHelper
|
||||||
|
import moe.fuqiuluo.shamrock.tools.EmptyJsonObject
|
||||||
|
import moe.fuqiuluo.shamrock.tools.EmptyJsonString
|
||||||
|
import moe.fuqiuluo.shamrock.tools.asInt
|
||||||
|
import moe.fuqiuluo.shamrock.tools.asJsonObject
|
||||||
|
import moe.fuqiuluo.shamrock.tools.asString
|
||||||
|
import moe.fuqiuluo.shamrock.tools.asStringOrNull
|
||||||
|
import moe.fuqiuluo.shamrock.tools.json
|
||||||
|
import moe.fuqiuluo.shamrock.xposed.helper.NTServiceFetcher
|
||||||
|
|
||||||
|
internal object SendPrivateForwardMsg: IActionHandler() {
|
||||||
|
override suspend fun internalHandle(session: ActionSession): String {
|
||||||
|
val groupId = session.getString("user_id")
|
||||||
|
if (session.isArray("messages")) {
|
||||||
|
val messages = session.getArray("messages")
|
||||||
|
return invoke(messages, groupId, session.echo)
|
||||||
|
}
|
||||||
|
return logic("未知格式合并转发消息", session.echo)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend operator fun invoke(
|
||||||
|
message: JsonArray,
|
||||||
|
userId: String,
|
||||||
|
echo: JsonElement = EmptyJsonString
|
||||||
|
): String {
|
||||||
|
kotlin.runCatching {
|
||||||
|
val kernelService = NTServiceFetcher.kernelService
|
||||||
|
val sessionService = kernelService.wrapperSession
|
||||||
|
val msgService = sessionService.msgService
|
||||||
|
val selfUin = TicketSvc.getUin()
|
||||||
|
|
||||||
|
val msgs = message.map {
|
||||||
|
it.asJsonObject["data"].asJsonObject.let { data ->
|
||||||
|
if (data.containsKey("content"))
|
||||||
|
MessageNode(
|
||||||
|
name = data["name"].asStringOrNull ?: "",
|
||||||
|
content = data["content"]
|
||||||
|
)
|
||||||
|
else MessageIdNode(data["id"].asInt)
|
||||||
|
}
|
||||||
|
}.map {
|
||||||
|
if (it is MessageIdNode) {
|
||||||
|
val recordResult = MsgSvc.getMsg(it.id)
|
||||||
|
if (recordResult.isFailure) {
|
||||||
|
EmptyNode
|
||||||
|
} else {
|
||||||
|
val record = recordResult.getOrThrow()
|
||||||
|
MessageNode(
|
||||||
|
name = record.sendMemberName
|
||||||
|
.ifBlank { record.sendNickName }
|
||||||
|
.ifBlank { record.sendRemarkName }
|
||||||
|
.ifBlank { record.peerName },
|
||||||
|
content = record.toSegments().map { segment ->
|
||||||
|
segment.toJson()
|
||||||
|
}.json
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
it as MessageNode
|
||||||
|
}
|
||||||
|
}.filter {
|
||||||
|
it.content != null
|
||||||
|
}
|
||||||
|
|
||||||
|
lateinit var forwardMsgCallback: (() -> Unit)
|
||||||
|
val availableMsgSize = atomic(0)
|
||||||
|
val msgIds = msgs.map {
|
||||||
|
it.name to MessageHelper.sendMessageWithMsgId(MsgConstant.KCHATTYPEC2C, selfUin, it.content!!.let { msg ->
|
||||||
|
if (msg is JsonArray) msg else MessageHelper.decodeCQCode(msg.asString)
|
||||||
|
}, { code, why ->
|
||||||
|
if (code != 0) {
|
||||||
|
availableMsgSize.incrementAndGet()
|
||||||
|
LogCenter.log("合并转发消息节点消息发送失败:$code($why)", Level.WARN)
|
||||||
|
}
|
||||||
|
if (availableMsgSize.incrementAndGet() == msgs.size) {
|
||||||
|
forwardMsgCallback.invoke()
|
||||||
|
}
|
||||||
|
}).first
|
||||||
|
}
|
||||||
|
|
||||||
|
val from = MessageHelper.generateContact(MsgConstant.KCHATTYPEC2C, selfUin)
|
||||||
|
val to = MessageHelper.generateContact(MsgConstant.KCHATTYPEC2C, userId)
|
||||||
|
forwardMsgCallback = {
|
||||||
|
msgService.multiForwardMsg(ArrayList<MultiMsgInfo>().apply {
|
||||||
|
msgIds.forEach { add(MultiMsgInfo(it.second, it.first)) }
|
||||||
|
}.also { it.reverse() }, from, to) { code, why ->
|
||||||
|
if (code != 0)
|
||||||
|
LogCenter.log("合并转发消息:$code($why)", Level.WARN)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ok(data = EmptyJsonObject, echo = echo)
|
||||||
|
}.onFailure {
|
||||||
|
return error("error: $it", echo)
|
||||||
|
}
|
||||||
|
return logic("合并转发消息失败(unknown error)", echo)
|
||||||
|
}
|
||||||
|
|
||||||
|
override val requiredParams: Array<String> = arrayOf("user_id")
|
||||||
|
|
||||||
|
override fun path(): String = "send_private_forward_msg"
|
||||||
|
|
||||||
|
class MessageIdNode(
|
||||||
|
val id: Int
|
||||||
|
): Node
|
||||||
|
open class MessageNode(
|
||||||
|
val name: String,
|
||||||
|
val content: JsonElement?
|
||||||
|
): Node
|
||||||
|
object EmptyNode: MessageNode("", null)
|
||||||
|
interface Node
|
||||||
|
}
|
@ -22,6 +22,18 @@ import moe.fuqiuluo.shamrock.tools.isJsonData
|
|||||||
import moe.fuqiuluo.shamrock.tools.isJsonString
|
import moe.fuqiuluo.shamrock.tools.isJsonString
|
||||||
|
|
||||||
fun Routing.messageAction() {
|
fun Routing.messageAction() {
|
||||||
|
post("/send_group_forward_msg") {
|
||||||
|
val groupId = fetchPostOrNull("group_id")
|
||||||
|
val messages = fetchPostJsonArray("messages")
|
||||||
|
call.respondText(SendGroupForwardMsg(messages, groupId ?: ""))
|
||||||
|
}
|
||||||
|
|
||||||
|
post("/send_private_forward_msg") {
|
||||||
|
val userId = fetchPostOrNull("user_id")
|
||||||
|
val messages = fetchPostJsonArray("messages")
|
||||||
|
call.respondText(SendPrivateForwardMsg(messages, userId ?: ""))
|
||||||
|
}
|
||||||
|
|
||||||
getOrPost("/get_forward_msg") {
|
getOrPost("/get_forward_msg") {
|
||||||
val id = fetchOrThrow("id")
|
val id = fetchOrThrow("id")
|
||||||
call.respondText(GetForwardMsg(id))
|
call.respondText(GetForwardMsg(id))
|
||||||
|
@ -6,6 +6,7 @@ import com.tencent.qqnt.kernel.nativeinterface.*
|
|||||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import moe.fuqiuluo.qqinterface.servlet.TicketSvc
|
||||||
import moe.fuqiuluo.qqinterface.servlet.msg.convert.toCQCode
|
import moe.fuqiuluo.qqinterface.servlet.msg.convert.toCQCode
|
||||||
import moe.fuqiuluo.qqinterface.servlet.transfile.RichProtoSvc
|
import moe.fuqiuluo.qqinterface.servlet.transfile.RichProtoSvc
|
||||||
import moe.fuqiuluo.shamrock.remote.service.config.ShamrockConfig
|
import moe.fuqiuluo.shamrock.remote.service.config.ShamrockConfig
|
||||||
@ -119,6 +120,7 @@ internal object AioListener: IKernelMsgListener {
|
|||||||
|
|
||||||
override fun onAddSendMsg(record: MsgRecord) {
|
override fun onAddSendMsg(record: MsgRecord) {
|
||||||
if (record.chatType == MsgConstant.KCHATTYPEGUILD) return // TODO: 频道消息暂不处理
|
if (record.chatType == MsgConstant.KCHATTYPEGUILD) return // TODO: 频道消息暂不处理
|
||||||
|
if (record.peerUin == TicketSvc.getLongUin()) return // 发给自己的消息不处理
|
||||||
|
|
||||||
GlobalScope.launch {
|
GlobalScope.launch {
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user