mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
sync
This commit is contained in:
parent
5d78fdd6a4
commit
a9902d9109
@ -5,14 +5,18 @@ import { selfInfo, uidMaps } from '../../common/data'
|
|||||||
import { cacheFunc, isQQ998, log, sleep } from '../../common/utils'
|
import { cacheFunc, isQQ998, log, sleep } from '../../common/utils'
|
||||||
import { wrapperApi } from '@/ntqqapi/wrapper'
|
import { wrapperApi } from '@/ntqqapi/wrapper'
|
||||||
import { RequestUtil } from '@/common/utils/request'
|
import { RequestUtil } from '@/common/utils/request'
|
||||||
|
import { NodeIKernelProfileService, UserDetailSource, ProfileBizType } from '../services'
|
||||||
|
import { NodeIKernelProfileListener } from '../listeners'
|
||||||
|
import { NTEventDispatch } from '@/common/utils/EventTask'
|
||||||
|
import { qqPkgInfo } from '@/common/utils/QQBasicInfo'
|
||||||
|
|
||||||
const userInfoCache: Record<string, User> = {} // uid: User
|
const userInfoCache: Record<string, User> = {} // uid: User
|
||||||
|
|
||||||
export interface ClientKeyData extends GeneralCallResult {
|
export interface ClientKeyData extends GeneralCallResult {
|
||||||
url: string;
|
url: string
|
||||||
keyIndex: string;
|
keyIndex: string
|
||||||
clientKey: string;
|
clientKey: string
|
||||||
expireTime: string;
|
expireTime: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export class NTQQUserApi {
|
export class NTQQUserApi {
|
||||||
@ -46,8 +50,49 @@ export class NTQQUserApi {
|
|||||||
return result.profiles.get(uid)
|
return result.profiles.get(uid)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 26702
|
||||||
|
static async fetchUserDetailInfo(uid: string) {
|
||||||
|
type EventService = NodeIKernelProfileService['fetchUserDetailInfo']
|
||||||
|
type EventListener = NodeIKernelProfileListener['onUserDetailInfoChanged']
|
||||||
|
const [_retData, profile] = await NTEventDispatch.CallNormalEvent
|
||||||
|
<EventService, EventListener>
|
||||||
|
(
|
||||||
|
'NodeIKernelProfileService/fetchUserDetailInfo',
|
||||||
|
'NodeIKernelProfileListener/onUserDetailInfoChanged',
|
||||||
|
1,
|
||||||
|
5000,
|
||||||
|
(profile) => {
|
||||||
|
if (profile.uid === uid) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
'BuddyProfileStore',
|
||||||
|
[
|
||||||
|
uid
|
||||||
|
],
|
||||||
|
UserDetailSource.KSERVER,
|
||||||
|
[
|
||||||
|
ProfileBizType.KALL
|
||||||
|
]
|
||||||
|
)
|
||||||
|
const RetUser: User = {
|
||||||
|
...profile.simpleInfo.coreInfo,
|
||||||
|
...profile.simpleInfo.status,
|
||||||
|
...profile.simpleInfo.vasInfo,
|
||||||
|
...profile.commonExt,
|
||||||
|
...profile.simpleInfo.baseInfo,
|
||||||
|
qqLevel: profile.commonExt.qqLevel,
|
||||||
|
pendantId: ''
|
||||||
|
}
|
||||||
|
return RetUser
|
||||||
|
}
|
||||||
|
|
||||||
static async getUserDetailInfo(uid: string, getLevel = false, withBizInfo = true) {
|
static async getUserDetailInfo(uid: string, getLevel = false, withBizInfo = true) {
|
||||||
// this.getUserInfo(uid);
|
if (+qqPkgInfo.buildVersion >= 26702) {
|
||||||
|
return this.fetchUserDetailInfo(uid)
|
||||||
|
}
|
||||||
|
// this.getUserInfo(uid)
|
||||||
let methodName = !isQQ998 ? NTQQApiMethod.USER_DETAIL_INFO : NTQQApiMethod.USER_DETAIL_INFO_WITH_BIZ_INFO
|
let methodName = !isQQ998 ? NTQQApiMethod.USER_DETAIL_INFO : NTQQApiMethod.USER_DETAIL_INFO_WITH_BIZ_INFO
|
||||||
if (!withBizInfo) {
|
if (!withBizInfo) {
|
||||||
methodName = NTQQApiMethod.USER_DETAIL_INFO
|
methodName = NTQQApiMethod.USER_DETAIL_INFO
|
||||||
@ -80,7 +125,7 @@ export class NTQQUserApi {
|
|||||||
await fetchInfo()
|
await fetchInfo()
|
||||||
await sleep(1000)
|
await sleep(1000)
|
||||||
}
|
}
|
||||||
let userInfo = await fetchInfo()
|
const userInfo = await fetchInfo()
|
||||||
userInfoCache[uid] = userInfo
|
userInfoCache[uid] = userInfo
|
||||||
return userInfo
|
return userInfo
|
||||||
}
|
}
|
||||||
@ -97,16 +142,17 @@ export class NTQQUserApi {
|
|||||||
],
|
],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getQzoneCookies() {
|
static async getQzoneCookies() {
|
||||||
const requestUrl = 'https://ssl.ptlogin2.qq.com/jump?ptlang=1033&clientuin=' + selfInfo.uin + '&clientkey=' + (await this.getClientKey()).clientKey + '&u1=https%3A%2F%2Fuser.qzone.qq.com%2F' + selfInfo.uin + '%2Finfocenter&keyindex=19%27'
|
const requestUrl = 'https://ssl.ptlogin2.qq.com/jump?ptlang=1033&clientuin=' + selfInfo.uin + '&clientkey=' + (await this.getClientKey()).clientKey + '&u1=https%3A%2F%2Fuser.qzone.qq.com%2F' + selfInfo.uin + '%2Finfocenter&keyindex=19%27'
|
||||||
let cookies: { [key: string]: string; } = {};
|
let cookies: { [key: string]: string } = {}
|
||||||
try {
|
try {
|
||||||
cookies = await RequestUtil.HttpsGetCookies(requestUrl);
|
cookies = await RequestUtil.HttpsGetCookies(requestUrl)
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
log('获取QZone Cookies失败', e)
|
log('获取QZone Cookies失败', e)
|
||||||
cookies = {}
|
cookies = {}
|
||||||
}
|
}
|
||||||
return cookies;
|
return cookies
|
||||||
}
|
}
|
||||||
static async getSkey(): Promise<string> {
|
static async getSkey(): Promise<string> {
|
||||||
const clientKeyData = await this.getClientKey()
|
const clientKeyData = await this.getClientKey()
|
||||||
@ -115,24 +161,24 @@ export class NTQQUserApi {
|
|||||||
}
|
}
|
||||||
const url = 'https://ssl.ptlogin2.qq.com/jump?ptlang=1033&clientuin=' + selfInfo.uin
|
const url = 'https://ssl.ptlogin2.qq.com/jump?ptlang=1033&clientuin=' + selfInfo.uin
|
||||||
+ '&clientkey=' + clientKeyData.clientKey
|
+ '&clientkey=' + clientKeyData.clientKey
|
||||||
+ '&u1=https%3A%2F%2Fh5.qzone.qq.com%2Fqqnt%2Fqzoneinpcqq%2Ffriend%3Frefresh%3D0%26clientuin%3D0%26darkMode%3D0&keyindex=' + clientKeyData.keyIndex;
|
+ '&u1=https%3A%2F%2Fh5.qzone.qq.com%2Fqqnt%2Fqzoneinpcqq%2Ffriend%3Frefresh%3D0%26clientuin%3D0%26darkMode%3D0&keyindex=' + clientKeyData.keyIndex
|
||||||
return (await RequestUtil.HttpsGetCookies(url))?.skey;
|
return (await RequestUtil.HttpsGetCookies(url))?.skey
|
||||||
}
|
}
|
||||||
|
|
||||||
@cacheFunc(60 * 30 * 1000)
|
@cacheFunc(60 * 30 * 1000)
|
||||||
static async getCookies(domain: string) {
|
static async getCookies(domain: string) {
|
||||||
if (domain.endsWith("qzone.qq.com")) {
|
if (domain.endsWith("qzone.qq.com")) {
|
||||||
let data = (await NTQQUserApi.getQzoneCookies());
|
let data = (await NTQQUserApi.getQzoneCookies())
|
||||||
const CookieValue = 'p_skey=' + data.p_skey + '; skey=' + data.skey + '; p_uin=o' + selfInfo.uin + '; uin=o' + selfInfo.uin;
|
const CookieValue = 'p_skey=' + data.p_skey + '; skey=' + data.skey + '; p_uin=o' + selfInfo.uin + '; uin=o' + selfInfo.uin
|
||||||
return { bkn: NTQQUserApi.genBkn(data.p_skey), cookies: CookieValue };
|
return { bkn: NTQQUserApi.genBkn(data.p_skey), cookies: CookieValue }
|
||||||
}
|
}
|
||||||
const skey = await this.getSkey();
|
const skey = await this.getSkey()
|
||||||
const pskey = (await this.getPSkey([domain])).get(domain);
|
const pskey = (await this.getPSkey([domain])).get(domain)
|
||||||
if (!pskey || !skey) {
|
if (!pskey || !skey) {
|
||||||
throw new Error('获取Cookies失败')
|
throw new Error('获取Cookies失败')
|
||||||
}
|
}
|
||||||
const bkn = NTQQUserApi.genBkn(skey)
|
const bkn = NTQQUserApi.genBkn(skey)
|
||||||
const cookies = `p_skey=${pskey}; skey=${skey}; p_uin=o${selfInfo.uin}; uin=o${selfInfo.uin}`;
|
const cookies = `p_skey=${pskey}; skey=${skey}; p_uin=o${selfInfo.uin}; uin=o${selfInfo.uin}`
|
||||||
return { cookies, bkn }
|
return { cookies, bkn }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
44
src/ntqqapi/listeners/NodeIKernelProfileListener.ts
Normal file
44
src/ntqqapi/listeners/NodeIKernelProfileListener.ts
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import { User, UserDetailInfoListenerArg } from '@/ntqqapi/types'
|
||||||
|
|
||||||
|
interface IProfileListener {
|
||||||
|
onProfileSimpleChanged(...args: unknown[]): void
|
||||||
|
|
||||||
|
onUserDetailInfoChanged(arg: UserDetailInfoListenerArg): void
|
||||||
|
|
||||||
|
onProfileDetailInfoChanged(profile: User): void
|
||||||
|
|
||||||
|
onStatusUpdate(...args: unknown[]): void
|
||||||
|
|
||||||
|
onSelfStatusChanged(...args: unknown[]): void
|
||||||
|
|
||||||
|
onStrangerRemarkChanged(...args: unknown[]): void
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface NodeIKernelProfileListener extends IProfileListener {
|
||||||
|
new(listener: IProfileListener): NodeIKernelProfileListener
|
||||||
|
}
|
||||||
|
|
||||||
|
export class ProfileListener implements IProfileListener {
|
||||||
|
onUserDetailInfoChanged(arg: UserDetailInfoListenerArg): void {
|
||||||
|
|
||||||
|
}
|
||||||
|
onProfileSimpleChanged(...args: unknown[]) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
onProfileDetailInfoChanged(profile: User) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
onStatusUpdate(...args: unknown[]) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
onSelfStatusChanged(...args: unknown[]) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
onStrangerRemarkChanged(...args: unknown[]) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
1
src/ntqqapi/listeners/index.ts
Normal file
1
src/ntqqapi/listeners/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './NodeIKernelProfileListener'
|
@ -222,3 +222,40 @@ export interface FriendV2 extends SimpleInfo {
|
|||||||
categoryId?: number
|
categoryId?: number
|
||||||
categroyName?: string
|
categroyName?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface CommonExt {
|
||||||
|
constellation: number
|
||||||
|
shengXiao: number
|
||||||
|
kBloodType: number
|
||||||
|
homeTown: string
|
||||||
|
makeFriendCareer: number
|
||||||
|
pos: string
|
||||||
|
college: string
|
||||||
|
country: string
|
||||||
|
province: string
|
||||||
|
city: string
|
||||||
|
postCode: string
|
||||||
|
address: string
|
||||||
|
regTime: number
|
||||||
|
interest: string
|
||||||
|
labels: any[]
|
||||||
|
qqLevel: QQLevel
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Pic {
|
||||||
|
picId: string
|
||||||
|
picTime: number
|
||||||
|
picUrlMap: Record<string, string>
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PhotoWall {
|
||||||
|
picList: Pic[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UserDetailInfoListenerArg {
|
||||||
|
uid: string
|
||||||
|
uin: string
|
||||||
|
simpleInfo: SimpleInfo
|
||||||
|
commonExt: CommonExt
|
||||||
|
photoWall: PhotoWall
|
||||||
|
}
|
@ -5,8 +5,8 @@ import { OB11Message, OB11MessageAt, OB11MessageData, OB11MessageDataType } from
|
|||||||
import { OB11FriendRequestEvent } from '../event/request/OB11FriendRequest'
|
import { OB11FriendRequestEvent } from '../event/request/OB11FriendRequest'
|
||||||
import { OB11GroupRequestEvent } from '../event/request/OB11GroupRequest'
|
import { OB11GroupRequestEvent } from '../event/request/OB11GroupRequest'
|
||||||
import { dbUtil } from '@/common/db'
|
import { dbUtil } from '@/common/db'
|
||||||
import { NTQQFriendApi, NTQQGroupApi, NTQQMsgApi, Peer } from '@/ntqqapi/api'
|
import { NTQQFriendApi, NTQQGroupApi, NTQQMsgApi } from '@/ntqqapi/api'
|
||||||
import { ChatType, Group, GroupRequestOperateTypes } from '@/ntqqapi/types'
|
import { ChatType, Group, GroupRequestOperateTypes, Peer } from '@/ntqqapi/types'
|
||||||
import { getGroup, getUidByUin } from '@/common/data'
|
import { getGroup, getUidByUin } from '@/common/data'
|
||||||
import { convertMessage2List, createSendElements, sendMsg } from './msg/SendMsg'
|
import { convertMessage2List, createSendElements, sendMsg } from './msg/SendMsg'
|
||||||
import { isNull, log } from '@/common/utils'
|
import { isNull, log } from '@/common/utils'
|
||||||
@ -129,7 +129,7 @@ async function handleMsg(msg: OB11Message, quickAction: QuickOperationPrivateMes
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function handleFriendRequest(request: OB11FriendRequestEvent,
|
async function handleFriendRequest(request: OB11FriendRequestEvent,
|
||||||
quickAction: QuickOperationFriendRequest) {
|
quickAction: QuickOperationFriendRequest) {
|
||||||
if (!isNull(quickAction.approve)) {
|
if (!isNull(quickAction.approve)) {
|
||||||
// todo: set remark
|
// todo: set remark
|
||||||
NTQQFriendApi.handleFriendRequest(request.flag, quickAction.approve).then().catch(log)
|
NTQQFriendApi.handleFriendRequest(request.flag, quickAction.approve).then().catch(log)
|
||||||
@ -138,7 +138,7 @@ async function handleFriendRequest(request: OB11FriendRequestEvent,
|
|||||||
|
|
||||||
|
|
||||||
async function handleGroupRequest(request: OB11GroupRequestEvent,
|
async function handleGroupRequest(request: OB11GroupRequestEvent,
|
||||||
quickAction: QuickOperationGroupRequest) {
|
quickAction: QuickOperationGroupRequest) {
|
||||||
if (!isNull(quickAction.approve)) {
|
if (!isNull(quickAction.approve)) {
|
||||||
NTQQGroupApi.handleGroupRequest(
|
NTQQGroupApi.handleGroupRequest(
|
||||||
request.flag,
|
request.flag,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user