fix: stranger info

This commit is contained in:
linyuchen 2024-03-20 18:25:09 +08:00
parent 7cafbdfae5
commit 1307679dae
10 changed files with 146 additions and 84 deletions

View File

@ -6,7 +6,7 @@ import path from "node:path";
import {selfInfo} from "./data"; import {selfInfo} from "./data";
import {DATA_DIR} from "./utils"; import {DATA_DIR} from "./utils";
export const HOOK_LOG = true; export const HOOK_LOG = false;
export const ALLOW_SEND_TEMP_MSG = false; export const ALLOW_SEND_TEMP_MSG = false;

7
src/ntqqapi/api/index.ts Normal file
View File

@ -0,0 +1,7 @@
export * from "./file";
export * from "./friend";
export * from "./group";
export * from "./msg";
export * from "./user";
export * from "./webapi";
export * from "./window";

View File

@ -61,6 +61,7 @@ let receiveHooks: Array<{
export function hookNTQQApiReceive(window: BrowserWindow) { export function hookNTQQApiReceive(window: BrowserWindow) {
const originalSend = window.webContents.send; const originalSend = window.webContents.send;
const patchSend = (channel: string, ...args: NTQQApiReturnData) => { const patchSend = (channel: string, ...args: NTQQApiReturnData) => {
console.log("hookNTQQApiReceive", channel, args)
let isLogger = false let isLogger = false
try { try {
isLogger = args[0]?.eventName?.startsWith("ns-LoggerApi") isLogger = args[0]?.eventName?.startsWith("ns-LoggerApi")
@ -69,11 +70,12 @@ export function hookNTQQApiReceive(window: BrowserWindow) {
} }
if (!isLogger) { if (!isLogger) {
try { try {
HOOK_LOG && log(`received ntqq api message: ${channel}`, JSON.stringify(args)) HOOK_LOG && log(`received ntqq api message: ${channel}`, args)
}catch (e) { }catch (e) {
log("hook log error", e, args)
} }
} }
try {
if (args?.[1] instanceof Array) { if (args?.[1] instanceof Array) {
for (let receiveData of args?.[1]) { for (let receiveData of args?.[1]) {
const ntQQApiMethodName = receiveData.cmdName; const ntQQApiMethodName = receiveData.cmdName;
@ -105,7 +107,10 @@ export function hookNTQQApiReceive(window: BrowserWindow) {
delete hookApiCallbacks[callbackId]; delete hookApiCallbacks[callbackId];
} }
} }
return originalSend.call(window.webContents, channel, ...args); }catch (e) {
log("hookNTQQApiReceive error", e.stack.toString(), args)
}
originalSend.call(window.webContents, channel, ...args);
} }
window.webContents.send = patchSend; window.webContents.send = patchSend;
} }
@ -117,6 +122,7 @@ export function hookNTQQApiCall(window: BrowserWindow) {
const proxyIpcMsg = new Proxy(ipc_message_proxy, { const proxyIpcMsg = new Proxy(ipc_message_proxy, {
apply(target, thisArg, args) { apply(target, thisArg, args) {
console.log(thisArg, args);
let isLogger = false let isLogger = false
try { try {
isLogger = args[3][0].eventName.startsWith("ns-LoggerApi") isLogger = args[3][0].eventName.startsWith("ns-LoggerApi")

View File

@ -18,7 +18,54 @@ export interface User {
longNick?: string; // 签名 longNick?: string; // 签名
remark?: string; remark?: string;
sex?: Sex; sex?: Sex;
"qqLevel"?: QQLevel qqLevel?: QQLevel,
qid?: string
"birthday_year"?: number,
"birthday_month"?: number,
"birthday_day"?: number,
"topTime"?: string,
"constellation"?: number,
"shengXiao"?: number,
"kBloodType"?: number,
"homeTown"?: string, //"0-0-0",
"makeFriendCareer"?: number,
"pos"?: string,
"eMail"?: string
"phoneNum"?: string,
"college"?: string,
"country"?: string,
"province"?: string,
"city"?: string,
"postCode"?: string,
"address"?: string,
"isBlock"?: boolean,
"isSpecialCareOpen"?: boolean,
"isSpecialCareZone"?: boolean,
"ringId"?: string,
"regTime"?: number,
interest?: string,
"labels"?: string[],
"isHideQQLevel"?: number,
"privilegeIcon"?: {
"jumpUrl": string,
"openIconList": unknown[],
"closeIconList": unknown[]
},
"photoWall"?: {
"picList": unknown[]
},
"vipFlag"?: boolean,
"yearVipFlag"?: boolean,
"svipFlag"?: boolean,
"vipLevel"?: number,
"status"?: number,
"qidianMasterFlag"?: number,
"qidianCrewFlag"?: number,
"qidianCrewFlag2"?: number,
"extStatus"?: number,
"recommendImgFlag"?: number,
"disableEmojiShortCuts"?: number,
"pendantId"?: string,
} }
export interface SelfInfo extends User { export interface SelfInfo extends User {

View File

@ -1,29 +0,0 @@
import BaseAction from "./BaseAction";
import {NTQQApi} from "../../ntqqapi/ntcall";
import {ActionName} from "./types";
import {log} from "../../common/utils/log";
interface Payload {
method: string,
args: any[],
}
export default class Debug extends BaseAction<Payload, any> {
actionName = ActionName.Debug
protected async _handle(payload: Payload): Promise<any> {
log("debug call ntqq api", payload);
const method = NTQQApi[payload.method]
if (!method) {
throw `${method} 不存在`
}
const result = method(...payload.args);
if (method.constructor.name === "AsyncFunction") {
return await result
}
return result
// const info = await NTQQApi.getUserDetailInfo(friends[0].uid);
// return info
}
}

View File

@ -1,36 +1,20 @@
import BaseAction from "../BaseAction"; import BaseAction from "../BaseAction";
import {OB11User} from "../../types"; import {OB11User} from "../../types";
import {getFriend, getGroupMember, groups} from "../../../common/data"; import {getUidByUin, uidMaps} from "../../../common/data";
import {OB11Constructor} from "../../constructor"; import {OB11Constructor} from "../../constructor";
import {ActionName} from "../types"; import {ActionName} from "../types";
import {isNull, log} from "../../../common/utils";
import {NTQQUserApi} from "../../../ntqqapi/api/user"; import {NTQQUserApi} from "../../../ntqqapi/api/user";
import {Friend, GroupMember} from "../../../ntqqapi/types";
export default class GoCQHTTPGetStrangerInfo extends BaseAction<{ user_id: number }, OB11User> { export default class GoCQHTTPGetStrangerInfo extends BaseAction<{ user_id: number }, OB11User> {
actionName = ActionName.GoCQHTTP_GetStrangerInfo actionName = ActionName.GoCQHTTP_GetStrangerInfo
private async refreshInfo(user: Friend | GroupMember){
if (isNull(user.sex)){
let info = (await NTQQUserApi.getUserDetailInfo(user.uid))
Object.assign(user, info);
}
}
protected async _handle(payload: { user_id: number }): Promise<OB11User> { protected async _handle(payload: { user_id: number }): Promise<OB11User> {
const user_id = payload.user_id.toString() const user_id = payload.user_id.toString()
const friend = await getFriend(user_id) const uid = getUidByUin(user_id)
if (friend) { if (!uid) {
await this.refreshInfo(friend);
return OB11Constructor.friend(friend);
}
for (const group of groups) {
const member = await getGroupMember(group.groupCode, user_id)
if (member) {
await this.refreshInfo(member);
return OB11Constructor.groupMember(group.groupCode, member) as OB11User
}
}
throw new Error("查无此人") throw new Error("查无此人")
} }
return OB11Constructor.stranger(await NTQQUserApi.getUserDetailInfo(uid))
}
} }

View File

@ -20,7 +20,7 @@ import SendLike from "./SendLike";
import SetGroupAddRequest from "./SetGroupAddRequest"; import SetGroupAddRequest from "./SetGroupAddRequest";
import SetGroupLeave from "./SetGroupLeave"; import SetGroupLeave from "./SetGroupLeave";
import GetGuildList from "./GetGuildList"; import GetGuildList from "./GetGuildList";
import Debug from "./Debug"; import Debug from "./llonebot/Debug";
import SetFriendAddRequest from "./SetFriendAddRequest"; import SetFriendAddRequest from "./SetFriendAddRequest";
import SetGroupWholeBan from "./SetGroupWholeBan"; import SetGroupWholeBan from "./SetGroupWholeBan";
import SetGroupName from "./SetGroupName"; import SetGroupName from "./SetGroupName";

View File

@ -0,0 +1,31 @@
import BaseAction from "../BaseAction";
import * as ntqqApi from "../../../ntqqapi/api";
import {ActionName} from "../types";
import {log} from "../../../common/utils/log";
interface Payload {
method: string,
args: any[],
}
export default class Debug extends BaseAction<Payload, any> {
actionName = ActionName.Debug
protected async _handle(payload: Payload): Promise<any> {
log("debug call ntqq api", payload);
for (const ntqqApiClass in ntqqApi) {
const method = ntqqApi[ntqqApiClass][payload.method]
if (method) {
const result = method(...payload.args);
if (method.constructor.name === "AsyncFunction") {
return await result
}
return result
}
}
throw `${payload.method}方法 不存在`
// const info = await NTQQApi.getUserDetailInfo(friends[0].uid);
// return info
}
}

View File

@ -311,14 +311,14 @@ export class OB11Constructor {
nickname: friend.nick, nickname: friend.nick,
remark: friend.remark, remark: friend.remark,
sex: OB11Constructor.sex(friend.sex), sex: OB11Constructor.sex(friend.sex),
qq_level: friend.qqLevel && calcQQLevel(friend.qqLevel) || 0 level: friend.qqLevel && calcQQLevel(friend.qqLevel) || 0
} }
} }
static selfInfo(selfInfo: SelfInfo): OB11User { static selfInfo(selfInfo: SelfInfo): OB11User {
return { return {
user_id: parseInt(selfInfo.uin), user_id: parseInt(selfInfo.uin),
nickname: selfInfo.nick nickname: selfInfo.nick,
} }
} }
@ -365,6 +365,19 @@ export class OB11Constructor {
} }
} }
static stranger(user: User): OB11User {
return {
...user,
user_id: parseInt(user.uin),
nickname: user.nick,
sex: OB11Constructor.sex(user.sex),
age: 0,
qid: user.qid,
login_days: 0,
level: user.qqLevel && calcQQLevel(user.qqLevel) || 0,
}
}
static groupMembers(group: Group): OB11GroupMember[] { static groupMembers(group: Group): OB11GroupMember[] {
log("construct ob11 group members", group) log("construct ob11 group members", group)
return group.members.map(m => OB11Constructor.groupMember(group.groupCode, m)) return group.members.map(m => OB11Constructor.groupMember(group.groupCode, m))

View File

@ -6,7 +6,10 @@ export interface OB11User {
nickname: string; nickname: string;
remark?: string; remark?: string;
sex?: OB11UserSex; sex?: OB11UserSex;
qq_level?: number; level?: number;
age?: number;
qid?: string;
login_days?: number;
} }
export enum OB11UserSex { export enum OB11UserSex {