diff --git a/src/main/main.ts b/src/main/main.ts index 59f3973..4804509 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -199,14 +199,16 @@ function onLoad() { // 创建窗口时触发 function onBrowserWindowCreated(window: BrowserWindow) { - if (window.id !== 2) { + if (![2, 4].includes(window.id)) { return } - mainWindow = window + if (window.id === 2) { + mainWindow = window + } log('window create', window.webContents.getURL().toString()) try { - hookNTQQApiCall(window) - hookNTQQApiReceive(window) + hookNTQQApiCall(window, window.id !== 2) + hookNTQQApiReceive(window, window.id !== 2) } catch (e: any) { log('LLOneBot hook error: ', e.toString()) } diff --git a/src/ntqqapi/api/group.ts b/src/ntqqapi/api/group.ts index 05132c5..ed95f6f 100644 --- a/src/ntqqapi/api/group.ts +++ b/src/ntqqapi/api/group.ts @@ -382,4 +382,30 @@ export class NTQQGroupApi extends Service { // GetMsgByShoretID(ShoretID) -> MsgService.getMsgs(Peer,MsgId,1,false) -> 组出参数 return session?.getGroupService().addGroupEssence(param) } + + async createGroupFileFolder(groupId: string, folderName: string) { + return await invoke({ + methodName: 'nodeIKernelRichMediaService/createGroupFolder', + args: [ + { + groupId, + folderName + }, + null, + ], + }) + } + + async deleteGroupFileFolder(groupId: string, folderId: string) { + return await invoke({ + methodName: 'nodeIKernelRichMediaService/deleteGroupFolder', + args: [ + { + groupId, + folderId + }, + null, + ], + }) + } } diff --git a/src/ntqqapi/core.ts b/src/ntqqapi/core.ts index f40b243..883f52a 100644 --- a/src/ntqqapi/core.ts +++ b/src/ntqqapi/core.ts @@ -33,7 +33,6 @@ declare module 'cordis' { 'nt/group-notify': (input: GroupNotify[]) => void 'nt/friend-request': (input: FriendRequest[]) => void 'nt/group-member-info-updated': (input: { groupCode: string; members: GroupMember[] }) => void - 'nt/friend-list-updated': (input: { groupCode: string; members: GroupMember[] }) => void } } diff --git a/src/ntqqapi/hook.ts b/src/ntqqapi/hook.ts index f9de852..5eaf14c 100644 --- a/src/ntqqapi/hook.ts +++ b/src/ntqqapi/hook.ts @@ -56,7 +56,7 @@ const callHooks: Array<{ hookFunc: (callParams: unknown[]) => void | Promise }> = [] -export function hookNTQQApiReceive(window: BrowserWindow) { +export function hookNTQQApiReceive(window: BrowserWindow, onlyLog: boolean) { const originalSend = window.webContents.send const patchSend = (channel: string, ...args: NTQQApiReturnData) => { try { @@ -65,34 +65,36 @@ export function hookNTQQApiReceive(window: BrowserWindow) { log(`received ntqq api message: ${channel}`, args) } } catch { } - if (args?.[1] instanceof Array) { - for (const receiveData of args?.[1]) { - const ntQQApiMethodName = receiveData.cmdName - // log(`received ntqq api message: ${channel} ${ntQQApiMethodName}`, JSON.stringify(receiveData)) - for (const hook of receiveHooks) { - if (hook.method.includes(ntQQApiMethodName)) { - new Promise((resolve, reject) => { - try { - hook.hookFunc(receiveData.payload) - } catch (e: any) { - log('hook error', ntQQApiMethodName, e.stack.toString()) - } - resolve(undefined) - }).then() + if (!onlyLog) { + if (args?.[1] instanceof Array) { + for (const receiveData of args?.[1]) { + const ntQQApiMethodName = receiveData.cmdName + // log(`received ntqq api message: ${channel} ${ntQQApiMethodName}`, JSON.stringify(receiveData)) + for (const hook of receiveHooks) { + if (hook.method.includes(ntQQApiMethodName)) { + new Promise((resolve, reject) => { + try { + hook.hookFunc(receiveData.payload) + } catch (e: any) { + log('hook error', ntQQApiMethodName, e.stack.toString()) + } + resolve(undefined) + }).then() + } } } } - } - if (args[0]?.callbackId) { - // log("hookApiCallback", hookApiCallbacks, args) - const callbackId = args[0].callbackId - if (hookApiCallbacks[callbackId]) { - // log("callback found") - new Promise((resolve, reject) => { - hookApiCallbacks[callbackId](args[1]) - resolve(undefined) - }).then() - delete hookApiCallbacks[callbackId] + if (args[0]?.callbackId) { + // log("hookApiCallback", hookApiCallbacks, args) + const callbackId = args[0].callbackId + if (hookApiCallbacks[callbackId]) { + // log("callback found") + new Promise((resolve, reject) => { + hookApiCallbacks[callbackId](args[1]) + resolve(undefined) + }).then() + delete hookApiCallbacks[callbackId] + } } } originalSend.call(window.webContents, channel, ...args) @@ -100,7 +102,7 @@ export function hookNTQQApiReceive(window: BrowserWindow) { window.webContents.send = patchSend } -export function hookNTQQApiCall(window: BrowserWindow) { +export function hookNTQQApiCall(window: BrowserWindow, onlyLog: boolean) { // 监听调用NTQQApi let webContents = window.webContents as any const ipc_message_proxy = webContents._events['-ipc-message']?.[0] || webContents._events['-ipc-message'] @@ -116,23 +118,25 @@ export function hookNTQQApiCall(window: BrowserWindow) { try { logHook && log('call NTQQ api', thisArg, args) } catch (e) { } - try { - const _args: unknown[] = args[3][1] - const cmdName: NTMethod = _args[0] as NTMethod - const callParams = _args.slice(1) - callHooks.forEach((hook) => { - if (hook.method.includes(cmdName)) { - new Promise((resolve, reject) => { - try { - hook.hookFunc(callParams) - } catch (e: any) { - log('hook call error', e, _args) - } - resolve(undefined) - }).then() - } - }) - } catch (e) { } + if (!onlyLog) { + try { + const _args: unknown[] = args[3][1] + const cmdName: NTMethod = _args[0] as NTMethod + const callParams = _args.slice(1) + callHooks.forEach((hook) => { + if (hook.method.includes(cmdName)) { + new Promise((resolve, reject) => { + try { + hook.hookFunc(callParams) + } catch (e: any) { + log('hook call error', e, _args) + } + resolve(undefined) + }).then() + } + }) + } catch (e) { } + } } return target.apply(thisArg, args) }, diff --git a/src/ntqqapi/ntcall.ts b/src/ntqqapi/ntcall.ts index 2ca3bdd..302586f 100644 --- a/src/ntqqapi/ntcall.ts +++ b/src/ntqqapi/ntcall.ts @@ -89,9 +89,10 @@ export enum NTMethod { } export enum NTChannel { + IPC_UP_1 = 'IPC_UP_1', IPC_UP_2 = 'IPC_UP_2', IPC_UP_3 = 'IPC_UP_3', - IPC_UP_1 = 'IPC_UP_1', + IPC_UP_4 = 'IPC_UP_4' } interface InvokeParams { diff --git a/src/ntqqapi/types/notify.ts b/src/ntqqapi/types/notify.ts index 1310612..926489b 100644 --- a/src/ntqqapi/types/notify.ts +++ b/src/ntqqapi/types/notify.ts @@ -17,17 +17,18 @@ export interface GroupNotifies { } export enum GroupNotifyStatus { - IGNORE = 0, - WAIT_HANDLE = 1, - APPROVE = 2, - REJECT = 3, + KINIT, // 初始化 + KUNHANDLE, // 未处理 + KAGREED, // 同意 + KREFUSED, // 拒绝 + KIGNORED // 忽略 } export interface GroupNotify { time: number // 自己添加的字段,时间戳,毫秒, 用于判断收到短时间内收到重复的notify seq: string // 唯一标识符,转成数字再除以1000应该就是时间戳? type: GroupNotifyTypes - status: GroupNotifyStatus // 0是已忽略?,1是未处理,2是已同意 + status: GroupNotifyStatus group: { groupCode: string; groupName: string } user1: { uid: string; nickName: string } // 被设置管理员的人 user2: { uid: string; nickName: string } // 操作者 diff --git a/src/onebot11/action/go-cqhttp/CreateGroupFileFolder.ts b/src/onebot11/action/go-cqhttp/CreateGroupFileFolder.ts new file mode 100644 index 0000000..4fdafdd --- /dev/null +++ b/src/onebot11/action/go-cqhttp/CreateGroupFileFolder.ts @@ -0,0 +1,17 @@ +import BaseAction from '../BaseAction' +import { ActionName } from '../types' + +interface Payload { + group_id: number | string + name: string + parent_id?: '/' +} + +export class GoCQHTTPCreateGroupFileFolder extends BaseAction { + actionName = ActionName.GoCQHTTP_CreateGroupFileFolder + + async _handle(payload: Payload) { + await this.ctx.ntGroupApi.createGroupFileFolder(payload.group_id.toString(), payload.name) + return null + } +} \ No newline at end of file diff --git a/src/onebot11/action/go-cqhttp/DelGroupFolder.ts b/src/onebot11/action/go-cqhttp/DelGroupFolder.ts new file mode 100644 index 0000000..2e4a692 --- /dev/null +++ b/src/onebot11/action/go-cqhttp/DelGroupFolder.ts @@ -0,0 +1,16 @@ +import BaseAction from '../BaseAction' +import { ActionName } from '../types' + +interface Payload { + group_id: number | string + folder_id: string +} + +export class GoCQHTTPDelGroupFolder extends BaseAction { + actionName = ActionName.GoCQHTTP_DelGroupFolder + + async _handle(payload: Payload) { + await this.ctx.ntGroupApi.deleteGroupFileFolder(payload.group_id.toString(), payload.folder_id) + return null + } +} \ No newline at end of file diff --git a/src/onebot11/action/go-cqhttp/GetGroupSystemMsg.ts b/src/onebot11/action/go-cqhttp/GetGroupSystemMsg.ts new file mode 100644 index 0000000..bbaba57 --- /dev/null +++ b/src/onebot11/action/go-cqhttp/GetGroupSystemMsg.ts @@ -0,0 +1,59 @@ +import BaseAction from '../BaseAction' +import { GroupNotifyStatus } from '@/ntqqapi/types' +import { ActionName } from '../types' + +interface Response { + invited_requests: { + request_id: number + invitor_uin: number + invitor_nick: string + group_id: number + group_name: string + checked: boolean + actor: number + }[] + join_requests: { + request_id: number + requester_uin: number + requester_nick: string + message: string + group_id: number + group_name: string + checked: boolean + actor: number + }[] +} + +export class GoCQHTTPGetGroupSystemMsg extends BaseAction { + actionName = ActionName.GoCQHTTP_GetGroupSystemMsg + + async _handle(payload: void) { + const singleScreenNotifies = await this.ctx.ntGroupApi.getSingleScreenNotifies(10) + const data: Response = { invited_requests: [], join_requests: [] } + for (const notify of singleScreenNotifies) { + if (notify.type == 1) { + data.invited_requests.push({ + request_id: +notify.seq, + invitor_uin: Number(await this.ctx.ntUserApi.getUinByUid(notify.user1.uid)), + invitor_nick: notify.user1.nickName, + group_id: +notify.group.groupCode, + group_name: notify.group.groupName, + checked: notify.status !== GroupNotifyStatus.KUNHANDLE, + actor: notify.user2?.uid ? Number(await this.ctx.ntUserApi.getUinByUid(notify.user2.uid)) : 0 + }) + } else if (notify.type == 7) { + data.join_requests.push({ + request_id: +notify.seq, + requester_uin: Number(await this.ctx.ntUserApi.getUinByUid(notify.user1.uid)), + requester_nick: notify.user1.nickName, + message: notify.postscript, + group_id: +notify.group.groupCode, + group_name: notify.group.groupName, + checked: notify.status !== GroupNotifyStatus.KUNHANDLE, + actor: notify.user2?.uid ? Number(await this.ctx.ntUserApi.getUinByUid(notify.user2.uid)) : 0 + }) + } + } + return data + } +} \ No newline at end of file diff --git a/src/onebot11/action/index.ts b/src/onebot11/action/index.ts index 71bf307..d37de37 100644 --- a/src/onebot11/action/index.ts +++ b/src/onebot11/action/index.ts @@ -1,3 +1,4 @@ +import type Adapter from '../adapter' import GetMsg from './msg/GetMsg' import GetLoginInfo from './system/GetLoginInfo' import { GetFriendList, GetFriendWithCategory } from './user/GetFriendList' @@ -54,7 +55,9 @@ import GoCQHTTPSetEssenceMsg from './go-cqhttp/SetEssenceMsg' import GoCQHTTPDelEssenceMsg from './go-cqhttp/DelEssenceMsg' import GetEvent from './llonebot/GetEvent' import { GoCQHTTPDelGroupFile } from './go-cqhttp/DelGroupFile' -import type Adapter from '../adapter' +import { GoCQHTTPGetGroupSystemMsg } from './go-cqhttp/GetGroupSystemMsg' +import { GoCQHTTPCreateGroupFileFolder } from './go-cqhttp/CreateGroupFileFolder' +import { GoCQHTTPDelGroupFolder } from './go-cqhttp/DelGroupFolder' export function initActionMap(adapter: Adapter) { const actionHandlers = [ @@ -116,7 +119,10 @@ export function initActionMap(adapter: Adapter) { new GoCQHTTHandleQuickOperation(adapter), new GoCQHTTPSetEssenceMsg(adapter), new GoCQHTTPDelEssenceMsg(adapter), - new GoCQHTTPDelGroupFile(adapter) + new GoCQHTTPDelGroupFile(adapter), + new GoCQHTTPGetGroupSystemMsg(adapter), + new GoCQHTTPCreateGroupFileFolder(adapter), + new GoCQHTTPDelGroupFolder(adapter) ] const actionMap = new Map>() for (const action of actionHandlers) { diff --git a/src/onebot11/action/llonebot/GetGroupAddRequest.ts b/src/onebot11/action/llonebot/GetGroupAddRequest.ts index e375600..d810f25 100644 --- a/src/onebot11/action/llonebot/GetGroupAddRequest.ts +++ b/src/onebot11/action/llonebot/GetGroupAddRequest.ts @@ -1,5 +1,5 @@ -import { GroupNotify, GroupNotifyStatus } from '@/ntqqapi/types' import BaseAction from '../BaseAction' +import { GroupNotify, GroupNotifyStatus } from '@/ntqqapi/types' import { ActionName } from '../types' interface OB11GroupRequestNotify { @@ -13,7 +13,7 @@ export default class GetGroupAddRequest extends BaseAction { const data = await this.ctx.ntGroupApi.getGroupIgnoreNotifies() - const notifies: GroupNotify[] = data.notifies.filter((notify) => notify.status === GroupNotifyStatus.WAIT_HANDLE) + const notifies: GroupNotify[] = data.notifies.filter((notify) => notify.status === GroupNotifyStatus.KUNHANDLE) const returnData: OB11GroupRequestNotify[] = [] for (const notify of notifies) { const uin = await this.ctx.ntUserApi.getUinByUid(notify.user1.uid) diff --git a/src/onebot11/action/types.ts b/src/onebot11/action/types.ts index 71730ea..cf675ff 100644 --- a/src/onebot11/action/types.ts +++ b/src/onebot11/action/types.ts @@ -74,4 +74,7 @@ export enum ActionName { GoCQHTTP_SetEssenceMsg = 'set_essence_msg', GoCQHTTP_DelEssenceMsg = 'delete_essence_msg', GoCQHTTP_DelGroupFile = 'delete_group_file', + GoCQHTTP_GetGroupSystemMsg = 'get_group_system_msg', + GoCQHTTP_CreateGroupFileFolder = 'create_group_file_folder', + GoCQHTTP_DelGroupFolder = 'delete_group_folder' }