mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
feat
This commit is contained in:
parent
c71885a29e
commit
6954551cb7
@ -199,14 +199,16 @@ function onLoad() {
|
||||
|
||||
// 创建窗口时触发
|
||||
function onBrowserWindowCreated(window: BrowserWindow) {
|
||||
if (window.id !== 2) {
|
||||
if (![2, 4].includes(window.id)) {
|
||||
return
|
||||
}
|
||||
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())
|
||||
}
|
||||
|
@ -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,
|
||||
],
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ const callHooks: Array<{
|
||||
hookFunc: (callParams: unknown[]) => void | Promise<void>
|
||||
}> = []
|
||||
|
||||
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,6 +65,7 @@ export function hookNTQQApiReceive(window: BrowserWindow) {
|
||||
log(`received ntqq api message: ${channel}`, args)
|
||||
}
|
||||
} catch { }
|
||||
if (!onlyLog) {
|
||||
if (args?.[1] instanceof Array) {
|
||||
for (const receiveData of args?.[1]) {
|
||||
const ntQQApiMethodName = receiveData.cmdName
|
||||
@ -95,12 +96,13 @@ export function hookNTQQApiReceive(window: BrowserWindow) {
|
||||
delete hookApiCallbacks[callbackId]
|
||||
}
|
||||
}
|
||||
}
|
||||
originalSend.call(window.webContents, channel, ...args)
|
||||
}
|
||||
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,6 +118,7 @@ export function hookNTQQApiCall(window: BrowserWindow) {
|
||||
try {
|
||||
logHook && log('call NTQQ api', thisArg, args)
|
||||
} catch (e) { }
|
||||
if (!onlyLog) {
|
||||
try {
|
||||
const _args: unknown[] = args[3][1]
|
||||
const cmdName: NTMethod = _args[0] as NTMethod
|
||||
@ -134,6 +137,7 @@ export function hookNTQQApiCall(window: BrowserWindow) {
|
||||
})
|
||||
} catch (e) { }
|
||||
}
|
||||
}
|
||||
return target.apply(thisArg, args)
|
||||
},
|
||||
})
|
||||
|
@ -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<ReturnType> {
|
||||
|
@ -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 } // 操作者
|
||||
|
17
src/onebot11/action/go-cqhttp/CreateGroupFileFolder.ts
Normal file
17
src/onebot11/action/go-cqhttp/CreateGroupFileFolder.ts
Normal file
@ -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<Payload, null> {
|
||||
actionName = ActionName.GoCQHTTP_CreateGroupFileFolder
|
||||
|
||||
async _handle(payload: Payload) {
|
||||
await this.ctx.ntGroupApi.createGroupFileFolder(payload.group_id.toString(), payload.name)
|
||||
return null
|
||||
}
|
||||
}
|
16
src/onebot11/action/go-cqhttp/DelGroupFolder.ts
Normal file
16
src/onebot11/action/go-cqhttp/DelGroupFolder.ts
Normal file
@ -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<Payload, null> {
|
||||
actionName = ActionName.GoCQHTTP_DelGroupFolder
|
||||
|
||||
async _handle(payload: Payload) {
|
||||
await this.ctx.ntGroupApi.deleteGroupFileFolder(payload.group_id.toString(), payload.folder_id)
|
||||
return null
|
||||
}
|
||||
}
|
59
src/onebot11/action/go-cqhttp/GetGroupSystemMsg.ts
Normal file
59
src/onebot11/action/go-cqhttp/GetGroupSystemMsg.ts
Normal file
@ -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<void, Response> {
|
||||
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
|
||||
}
|
||||
}
|
@ -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<string, BaseAction<any, any>>()
|
||||
for (const action of actionHandlers) {
|
||||
|
@ -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<null, OB11GroupReques
|
||||
|
||||
protected async _handle(payload: null): Promise<OB11GroupRequestNotify[]> {
|
||||
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)
|
||||
|
@ -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'
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user