diff --git a/src/ntqq/core/core.ts b/src/ntqq/core/core.ts index 546170e..8aa08ae 100644 --- a/src/ntqq/core/core.ts +++ b/src/ntqq/core/core.ts @@ -7,33 +7,37 @@ const dispatcher = useNTDispatcher() const log = useLogger('NTStore') const wrapperUtil = new NodeQQNTWrapperUtil() const globalAdapter = new NodeIGlobalAdapter({ - onGetOfflineMsg(...args) { - log.info('GlobalAdapter/onGetOfflineMsg', ...args) - dispatcher.emit('GlobalAdapter/onGetOfflineMsg', ...args) + onLog(...args) { + log.info('GlobalAdapter/onLog', ...args) + dispatcher.emit('GlobalAdapter/onLog', ...args) }, onGetSrvCalTime(...args) { log.info('GlobalAdapter/onGetSrvCalTime', ...args) dispatcher.emit('GlobalAdapter/onGetSrvCalTime', ...args) }, - async onInstallFinished(...args) { - log.info('GlobalAdapter/onInstallFinished', ...args) - dispatcher.emit('GlobalAdapter/onInstallFinished', ...args) - }, - onLog(...args) { - log.info('GlobalAdapter/onLog', ...args) - dispatcher.emit('GlobalAdapter/onLog', ...args) - }, onShowErrUITips(...args) { log.info('GlobalAdapter/onShowErrUITips', ...args) dispatcher.emit('GlobalAdapter/onShowErrUITips', ...args) }, + async fixPicImgType(...args) { + log.info('GlobalAdapter/fixPicImgType', ...args) + dispatcher.emit('GlobalAdapter/fixPicImgType', ...args) + }, + getAppSetting(...args) { + log.info('GlobalAdapter/getAppSetting', ...args) + dispatcher.emit('GlobalAdapter/getAppSetting', ...args) + }, + async onInstallFinished(...args) { + log.info('GlobalAdapter/onInstallFinished', ...args) + dispatcher.emit('GlobalAdapter/onInstallFinished', ...args) + }, onUpdateGeneralFlag(...args) { log.info('GlobalAdapter/onUpdateGeneralFlag', ...args) dispatcher.emit('GlobalAdapter/onUpdateGeneralFlag', ...args) }, - async fixPicImgType(...args) { - log.info('GlobalAdapter/fixPicImgType', ...args) - dispatcher.emit('GlobalAdapter/fixPicImgType', ...args) + onGetOfflineMsg(...args) { + log.info('GlobalAdapter/onGetOfflineMsg', ...args) + dispatcher.emit('GlobalAdapter/onGetOfflineMsg', ...args) }, }) const wrapperEngine = new NodeIQQNTWrapperEngine() diff --git a/src/ntqq/core/prepare.ts b/src/ntqq/core/prepare.ts index bdea807..f6fa497 100644 --- a/src/ntqq/core/prepare.ts +++ b/src/ntqq/core/prepare.ts @@ -50,6 +50,7 @@ export const prepareBaseEnvironment = async() => { density: 2 } } + log.info('cfg:', cfg) const globalAdapter = getGlobalAdapter() const wrapperEngine = getWrapperEngine() const initResult = wrapperEngine.initWithDeskTopConfig(cfg, globalAdapter) diff --git a/src/ntqq/core/service/login.ts b/src/ntqq/core/service/login.ts index 7e53c93..4e5c4b1 100644 --- a/src/ntqq/core/service/login.ts +++ b/src/ntqq/core/service/login.ts @@ -18,7 +18,7 @@ export const initLogin = () => { const listener = new NodeIKernelLoginListener(p) const { registerEventListener } = useStore() log.info('add handle after login success.') - registerEventListener('KernelLoginListener/onQRCodeLoginSucceed', 'once', (info) => { + registerEventListener('KernelLoginListener/onQRCodeLoginSucceed', 'always', (info) => { const { userInfo } = useNTUserStore() userInfo.uid = info.uid userInfo.uin = info.uin diff --git a/src/ntqq/login/account.ts b/src/ntqq/login/account.ts index 75e33e1..d595c31 100644 --- a/src/ntqq/login/account.ts +++ b/src/ntqq/login/account.ts @@ -128,4 +128,20 @@ export const NTLoginByAccountInfo = (ntLogin: NTLogin.AccountLoginRequest): Prom } }) +} + +export const NTGetQuickLoginList = async () => { + const { getLoginService } = useNTCore() + await sleep(2000) + const loginService = getLoginService() + const loginList = await loginService.getLoginList() + return loginList.LocalLoginInfoList +} + +export const NTQuickLoginByUin = async (uin: `${number}`) => { + const { getLoginService } = useNTCore() + await sleep(2000) + const loginService = getLoginService() + const loginResult = await loginService.quickLoginWithUin(uin) + return loginResult } \ No newline at end of file diff --git a/src/ntqq/store/config.ts b/src/ntqq/store/config.ts index 8fc043c..2fe9315 100644 --- a/src/ntqq/store/config.ts +++ b/src/ntqq/store/config.ts @@ -80,7 +80,7 @@ const getAppInfo = (): StoreAppInfo => { } } const getAppId = () => { - return platform === 'win32' ? '537207183' : '537207207' + return platform === 'win32' ? '537237802' : '537207207' } const getNTConfigStoreFolder = (): string => { const wrapperUtil = new NodeQQNTWrapperUtil() diff --git a/src/onebot/actions/bot/bot.ts b/src/onebot/actions/bot/bot.ts index 77f3b4d..7d08836 100644 --- a/src/onebot/actions/bot/bot.ts +++ b/src/onebot/actions/bot/bot.ts @@ -1,10 +1,13 @@ import { useLogger } from "../../../common/log" +import { NTGetQuickLoginList, NTQuickLoginByUin } from "../../../ntqq/login/account" import { useNTUserStore } from "../../../ntqq/store/user" import { CustomError } from "../../../server/error/custom-error" import { useStore } from "../../../store/store" import { loginByAccount, loginByQrCode } from "../../../transfer/login/login" import { getUserInfoByUid } from "../../common/user" import { UserInfoReq, UserInfoResp } from "../friend/interfaces" +import { BotActionParams } from "../interfaces" +import { QuickLoginItem } from "./types" const log = useLogger('Bot') const getBotInfo = async (p: {}): Promise => { @@ -24,14 +27,41 @@ const getBotInfo = async (p: {}): Promise => { log.info('getUserDetailInfo:', ret) resp.user_uid = ret.uid resp.user_uin = parseInt(ret.uin) - resp.nick = ret.nick + resp.nick = ret.simpleInfo.coreInfo.nick resp.avatar_url = `http://q1.qlogo.cn/g?b=qq&nk=${resp.user_uin}&s=640` return resp } +const getQuickLoginList = async (p: {}) => { + const list = await NTGetQuickLoginList() + return list.map(e => ({ + uin: e.uin, + uid: e.uid, + nick_name: e.nickName, + face_path: e.facePath, + face_url: e.faceUrl, + login_type: e.loginType, + is_quick_login: e.isQuickLogin, + is_auto_login: e.isAutoLogin, + })) +} + +interface QuickLoginReq extends BotActionParams { + uin: `${number}` +} +const QuickLoginByUin = async (p: QuickLoginReq) => { + const result = await NTQuickLoginByUin(p.uin) + if (result.result !== '0') + { + throw new CustomError(parseInt(result.result), result.loginErrorInfo.errMsg) + } + return {} +} export const initBot = () => { const { registerActionHandle } = useStore() // 登录 registerActionHandle('login_by_account', loginByAccount) registerActionHandle('login_by_qrcode', loginByQrCode) registerActionHandle('get_self_info', getBotInfo) + registerActionHandle('get_quick_login_list', getQuickLoginList) + registerActionHandle('quick_login_by_uin', QuickLoginByUin) } \ No newline at end of file diff --git a/src/onebot/actions/bot/types.d.ts b/src/onebot/actions/bot/types.d.ts new file mode 100644 index 0000000..cc11298 --- /dev/null +++ b/src/onebot/actions/bot/types.d.ts @@ -0,0 +1,25 @@ +export interface QuickLoginItem { + /** + * QQ号 + */ + uin: `${number}` + /** + * 用户ID + */ + uid: `u_${string}` + /** + * 昵称 + */ + nick_name: string + face_url: string + face_path: string + login_type: 1 | 2 + /** + * 是否快速登录 + */ + is_quick_login: boolean + /** + * 是否自动登录 + */ + is_auto_login: boolean +} \ No newline at end of file diff --git a/src/onebot/actions/friend/friend.ts b/src/onebot/actions/friend/friend.ts index 6afe506..17e5326 100644 --- a/src/onebot/actions/friend/friend.ts +++ b/src/onebot/actions/friend/friend.ts @@ -55,7 +55,7 @@ const getUserInfo = async (p: UserInfoReq): Promise => { log.info('getUserDetailInfo:', ret) resp.user_uid = ret.uid resp.user_uin = parseInt(ret.uin) - resp.nick = ret.nick + resp.nick = ret.simpleInfo.coreInfo.nick resp.avatar_url = `http://q1.qlogo.cn/g?b=qq&nk=${resp.user_uin}&s=640` return resp } diff --git a/src/onebot/common/interfaces.d.ts b/src/onebot/common/interfaces.d.ts index 52ec376..100025b 100644 --- a/src/onebot/common/interfaces.d.ts +++ b/src/onebot/common/interfaces.d.ts @@ -3,26 +3,15 @@ export interface UserDetailInfoType { * 唯一标识 */ uid: `u_${string}` - qid: string /** * QQ号 */ uin: string - /** - * QQ昵称 - */ - nick: string - remark: string - longNick: string - avatarUrl: string - birthday_year: number - birthday_month: number - birthday_day: number - /** - * 2 - 女 - */ - sex: number - regTime: number + simpleInfo: { + coreInfo: { + nick: string + } + } } export interface GroupDetailInfoType { /** diff --git a/src/onebot/common/user.ts b/src/onebot/common/user.ts index a5e4ddf..e4b4c3f 100644 --- a/src/onebot/common/user.ts +++ b/src/onebot/common/user.ts @@ -14,7 +14,7 @@ export const getUserInfoByUid = (uid: `u_${string}`): Promise { if (userInfoListener) - removeEventListener('KernelProfileListener/onProfileDetailInfoChanged', userInfoListener) + removeEventListener('KernelProfileListener/onUserDetailInfoChanged', userInfoListener) reject('getUserInfoByUid timeout') }, 30000) userInfoListener = (payload: UserDetailInfoType) => { @@ -23,7 +23,7 @@ export const getUserInfoByUid = (uid: `u_${string}`): Promise { + const { sendMessage } = useServer() + const getQrCode = registerEventListener('KernelLoginListener/onQRCodeSessionFailed', 'once', (p1: number, p2: number) => { + /** + * 未扫描,超时:1 10 + * 扫描了,超时未确认:1 10 + */ + const ret: EventDataType = { + self: { + id: 0, + uid: 'u_0' + }, + time: new Date().getTime(), + type: "notice", + detail_type: "qrcode_error", + sub_type: "", + data: { + p1, + p2, + } + } + sendMessage(JSON.stringify(ret)) + }) +} +/** + * 登录二维码被扫描 + * + * @returns + */ +const qrCodeScaned = () => { + const { sendMessage } = useServer() + const getQrCode = registerEventListener('KernelLoginListener/onQRCodeSessionUserScaned', 'once', (p1: number, avatarUrl: string) => { + + const ret: EventDataType = { + self: { + id: 0, + uid: 'u_0' + }, + time: new Date().getTime(), + type: "notice", + detail_type: "qrcode_scaned", + sub_type: "", + data: { + p1, + avatar_url: avatarUrl, + } + } + sendMessage(JSON.stringify(ret)) + }) +} + +/** + * 二维码登录成功 + * + * @returns + */ +const qrCodeSuccess = () => { + const { sendMessage } = useServer() + const getQrCode = registerEventListener('KernelLoginListener/onQRCodeLoginSucceed', 'once', (userInfo) => { + + const ret: EventDataType = { + self: { + id: parseInt(userInfo.uin), + uid: userInfo.uid + }, + time: new Date().getTime(), + type: "notice", + detail_type: "qrcode_success", + sub_type: "", + data: { + account: userInfo.account, + uin: userInfo.uin, + uid: userInfo.uid, + nick_name: userInfo.nickName, + face_url: userInfo.faceUrl, + } + } + sendMessage(JSON.stringify(ret)) + }) +} + +/** + * 二维码登录成功 + * + * @returns + */ +const alreadyLogin = () => { + const { sendMessage } = useServer() + const getQrCode = registerEventListener('KernelLoginListener/onUserLoggedIn', 'once', (uin: number) => { + + const ret: EventDataType = { + self: { + id: 0, + uid: 'u_' + }, + time: new Date().getTime(), + type: "notice", + detail_type: "qrcode_userLogged", + sub_type: "", + data: { + uin: uin, + } + } + sendMessage(JSON.stringify(ret)) + }) +} + +/** + * 请求二维码的时候才会调用 + */ +export const listenLoginEvent = () => { + qrCodeFailed(); + qrCodeScaned(); + qrCodeSuccess(); + alreadyLogin(); +} \ No newline at end of file diff --git a/src/onebot/event/message.ts b/src/onebot/event/message.ts index 43c69fe..514595b 100644 --- a/src/onebot/event/message.ts +++ b/src/onebot/event/message.ts @@ -208,31 +208,6 @@ const onUpdateMsg = () => { }) } -/** - * 获取登录二维码 - * @returns 二维码信息 - */ -export const qrCodeFailed = () => { - const { sendMessage } = useServer() - const getQrCode = registerEventListener('KernelLoginListener/onQRCodeSessionFailed', 'always', (p1: number, p2: number) => { - - const ret: EventDataType = { - self: { - id: 0, - uid: 'u_0' - }, - time: new Date().getTime(), - type: "notice", - detail_type: "qrcode_error", - sub_type: "", - data: { - p1, - p2, - } - } - sendMessage(JSON.stringify(ret)) - }) -} /** * 监听消息事件 * @@ -242,5 +217,4 @@ export const listenMessage = () => { onRecvMsg() onAddSendMsg() onUpdateMsg() - qrCodeFailed(); } \ No newline at end of file diff --git a/src/transfer/login/login.ts b/src/transfer/login/login.ts index e1d5947..1410afb 100644 --- a/src/transfer/login/login.ts +++ b/src/transfer/login/login.ts @@ -5,6 +5,7 @@ import { BotLogin } from "../../onebot/actions/bot/interfaces" import { BotActionResponse, BotActionParams } from "../../onebot/actions/interfaces" import { useLogger } from "../../common/log" import { CustomError } from "../../server/error/custom-error" +import { listenLoginEvent } from "../../onebot/event/login" const log = useLogger('Login') @@ -51,6 +52,7 @@ export const loginByAccount = async (p: BotLogin.AccountLoginData): Promise */ export const loginByQrCode = async (p: BotActionParams): Promise => { const resp = await NTGetLoginQrCode() + listenLoginEvent(); return { qrCodeImage: resp.pngBase64QrcodeData, qrCodeUrl: resp.qrcodeUrl,