Shamrock: support /switch_account

This commit is contained in:
WhiteChi 2023-11-23 09:48:30 +08:00
parent 03d62c55c2
commit 5f0cf952e8
5 changed files with 47 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import android.text.TextUtils;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import com.tencent.qphone.base.remote.SimpleAccount;
import com.tencent.qphone.base.remote.ToServiceMsg; import com.tencent.qphone.base.remote.ToServiceMsg;
import mqq.app.api.IRuntimeService; import mqq.app.api.IRuntimeService;
@ -72,6 +73,10 @@ public abstract class AppRuntime {
public <T extends IRuntimeService> T getRuntimeServiceIPCSync(@NonNull Class<T> cls, String str) { public <T extends IRuntimeService> T getRuntimeServiceIPCSync(@NonNull Class<T> cls, String str) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
public void switchAccount(SimpleAccount simpleAccount, String process) {
}
public String getAccount() { public String getAccount() {
return ""; return "";
} }

View File

@ -18,6 +18,7 @@ internal object ActionManager {
arrayOf( arrayOf(
// Framework Info // Framework Info
TestHandler, GetLatestEvents, GetSupportedActions, GetStatus, GetVersionInfo, GetSelfInfo, GetLoginInfo, TestHandler, GetLatestEvents, GetSupportedActions, GetStatus, GetVersionInfo, GetSelfInfo, GetLoginInfo,
SwitchAccount,
// UserActions // UserActions
GetProfileCard, GetFriendList, SendLike, GetUid, GetUinByUid, ScanQRCode, SetProfileCard, GetProfileCard, GetFriendList, SendLike, GetUid, GetUinByUid, ScanQRCode, SetProfileCard,

View File

@ -0,0 +1,35 @@
package moe.fuqiuluo.shamrock.remote.action.handlers
import kotlinx.serialization.json.JsonElement
import moe.fuqiuluo.shamrock.remote.action.ActionSession
import moe.fuqiuluo.shamrock.remote.action.IActionHandler
import moe.fuqiuluo.shamrock.tools.EmptyJsonString
import moe.fuqiuluo.shamrock.xposed.helper.AppRuntimeFetcher
import mqq.app.MobileQQ
internal object SwitchAccount: IActionHandler() {
override suspend fun internalHandle(session: ActionSession): String {
val userId = session.getString("user_id")
return invoke(userId, session.echo)
}
operator fun invoke(
userId: String,
echo: JsonElement = EmptyJsonString
): String {
val account = MobileQQ.getMobileQQ().allAccounts.firstOrNull { it.uin == userId }
?: return error("账号不存在", echo)
val runtime = AppRuntimeFetcher.appRuntime
val result = kotlin.runCatching {
runtime.switchAccount(account, null)
}
if (result.isFailure) {
return error(result.exceptionOrNull()?.message ?: "切换账号失败", echo)
}
return ok("切换成功", echo)
}
override val requiredParams: Array<String> = arrayOf("user_id")
override fun path(): String = "switch_account"
}

View File

@ -12,6 +12,11 @@ import moe.fuqiuluo.shamrock.tools.*
import moe.fuqiuluo.shamrock.utils.PlatformUtils import moe.fuqiuluo.shamrock.utils.PlatformUtils
fun Routing.userAction() { fun Routing.userAction() {
getOrPost("/switch_account") {
val userId = fetchOrThrow("user_id")
call.respondText(SwitchAccount(userId), ContentType.Application.Json)
}
getOrPost("/set_group_leave") { getOrPost("/set_group_leave") {
val group = fetchOrThrow("group_id") val group = fetchOrThrow("group_id")
call.respondText(LeaveTroop(group), ContentType.Application.Json) call.respondText(LeaveTroop(group), ContentType.Application.Json)

View File

@ -104,7 +104,7 @@ internal object GlobalEventTransmitter: BaseSvc() {
var nickName = record.sendNickName var nickName = record.sendNickName
if (nickName.isNullOrBlank()) { if (nickName.isNullOrBlank()) {
CardSvc.getProfileCard(record.senderUin.toString()).onSuccess { CardSvc.getProfileCard(record.senderUin.toString()).onSuccess {
nickName = it.strNick ?: "" nickName = it.strNick ?: record.peerName
} }
} }
transMessageEvent(record, transMessageEvent(record,