fix ping-pong

This commit is contained in:
fuqiuluo 2024-07-08 09:11:49 +08:00
parent 012ecaa85d
commit 5fb1d0aeb9
2 changed files with 24 additions and 0 deletions

View File

@ -20,6 +20,7 @@ private val configKeys = setOf(
ResourceGroup, ResourceGroup,
RPCAddress, RPCAddress,
RPCPort, RPCPort,
AliveReply,
) )
internal object ShamrockConfig: Properties() { internal object ShamrockConfig: Properties() {

View File

@ -3,10 +3,16 @@
package qq.service.internals package qq.service.internals
import com.tencent.qqnt.kernel.nativeinterface.MsgConstant 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.MsgRecord
import com.tencent.qqnt.kernel.nativeinterface.TextElement
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 kotlinx.serialization.json.JsonNull.content
import moe.fuqiuluo.shamrock.config.AliveReply
import moe.fuqiuluo.shamrock.config.ConfigKey
import moe.fuqiuluo.shamrock.config.get
import moe.fuqiuluo.shamrock.helper.Level import moe.fuqiuluo.shamrock.helper.Level
import moe.fuqiuluo.shamrock.helper.LogCenter import moe.fuqiuluo.shamrock.helper.LogCenter
import moe.fuqiuluo.shamrock.internals.GlobalEventTransmitter import moe.fuqiuluo.shamrock.internals.GlobalEventTransmitter
@ -28,6 +34,23 @@ object AioListener : SimpleKernelMsgListener() {
} }
private suspend fun onMsg(record: MsgRecord) { private suspend fun onMsg(record: MsgRecord) {
if (AliveReply.get()) {
//LogCenter.log("自回复测试功能打开!")
val texts = record.elements.filter { it.elementType == MsgConstant.KELEMTYPETEXT }
val text = texts.joinToString { it.textElement.content }
if (texts.isNotEmpty() && text == "ping") {
val contact = MessageHelper.generateContact(record)
MessageHelper.sendMessage(contact, arrayListOf(
MsgElement().apply {
elementType = MsgConstant.KELEMTYPETEXT
textElement = TextElement().apply {
content = "pong"
}
}
), 3, MessageHelper.generateMsgId(record.chatType))
return
}
}
when (record.chatType) { when (record.chatType) {
MsgConstant.KCHATTYPEGROUP -> { MsgConstant.KCHATTYPEGROUP -> {
if (record.senderUin == 0L) return if (record.senderUin == 0L) return