mirror of
https://github.com/whitechi73/OpenShamrock.git
synced 2024-08-14 13:12:17 +08:00
Shamrock
: 履歴メッセージの取得をサポート
This commit is contained in:
parent
3988ad3811
commit
7584390408
@ -1,5 +1,7 @@
|
|||||||
package com.tencent.qqnt.kernel.nativeinterface;
|
package com.tencent.qqnt.kernel.nativeinterface;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
@ -16,6 +18,16 @@ public interface IKernelMsgService {
|
|||||||
|
|
||||||
void addLocalRecordMsg(Contact contact, long msgId, MsgElement elem, HashMap<Integer, MsgAttributeInfo> hashMap, boolean z, IOperateCallback callback);
|
void addLocalRecordMsg(Contact contact, long msgId, MsgElement elem, HashMap<Integer, MsgAttributeInfo> hashMap, boolean z, IOperateCallback callback);
|
||||||
|
|
||||||
|
long getMsgUniqueId(long time);
|
||||||
|
|
||||||
|
void addSendMsg(long msgId, Contact contact, ArrayList<MsgElement> msgList, HashMap<Integer, MsgAttributeInfo> hashMap);
|
||||||
|
|
||||||
|
void getMsgs(@NotNull Contact contact, long startMsgId, int cnt, boolean queryOrder, @NotNull IMsgOperateCallback iMsgOperateCallback);
|
||||||
|
|
||||||
|
void getMsgsIncludeSelf(Contact contact, long startMsgId, int count, boolean queryOrder, IMsgOperateCallback iMsgOperateCallback);
|
||||||
|
|
||||||
|
void translatePtt2Text(long j2, Contact contact, MsgElement msgElement, IOperateCallback iOperateCallback);
|
||||||
|
|
||||||
void getMultiMsg(Contact contact, long rootMsgId, long parentMsgId, IGetMultiMsgCallback cb);
|
void getMultiMsg(Contact contact, long rootMsgId, long parentMsgId, IGetMultiMsgCallback cb);
|
||||||
|
|
||||||
void clearMsgRecords(Contact contact, IClearMsgRecordsCallback cb);
|
void clearMsgRecords(Contact contact, IClearMsgRecordsCallback cb);
|
||||||
|
@ -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,
|
ClearMsgs, GetHistoryMsg, GetGroupMsgHistory,
|
||||||
|
|
||||||
// RESOURCE ACTION
|
// RESOURCE ACTION
|
||||||
GetRecord, GetImage, UploadGroupFile, CreateGroupFileFolder, DeleteGroupFolder,
|
GetRecord, GetImage, UploadGroupFile, CreateGroupFileFolder, DeleteGroupFolder,
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
package moe.fuqiuluo.shamrock.remote.action.handlers
|
||||||
|
|
||||||
|
import moe.fuqiuluo.shamrock.remote.action.ActionSession
|
||||||
|
import moe.fuqiuluo.shamrock.remote.action.IActionHandler
|
||||||
|
|
||||||
|
internal object GetGroupMsgHistory: IActionHandler() {
|
||||||
|
override suspend fun internalHandle(session: ActionSession): String {
|
||||||
|
val groupId = session.getString("group_id")
|
||||||
|
val cnt = session.getIntOrNull("count") ?: 20
|
||||||
|
return GetHistoryMsg("group", groupId, cnt, session.echo)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun path(): String = "get_group_msg_history"
|
||||||
|
}
|
@ -0,0 +1,76 @@
|
|||||||
|
package moe.fuqiuluo.shamrock.remote.action.handlers
|
||||||
|
|
||||||
|
import com.tencent.qqnt.kernel.nativeinterface.MsgConstant
|
||||||
|
import com.tencent.qqnt.kernel.nativeinterface.MsgRecord
|
||||||
|
import kotlinx.serialization.json.JsonElement
|
||||||
|
import moe.fuqiuluo.qqinterface.servlet.msg.convert.MessageConvert
|
||||||
|
import moe.fuqiuluo.shamrock.helper.MessageHelper
|
||||||
|
import moe.fuqiuluo.shamrock.remote.action.ActionSession
|
||||||
|
import moe.fuqiuluo.shamrock.remote.action.IActionHandler
|
||||||
|
import moe.fuqiuluo.shamrock.remote.service.data.MessageDetail
|
||||||
|
import moe.fuqiuluo.shamrock.remote.service.data.MessageSender
|
||||||
|
import moe.fuqiuluo.shamrock.tools.EmptyJsonString
|
||||||
|
import moe.fuqiuluo.shamrock.xposed.helper.NTServiceFetcher
|
||||||
|
import java.util.ArrayList
|
||||||
|
import kotlin.coroutines.resume
|
||||||
|
import kotlin.coroutines.suspendCoroutine
|
||||||
|
|
||||||
|
internal object GetHistoryMsg: IActionHandler() {
|
||||||
|
override suspend fun internalHandle(session: ActionSession): String {
|
||||||
|
val msgType = session.getString("message_type")
|
||||||
|
val peerId = session.getString(if (msgType == "group") "group_id" else "user_id")
|
||||||
|
val cnt = session.getIntOrNull("count") ?: 20
|
||||||
|
return invoke(msgType, peerId, cnt, session.echo)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend operator fun invoke(
|
||||||
|
msgType: String,
|
||||||
|
peerId: String,
|
||||||
|
cnt: Int,
|
||||||
|
echo: JsonElement = EmptyJsonString
|
||||||
|
): String {
|
||||||
|
val msgService = NTServiceFetcher.kernelService.wrapperSession.msgService
|
||||||
|
val chatType = MessageHelper.obtainMessageTypeByDetailType(msgType)
|
||||||
|
val contact = MessageHelper.generateContact(chatType, peerId)
|
||||||
|
val result = suspendCoroutine {
|
||||||
|
msgService.getMsgs(contact, 0L, cnt, true) { code, why, msgs ->
|
||||||
|
it.resume(GetMsgResult(code, why, msgs))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (result.code != 0) {
|
||||||
|
return logic(result.msg ?: "获取历史消息失败", echo = echo)
|
||||||
|
}
|
||||||
|
|
||||||
|
val msgList = result.data!!.map { msg ->
|
||||||
|
val msgHash = MessageHelper.generateMsgIdHash(msg.chatType, msg.msgId)
|
||||||
|
MessageDetail(
|
||||||
|
time = msg.msgTime.toInt(),
|
||||||
|
msgType = MessageHelper.obtainDetailTypeByMsgType(msg.chatType),
|
||||||
|
msgId = msgHash,
|
||||||
|
realId = msg.msgSeq.toInt(),
|
||||||
|
sender = MessageSender(
|
||||||
|
msg.senderUin, msg.sendNickName, "unknown", 0, msg.senderUid
|
||||||
|
),
|
||||||
|
message = MessageConvert.convertMessageRecordToMsgSegment(msg).map {
|
||||||
|
it.toJson()
|
||||||
|
},
|
||||||
|
peerId = msg.peerUin,
|
||||||
|
groupId = if (msg.chatType == MsgConstant.KCHATTYPEGROUP) msg.peerUin else 0,
|
||||||
|
targetId = if (msg.chatType != MsgConstant.KCHATTYPEGROUP) msg.peerUin else 0
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return ok(data = msgList, echo = echo)
|
||||||
|
}
|
||||||
|
|
||||||
|
override val requiredParams: Array<String>
|
||||||
|
get() = arrayOf("message_type")
|
||||||
|
|
||||||
|
override fun path(): String = "get_history_msg"
|
||||||
|
|
||||||
|
data class GetMsgResult(
|
||||||
|
val code: Int,
|
||||||
|
val msg: String?,
|
||||||
|
val data: ArrayList<MsgRecord>?
|
||||||
|
)
|
||||||
|
}
|
@ -20,7 +20,7 @@ internal object GetVersionInfo : IActionHandler() {
|
|||||||
appVersion = ShamrockVersion,
|
appVersion = ShamrockVersion,
|
||||||
impl = "shamrock",
|
impl = "shamrock",
|
||||||
version = ShamrockVersion,
|
version = ShamrockVersion,
|
||||||
onebotVersion = "12",
|
onebotVersion = "11",
|
||||||
),
|
),
|
||||||
echo = echo
|
echo = echo
|
||||||
)
|
)
|
||||||
|
@ -22,6 +22,19 @@ import moe.fuqiuluo.shamrock.tools.isJsonData
|
|||||||
import moe.fuqiuluo.shamrock.tools.isJsonString
|
import moe.fuqiuluo.shamrock.tools.isJsonString
|
||||||
|
|
||||||
fun Routing.messageAction() {
|
fun Routing.messageAction() {
|
||||||
|
getOrPost("/get_group_msg_history") {
|
||||||
|
val peerId = fetchOrThrow("group_id")
|
||||||
|
val cnt = fetchOrNull("count")?.toInt() ?: 20
|
||||||
|
call.respondText(GetHistoryMsg("group", peerId, cnt))
|
||||||
|
}
|
||||||
|
|
||||||
|
getOrPost("/get_history_msg") {
|
||||||
|
val msgType = fetchOrThrow("message_type")
|
||||||
|
val peerId = fetchOrThrow(if (msgType == "group") "group_id" else "user_id")
|
||||||
|
val cnt = fetchOrNull("count")?.toInt() ?: 20
|
||||||
|
call.respondText(GetHistoryMsg(msgType, peerId, cnt))
|
||||||
|
}
|
||||||
|
|
||||||
getOrPost("/clear_msgs") {
|
getOrPost("/clear_msgs") {
|
||||||
val msgType = fetchOrThrow("message_type")
|
val msgType = fetchOrThrow("message_type")
|
||||||
val peerId = fetchOrThrow(if (msgType == "group") "group_id" else "user_id")
|
val peerId = fetchOrThrow(if (msgType == "group") "group_id" else "user_id")
|
||||||
|
@ -1,19 +1,77 @@
|
|||||||
package moe.fuqiuluo.shamrock.remote.api
|
package moe.fuqiuluo.shamrock.remote.api
|
||||||
|
|
||||||
|
import com.tencent.qqnt.kernel.nativeinterface.Contact
|
||||||
|
import com.tencent.qqnt.kernel.nativeinterface.IMsgOperateCallback
|
||||||
|
import com.tencent.qqnt.kernel.nativeinterface.MsgConstant
|
||||||
|
import com.tencent.qqnt.kernel.nativeinterface.MsgElement
|
||||||
|
import com.tencent.qqnt.kernel.nativeinterface.MsgRecord
|
||||||
|
import com.tencent.qqnt.kernel.nativeinterface.TextElement
|
||||||
import io.ktor.server.application.call
|
import io.ktor.server.application.call
|
||||||
import io.ktor.server.response.respondText
|
import io.ktor.server.response.respondText
|
||||||
import io.ktor.server.routing.Routing
|
import io.ktor.server.routing.Routing
|
||||||
import io.ktor.server.routing.get
|
import io.ktor.server.routing.get
|
||||||
|
import moe.fuqiuluo.qqinterface.servlet.TicketSvc
|
||||||
|
import moe.fuqiuluo.qqinterface.servlet.msg.convert.toCQCode
|
||||||
|
import moe.fuqiuluo.shamrock.helper.Level
|
||||||
|
import moe.fuqiuluo.shamrock.helper.LogCenter
|
||||||
|
import moe.fuqiuluo.shamrock.helper.MessageHelper
|
||||||
|
import moe.fuqiuluo.shamrock.tools.ShamrockVersion
|
||||||
import moe.fuqiuluo.shamrock.tools.fetch
|
import moe.fuqiuluo.shamrock.tools.fetch
|
||||||
import moe.fuqiuluo.shamrock.tools.fetchOrThrow
|
import moe.fuqiuluo.shamrock.tools.fetchOrThrow
|
||||||
import moe.fuqiuluo.shamrock.xposed.helper.NTServiceFetcher
|
import moe.fuqiuluo.shamrock.xposed.helper.NTServiceFetcher
|
||||||
|
import java.util.ArrayList
|
||||||
|
import kotlin.coroutines.resume
|
||||||
|
import kotlin.coroutines.suspendCoroutine
|
||||||
|
|
||||||
fun Routing.testAction() {
|
fun Routing.testAction() {
|
||||||
|
if(ShamrockVersion.contains("dev")) {
|
||||||
|
LogCenter.log("testAction is enabled.", Level.WARN)
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
get("/test/createUidFromTinyId") {
|
get("/test/createUidFromTinyId") {
|
||||||
val selfId = fetchOrThrow("selfId").toLong()
|
val selfId = fetchOrThrow("selfId").toLong()
|
||||||
val peerId = fetchOrThrow("peerId").toLong()
|
val peerId = fetchOrThrow("peerId").toLong()
|
||||||
call.respondText(NTServiceFetcher.kernelService.wrapperSession.msgService.createUidFromTinyId(selfId, peerId))
|
call.respondText(NTServiceFetcher.kernelService.wrapperSession.msgService.createUidFromTinyId(selfId, peerId))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get("/test/addSendMsg") {
|
||||||
|
val msgService = NTServiceFetcher.kernelService.wrapperSession.msgService
|
||||||
|
val msgId = msgService.getMsgUniqueId(System.currentTimeMillis())
|
||||||
|
msgService.addSendMsg(msgId, MessageHelper.generateContact(MsgConstant.KCHATTYPEC2C, TicketSvc.getUin()), arrayListOf(
|
||||||
|
MsgElement().apply {
|
||||||
|
elementType = MsgConstant.KELEMTYPETEXT
|
||||||
|
textElement = TextElement().apply {
|
||||||
|
content = "测试消息"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
), hashMapOf())
|
||||||
|
call.respondText("ok")
|
||||||
|
}*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
get("/test/getMsgs") {
|
||||||
|
kotlin.runCatching {
|
||||||
|
val msgService = NTServiceFetcher.kernelService.wrapperSession.msgService
|
||||||
|
val msgs = suspendCoroutine {
|
||||||
|
msgService.getMsgs(Contact(MsgConstant.KCHATTYPEGROUP, "884587317", ""), 0L, 20, true, object: IMsgOperateCallback{
|
||||||
|
override fun onResult(code: Int, why: String?, msgs: ArrayList<MsgRecord>?) {
|
||||||
|
it.resume(msgs)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (msgs == null) {
|
||||||
|
call.respondText("failed")
|
||||||
|
return@get
|
||||||
|
}
|
||||||
|
|
||||||
|
call.respondText("msg -> " + msgs.map { it.toCQCode() }.joinToString("\n"))
|
||||||
|
}.onFailure {
|
||||||
|
call.respondText("failed: ${it.stackTraceToString()}")
|
||||||
|
return@get
|
||||||
|
}
|
||||||
|
|
||||||
|
}*/
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user