mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
chore: improve code quality
chore: improve code quality chore: improve code quality
This commit is contained in:
parent
eae6e09e22
commit
e185e700b7
@ -53,15 +53,15 @@ function onLoad() {
|
||||
fs.mkdirSync(LOG_DIR)
|
||||
}
|
||||
|
||||
ipcMain.handle(CHANNEL_CHECK_VERSION, async (event, arg) => {
|
||||
ipcMain.handle(CHANNEL_CHECK_VERSION, async () => {
|
||||
return checkNewVersion()
|
||||
})
|
||||
|
||||
ipcMain.handle(CHANNEL_UPDATE, async (event, arg) => {
|
||||
ipcMain.handle(CHANNEL_UPDATE, async () => {
|
||||
return upgradeLLOneBot()
|
||||
})
|
||||
|
||||
ipcMain.handle(CHANNEL_SELECT_FILE, async (event, arg) => {
|
||||
ipcMain.handle(CHANNEL_SELECT_FILE, async () => {
|
||||
const selectPath = new Promise<string>((resolve, reject) => {
|
||||
dialog
|
||||
.showOpenDialog({
|
||||
@ -90,10 +90,10 @@ function onLoad() {
|
||||
}
|
||||
})
|
||||
|
||||
ipcMain.handle(CHANNEL_ERROR, async (event, arg) => {
|
||||
ipcMain.handle(CHANNEL_ERROR, async () => {
|
||||
const ffmpegOk = await checkFfmpeg(getConfigUtil().getConfig().ffmpeg)
|
||||
llonebotError.ffmpegError = ffmpegOk ? '' : '没有找到 FFmpeg, 音频只能发送 WAV 和 SILK, 视频尺寸可能异常'
|
||||
let { httpServerError, wsServerError, otherError, ffmpegError } = llonebotError
|
||||
const { httpServerError, wsServerError, otherError, ffmpegError } = llonebotError
|
||||
let error = `${otherError}\n${httpServerError}\n${wsServerError}\n${ffmpegError}`
|
||||
error = error.replace('\n\n', '\n')
|
||||
error = error.trim()
|
||||
@ -101,12 +101,12 @@ function onLoad() {
|
||||
return error
|
||||
})
|
||||
|
||||
ipcMain.handle(CHANNEL_GET_CONFIG, async (event, arg) => {
|
||||
ipcMain.handle(CHANNEL_GET_CONFIG, async () => {
|
||||
const config = getConfigUtil().getConfig()
|
||||
return config
|
||||
})
|
||||
|
||||
ipcMain.handle(CHANNEL_SET_CONFIG, (event, ask: boolean, config: LLOBConfig) => {
|
||||
ipcMain.handle(CHANNEL_SET_CONFIG, (_event, ask: boolean, config: LLOBConfig) => {
|
||||
return new Promise<boolean>(resolve => {
|
||||
if (!ask) {
|
||||
getConfigUtil().setConfig(config)
|
||||
@ -139,7 +139,7 @@ function onLoad() {
|
||||
})
|
||||
})
|
||||
|
||||
ipcMain.on(CHANNEL_LOG, (event, arg) => {
|
||||
ipcMain.on(CHANNEL_LOG, (_event, arg) => {
|
||||
log(arg)
|
||||
})
|
||||
|
||||
@ -212,15 +212,15 @@ function onBrowserWindowCreated(window: BrowserWindow) {
|
||||
try {
|
||||
hookNTQQApiCall(window, window.id !== 2)
|
||||
hookNTQQApiReceive(window, window.id !== 2)
|
||||
} catch (e: any) {
|
||||
log('LLOneBot hook error: ', e.toString())
|
||||
} catch (e) {
|
||||
log('LLOneBot hook error: ', String(e))
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
onLoad()
|
||||
} catch (e: any) {
|
||||
console.log(e.toString())
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
|
||||
// 这两个函数都是可选的
|
||||
|
@ -26,34 +26,19 @@ export class NTQQGroupApi extends Service {
|
||||
}
|
||||
|
||||
async getGroups(forced = false): Promise<Group[]> {
|
||||
if (NTEventDispatch.initialised) {
|
||||
type ListenerType = NodeIKernelGroupListener['onGroupListUpdate']
|
||||
const [, , groupList] = await NTEventDispatch.CallNormalEvent
|
||||
<(force: boolean) => Promise<any>, ListenerType>
|
||||
(
|
||||
'NodeIKernelGroupService/getGroupList',
|
||||
'NodeIKernelGroupListener/onGroupListUpdate',
|
||||
1,
|
||||
5000,
|
||||
() => true,
|
||||
forced
|
||||
)
|
||||
return groupList
|
||||
} else {
|
||||
const result = await invoke<{
|
||||
updateType: number
|
||||
groupList: Group[]
|
||||
}>(
|
||||
'getGroupList',
|
||||
[],
|
||||
{
|
||||
className: NTClass.NODE_STORE_API,
|
||||
cbCmd: ReceiveCmdS.GROUPS_STORE,
|
||||
afterFirstCmd: false,
|
||||
}
|
||||
)
|
||||
return result.groupList
|
||||
}
|
||||
const result = await invoke<{
|
||||
updateType: number
|
||||
groupList: Group[]
|
||||
}>(
|
||||
'getGroupList',
|
||||
[],
|
||||
{
|
||||
className: NTClass.NODE_STORE_API,
|
||||
cbCmd: ReceiveCmdS.GROUPS_STORE,
|
||||
afterFirstCmd: false,
|
||||
}
|
||||
)
|
||||
return result.groupList
|
||||
}
|
||||
|
||||
async getGroupMembers(groupCode: string, num = 3000): Promise<Map<string, GroupMember>> {
|
||||
@ -114,32 +99,16 @@ export class NTQQGroupApi extends Service {
|
||||
}
|
||||
|
||||
async getSingleScreenNotifies(num: number) {
|
||||
if (NTEventDispatch.initialised) {
|
||||
const [_retData, _doubt, _seq, notifies] = await NTEventDispatch.CallNormalEvent
|
||||
<(arg1: boolean, arg2: string, arg3: number) => Promise<any>, (doubt: boolean, seq: string, notifies: GroupNotify[]) => void>
|
||||
(
|
||||
'NodeIKernelGroupService/getSingleScreenNotifies',
|
||||
'NodeIKernelGroupListener/onGroupSingleScreenNotifies',
|
||||
1,
|
||||
5000,
|
||||
() => true,
|
||||
false,
|
||||
'',
|
||||
num,
|
||||
)
|
||||
return notifies
|
||||
} else {
|
||||
invoke(ReceiveCmdS.GROUP_NOTIFY, [], { classNameIsRegister: true })
|
||||
return (await invoke<GroupNotifies>(
|
||||
'nodeIKernelGroupService/getSingleScreenNotifies',
|
||||
[{ doubt: false, startSeq: '', number: num }, null],
|
||||
{
|
||||
invoke(ReceiveCmdS.GROUP_NOTIFY, [], { classNameIsRegister: true })
|
||||
return (await invoke<GroupNotifies>(
|
||||
'nodeIKernelGroupService/getSingleScreenNotifies',
|
||||
[{ doubt: false, startSeq: '', number: num }, null],
|
||||
{
|
||||
|
||||
cbCmd: ReceiveCmdS.GROUP_NOTIFY,
|
||||
afterFirstCmd: false,
|
||||
}
|
||||
)).notifies
|
||||
}
|
||||
cbCmd: ReceiveCmdS.GROUP_NOTIFY,
|
||||
afterFirstCmd: false,
|
||||
}
|
||||
)).notifies
|
||||
}
|
||||
|
||||
async handleGroupRequest(flag: string, operateType: GroupRequestOperateTypes, reason?: string) {
|
||||
@ -260,30 +229,30 @@ export class NTQQGroupApi extends Service {
|
||||
}
|
||||
|
||||
/** 27187 TODO */
|
||||
async removeGroupEssence(GroupCode: string, msgId: string) {
|
||||
async removeGroupEssence(groupCode: string, msgId: string) {
|
||||
const session = getSession()
|
||||
// 代码没测过
|
||||
// 需要 ob11msgid->msgId + (peer) -> msgSeq + msgRandom
|
||||
let MsgData = await session?.getMsgService().getMsgsIncludeSelf({ chatType: 2, guildId: '', peerUid: GroupCode }, msgId, 1, false)
|
||||
let param = {
|
||||
groupCode: GroupCode,
|
||||
msgRandom: parseInt(MsgData?.msgList[0].msgRandom!),
|
||||
msgSeq: parseInt(MsgData?.msgList[0].msgSeq!)
|
||||
const data = await session?.getMsgService().getMsgsIncludeSelf({ chatType: 2, guildId: '', peerUid: groupCode }, msgId, 1, false)
|
||||
const param = {
|
||||
groupCode: groupCode,
|
||||
msgRandom: Number(data?.msgList[0].msgRandom),
|
||||
msgSeq: Number(data?.msgList[0].msgSeq)
|
||||
}
|
||||
// GetMsgByShoretID(ShoretID) -> MsgService.getMsgs(Peer,MsgId,1,false) -> 组出参数
|
||||
return session?.getGroupService().removeGroupEssence(param)
|
||||
}
|
||||
|
||||
/** 27187 TODO */
|
||||
async addGroupEssence(GroupCode: string, msgId: string) {
|
||||
async addGroupEssence(groupCode: string, msgId: string) {
|
||||
const session = getSession()
|
||||
// 代码没测过
|
||||
// 需要 ob11msgid->msgId + (peer) -> msgSeq + msgRandom
|
||||
let MsgData = await session?.getMsgService().getMsgsIncludeSelf({ chatType: 2, guildId: '', peerUid: GroupCode }, msgId, 1, false)
|
||||
let param = {
|
||||
groupCode: GroupCode,
|
||||
msgRandom: parseInt(MsgData?.msgList[0].msgRandom!),
|
||||
msgSeq: parseInt(MsgData?.msgList[0].msgSeq!)
|
||||
const data = await session?.getMsgService().getMsgsIncludeSelf({ chatType: 2, guildId: '', peerUid: groupCode }, msgId, 1, false)
|
||||
const param = {
|
||||
groupCode: groupCode,
|
||||
msgRandom: Number(data?.msgList[0].msgRandom),
|
||||
msgSeq: Number(data?.msgList[0].msgSeq)
|
||||
}
|
||||
// GetMsgByShoretID(ShoretID) -> MsgService.getMsgs(Peer,MsgId,1,false) -> 组出参数
|
||||
return session?.getGroupService().addGroupEssence(param)
|
||||
|
@ -102,62 +102,35 @@ export class NTQQMsgApi extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
async sendMsg(peer: Peer, msgElements: SendMessageElement[], waitComplete = true, timeout = 10000) {
|
||||
async sendMsg(peer: Peer, msgElements: SendMessageElement[], timeout = 10000) {
|
||||
const msgId = generateMsgId()
|
||||
peer.guildId = msgId
|
||||
let msgList: RawMessage[]
|
||||
if (NTEventDispatch.initialised) {
|
||||
const data = await NTEventDispatch.CallNormalEvent<
|
||||
(msgId: string, peer: Peer, msgElements: SendMessageElement[], map: Map<any, any>) => Promise<unknown>,
|
||||
(msgList: RawMessage[]) => void
|
||||
>(
|
||||
'NodeIKernelMsgService/sendMsg',
|
||||
'NodeIKernelMsgListener/onMsgInfoListUpdate',
|
||||
1,
|
||||
timeout,
|
||||
(msgRecords: RawMessage[]) => {
|
||||
for (const msgRecord of msgRecords) {
|
||||
const data = await invoke<{ msgList: RawMessage[] }>(
|
||||
'nodeIKernelMsgService/sendMsg',
|
||||
[
|
||||
{
|
||||
msgId: '0',
|
||||
peer,
|
||||
msgElements,
|
||||
msgAttributeInfos: new Map()
|
||||
},
|
||||
null
|
||||
],
|
||||
{
|
||||
cbCmd: 'nodeIKernelMsgListener/onMsgInfoListUpdate',
|
||||
afterFirstCmd: false,
|
||||
cmdCB: payload => {
|
||||
for (const msgRecord of payload.msgList) {
|
||||
if (msgRecord.guildId === msgId && msgRecord.sendStatus === 2) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
},
|
||||
'0',
|
||||
peer,
|
||||
msgElements,
|
||||
new Map()
|
||||
)
|
||||
msgList = data[1]
|
||||
} else {
|
||||
const data = await invoke<{ msgList: RawMessage[] }>(
|
||||
'nodeIKernelMsgService/sendMsg',
|
||||
[
|
||||
{
|
||||
msgId: '0',
|
||||
peer,
|
||||
msgElements,
|
||||
msgAttributeInfos: new Map()
|
||||
},
|
||||
null
|
||||
],
|
||||
{
|
||||
cbCmd: 'nodeIKernelMsgListener/onMsgInfoListUpdate',
|
||||
afterFirstCmd: false,
|
||||
cmdCB: payload => {
|
||||
for (const msgRecord of payload.msgList) {
|
||||
if (msgRecord.guildId === msgId && msgRecord.sendStatus === 2) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
},
|
||||
timeout
|
||||
}
|
||||
)
|
||||
msgList = data.msgList
|
||||
}
|
||||
return msgList.find(msgRecord => msgRecord.guildId === msgId)
|
||||
timeout
|
||||
}
|
||||
)
|
||||
return data.msgList.find(msgRecord => msgRecord.guildId === msgId)
|
||||
}
|
||||
|
||||
async forwardMsg(srcPeer: Peer, destPeer: Peer, msgIds: string[]) {
|
||||
@ -181,65 +154,37 @@ export class NTQQMsgApi extends Service {
|
||||
return { msgId: id, senderShowName }
|
||||
})
|
||||
const selfUid = selfInfo.uid
|
||||
let msgList: RawMessage[]
|
||||
if (NTEventDispatch.initialised) {
|
||||
const data = await NTEventDispatch.CallNormalEvent<
|
||||
(msgInfo: typeof msgInfos, srcPeer: Peer, destPeer: Peer, comment: Array<any>, attr: Map<any, any>,) => Promise<unknown>,
|
||||
(msgList: RawMessage[]) => void
|
||||
>(
|
||||
'NodeIKernelMsgService/multiForwardMsgWithComment',
|
||||
'NodeIKernelMsgListener/onMsgInfoListUpdate',
|
||||
1,
|
||||
5000,
|
||||
(msgRecords: RawMessage[]) => {
|
||||
for (let msgRecord of msgRecords) {
|
||||
const data = await invoke<{ msgList: RawMessage[] }>(
|
||||
'nodeIKernelMsgService/multiForwardMsgWithComment',
|
||||
[
|
||||
{
|
||||
msgInfos,
|
||||
srcContact: srcPeer,
|
||||
dstContact: destPeer,
|
||||
commentElements: [],
|
||||
msgAttributeInfos: new Map(),
|
||||
},
|
||||
null,
|
||||
],
|
||||
{
|
||||
cbCmd: 'nodeIKernelMsgListener/onMsgInfoListUpdate',
|
||||
afterFirstCmd: false,
|
||||
cmdCB: payload => {
|
||||
for (const msgRecord of payload.msgList) {
|
||||
if (msgRecord.peerUid == destPeer.peerUid && msgRecord.senderUid == selfUid) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
},
|
||||
msgInfos,
|
||||
srcPeer,
|
||||
destPeer,
|
||||
[],
|
||||
new Map()
|
||||
)
|
||||
msgList = data[1]
|
||||
} else {
|
||||
const data = await invoke<{ msgList: RawMessage[] }>(
|
||||
'nodeIKernelMsgService/multiForwardMsgWithComment',
|
||||
[
|
||||
{
|
||||
msgInfos,
|
||||
srcContact: srcPeer,
|
||||
dstContact: destPeer,
|
||||
commentElements: [],
|
||||
msgAttributeInfos: new Map(),
|
||||
},
|
||||
null,
|
||||
],
|
||||
{
|
||||
cbCmd: 'nodeIKernelMsgListener/onMsgInfoListUpdate',
|
||||
afterFirstCmd: false,
|
||||
cmdCB: payload => {
|
||||
for (const msgRecord of payload.msgList) {
|
||||
if (msgRecord.peerUid == destPeer.peerUid && msgRecord.senderUid == selfUid) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
},
|
||||
}
|
||||
)
|
||||
msgList = data.msgList
|
||||
}
|
||||
for (const msg of msgList) {
|
||||
}
|
||||
)
|
||||
for (const msg of data.msgList) {
|
||||
const arkElement = msg.elements.find(ele => ele.arkElement)
|
||||
if (!arkElement) {
|
||||
continue
|
||||
}
|
||||
const forwardData: any = JSON.parse(arkElement.arkElement.bytesData)
|
||||
const forwardData = JSON.parse(arkElement.arkElement.bytesData)
|
||||
if (forwardData.app != 'com.tencent.multimsg') {
|
||||
continue
|
||||
}
|
||||
|
@ -37,44 +37,24 @@ export class NTQQUserApi extends Service {
|
||||
}
|
||||
|
||||
async fetchUserDetailInfo(uid: string) {
|
||||
let info: UserDetailInfoListenerArg
|
||||
if (NTEventDispatch.initialised) {
|
||||
type EventService = NodeIKernelProfileService['fetchUserDetailInfo']
|
||||
type EventListener = NodeIKernelProfileListener['onUserDetailInfoChanged']
|
||||
const [_retData, profile] = await NTEventDispatch.CallNormalEvent
|
||||
<EventService, EventListener>
|
||||
(
|
||||
'NodeIKernelProfileService/fetchUserDetailInfo',
|
||||
'NodeIKernelProfileListener/onUserDetailInfoChanged',
|
||||
1,
|
||||
5000,
|
||||
(profile) => profile.uid === uid,
|
||||
'BuddyProfileStore',
|
||||
[uid],
|
||||
UserDetailSource.KSERVER,
|
||||
[ProfileBizType.KALL]
|
||||
)
|
||||
info = profile
|
||||
} else {
|
||||
const result = await invoke<{ info: UserDetailInfoListenerArg }>(
|
||||
'nodeIKernelProfileService/fetchUserDetailInfo',
|
||||
[
|
||||
{
|
||||
callFrom: 'BuddyProfileStore',
|
||||
uid: [uid],
|
||||
source: UserDetailSource.KSERVER,
|
||||
bizList: [ProfileBizType.KALL]
|
||||
},
|
||||
null
|
||||
],
|
||||
const result = await invoke<{ info: UserDetailInfoListenerArg }>(
|
||||
'nodeIKernelProfileService/fetchUserDetailInfo',
|
||||
[
|
||||
{
|
||||
cbCmd: 'nodeIKernelProfileListener/onUserDetailInfoChanged',
|
||||
afterFirstCmd: false,
|
||||
cmdCB: payload => payload.info.uid === uid,
|
||||
}
|
||||
)
|
||||
info = result.info
|
||||
}
|
||||
callFrom: 'BuddyProfileStore',
|
||||
uid: [uid],
|
||||
source: UserDetailSource.KSERVER,
|
||||
bizList: [ProfileBizType.KALL]
|
||||
},
|
||||
null
|
||||
],
|
||||
{
|
||||
cbCmd: 'nodeIKernelProfileListener/onUserDetailInfoChanged',
|
||||
afterFirstCmd: false,
|
||||
cmdCB: payload => payload.info.uid === uid,
|
||||
}
|
||||
)
|
||||
const { info } = result
|
||||
const ret: User = {
|
||||
...info.simpleInfo.coreInfo,
|
||||
...info.simpleInfo.status,
|
||||
@ -87,43 +67,26 @@ export class NTQQUserApi extends Service {
|
||||
return ret
|
||||
}
|
||||
|
||||
async getUserDetailInfo(uid: string, getLevel = false, withBizInfo = true) {
|
||||
async getUserDetailInfo(uid: string, _getLevel = false) {
|
||||
if (getBuildVersion() >= 26702) {
|
||||
return this.fetchUserDetailInfo(uid)
|
||||
}
|
||||
if (NTEventDispatch.initialised) {
|
||||
type EventService = NodeIKernelProfileService['getUserDetailInfoWithBizInfo']
|
||||
type EventListener = NodeIKernelProfileListener['onProfileDetailInfoChanged']
|
||||
const [_retData, profile] = await NTEventDispatch.CallNormalEvent
|
||||
<EventService, EventListener>
|
||||
(
|
||||
'NodeIKernelProfileService/getUserDetailInfoWithBizInfo',
|
||||
'NodeIKernelProfileListener/onProfileDetailInfoChanged',
|
||||
2,
|
||||
5000,
|
||||
(profile) => profile.uid === uid,
|
||||
uid,
|
||||
[0]
|
||||
)
|
||||
return profile
|
||||
} else {
|
||||
const result = await invoke<{ info: User }>(
|
||||
'nodeIKernelProfileService/getUserDetailInfoWithBizInfo',
|
||||
[
|
||||
{
|
||||
uid,
|
||||
bizList: [0]
|
||||
},
|
||||
null,
|
||||
],
|
||||
const result = await invoke<{ info: User }>(
|
||||
'nodeIKernelProfileService/getUserDetailInfoWithBizInfo',
|
||||
[
|
||||
{
|
||||
cbCmd: 'nodeIKernelProfileListener/onProfileDetailInfoChanged',
|
||||
afterFirstCmd: false,
|
||||
cmdCB: (payload) => payload.info.uid === uid,
|
||||
}
|
||||
)
|
||||
return result.info
|
||||
}
|
||||
uid,
|
||||
bizList: [0]
|
||||
},
|
||||
null,
|
||||
],
|
||||
{
|
||||
cbCmd: 'nodeIKernelProfileListener/onProfileDetailInfoChanged',
|
||||
afterFirstCmd: false,
|
||||
cmdCB: (payload) => payload.info.uid === uid,
|
||||
}
|
||||
)
|
||||
return result.info
|
||||
}
|
||||
|
||||
async getSkey(): Promise<string> {
|
||||
@ -244,40 +207,27 @@ export class NTQQUserApi extends Service {
|
||||
}
|
||||
|
||||
async getUserDetailInfoByUinV2(uin: string) {
|
||||
if (NTEventDispatch.initialised) {
|
||||
return await NTEventDispatch.CallNoListenerEvent
|
||||
<(Uin: string) => Promise<UserDetailInfoByUinV2>>(
|
||||
'NodeIKernelProfileService/getUserDetailInfoByUin',
|
||||
5000,
|
||||
uin
|
||||
)
|
||||
} else {
|
||||
return await invoke<UserDetailInfoByUinV2>(
|
||||
'nodeIKernelProfileService/getUserDetailInfoByUin',
|
||||
[
|
||||
{ uin },
|
||||
null,
|
||||
],
|
||||
)
|
||||
}
|
||||
return await invoke<UserDetailInfoByUinV2>(
|
||||
'nodeIKernelProfileService/getUserDetailInfoByUin',
|
||||
[
|
||||
{ uin },
|
||||
null,
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
async getUserDetailInfoByUin(uin: string) {
|
||||
return NTEventDispatch.CallNoListenerEvent
|
||||
<(Uin: string) => Promise<UserDetailInfoByUin>>(
|
||||
'NodeIKernelProfileService/getUserDetailInfoByUin',
|
||||
5000,
|
||||
uin
|
||||
)
|
||||
return await invoke<UserDetailInfoByUin>(
|
||||
'nodeIKernelProfileService/getUserDetailInfoByUin',
|
||||
[
|
||||
{ uin },
|
||||
null,
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
async getUinByUidV1(uid: string) {
|
||||
const ret = await NTEventDispatch.CallNoListenerEvent
|
||||
<(Uin: string[]) => Promise<{ uinInfo: Map<string, string> }>>(
|
||||
'NodeIKernelUixConvertService/getUin',
|
||||
5000,
|
||||
[uid]
|
||||
)
|
||||
const ret = await invoke('nodeIKernelUixConvertService/getUin', [{ uids: [uid] }])
|
||||
let uin = ret.uinInfo.get(uid)
|
||||
if (!uin) {
|
||||
uin = (await this.getUserDetailInfo(uid)).uin //从QQ Native 转换
|
||||
|
@ -2,8 +2,9 @@ import type { BrowserWindow } from 'electron'
|
||||
import { NTClass, NTMethod } from './ntcall'
|
||||
import { log } from '@/common/utils'
|
||||
import { randomUUID } from 'node:crypto'
|
||||
import { Dict } from 'cosmokit'
|
||||
|
||||
export const hookApiCallbacks: Record<string, (apiReturn: any) => void> = {}
|
||||
export const hookApiCallbacks: Record<string, (res: any) => void> = {}
|
||||
|
||||
export const ReceiveCmdS = {
|
||||
RECENT_CONTACT: 'nodeIKernelRecentContactListener/onRecentContactListChangedVer2',
|
||||
@ -30,7 +31,7 @@ export const ReceiveCmdS = {
|
||||
|
||||
export type ReceiveCmd = string
|
||||
|
||||
interface NTQQApiReturnData<Payload = unknown> extends Array<any> {
|
||||
interface NTQQApiReturnData extends Array<unknown> {
|
||||
0: {
|
||||
type: 'request'
|
||||
eventName: NTClass
|
||||
@ -39,7 +40,7 @@ interface NTQQApiReturnData<Payload = unknown> extends Array<any> {
|
||||
1: {
|
||||
cmdName: ReceiveCmd
|
||||
cmdType: 'event'
|
||||
payload: Payload
|
||||
payload: unknown
|
||||
}[]
|
||||
}
|
||||
|
||||
@ -67,16 +68,16 @@ export function hookNTQQApiReceive(window: BrowserWindow, onlyLog: boolean) {
|
||||
} catch { }
|
||||
if (!onlyLog) {
|
||||
if (args?.[1] instanceof Array) {
|
||||
for (const receiveData of args?.[1]) {
|
||||
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) => {
|
||||
new Promise(resolve => {
|
||||
try {
|
||||
hook.hookFunc(receiveData.payload)
|
||||
} catch (e: any) {
|
||||
log('hook error', ntQQApiMethodName, e.stack.toString())
|
||||
} catch (e) {
|
||||
log('hook error', ntQQApiMethodName, (e as Error).stack?.toString())
|
||||
}
|
||||
resolve(undefined)
|
||||
}).then()
|
||||
@ -88,8 +89,7 @@ export function hookNTQQApiReceive(window: BrowserWindow, onlyLog: boolean) {
|
||||
// log("hookApiCallback", hookApiCallbacks, args)
|
||||
const callbackId = args[0].callbackId
|
||||
if (hookApiCallbacks[callbackId]) {
|
||||
// log("callback found")
|
||||
new Promise((resolve, reject) => {
|
||||
new Promise(resolve => {
|
||||
hookApiCallbacks[callbackId](args[1])
|
||||
resolve(undefined)
|
||||
}).then()
|
||||
@ -104,7 +104,7 @@ export function hookNTQQApiReceive(window: BrowserWindow, onlyLog: boolean) {
|
||||
|
||||
export function hookNTQQApiCall(window: BrowserWindow, onlyLog: boolean) {
|
||||
// 监听调用NTQQApi
|
||||
let webContents = window.webContents as any
|
||||
const webContents = window.webContents as Dict
|
||||
const ipc_message_proxy = webContents._events['-ipc-message']?.[0] || webContents._events['-ipc-message']
|
||||
|
||||
const proxyIpcMsg = new Proxy(ipc_message_proxy, {
|
||||
@ -125,10 +125,10 @@ export function hookNTQQApiCall(window: BrowserWindow, onlyLog: boolean) {
|
||||
const callParams = _args.slice(1)
|
||||
callHooks.forEach((hook) => {
|
||||
if (hook.method.includes(cmdName)) {
|
||||
new Promise((resolve, reject) => {
|
||||
new Promise(resolve => {
|
||||
try {
|
||||
hook.hookFunc(callParams)
|
||||
} catch (e: any) {
|
||||
} catch (e) {
|
||||
log('hook call error', e, _args)
|
||||
}
|
||||
resolve(undefined)
|
||||
@ -150,14 +150,13 @@ export function hookNTQQApiCall(window: BrowserWindow, onlyLog: boolean) {
|
||||
const ipc_invoke_proxy = webContents._events['-ipc-invoke']?.[0] || webContents._events['-ipc-invoke']
|
||||
const proxyIpcInvoke = new Proxy(ipc_invoke_proxy, {
|
||||
apply(target, thisArg, args) {
|
||||
// console.log(args);
|
||||
//HOOK_LOG && log('call NTQQ invoke api', thisArg, args)
|
||||
args[0]['_replyChannel']['sendReply'] = new Proxy(args[0]['_replyChannel']['sendReply'], {
|
||||
apply(sendtarget, sendthisArg, sendargs) {
|
||||
sendtarget.apply(sendthisArg, sendargs)
|
||||
},
|
||||
})
|
||||
let ret = target.apply(thisArg, args)
|
||||
const ret = target.apply(thisArg, args)
|
||||
/*try {
|
||||
HOOK_LOG && log('call NTQQ invoke api return', ret)
|
||||
} catch (e) { }*/
|
||||
|
@ -352,7 +352,7 @@ export interface VideoElement {
|
||||
thumbHeight?: number
|
||||
busiType?: 0 // 未知
|
||||
subBusiType?: 0 // 未知
|
||||
thumbPath?: Map<number, any>
|
||||
thumbPath?: Map<number, string>
|
||||
transferStatus?: 0 // 未知
|
||||
progress?: 0 // 下载进度?
|
||||
invalidState?: 0 // 未知
|
||||
@ -523,22 +523,22 @@ export interface MessageElement {
|
||||
grayTipElement?: GrayTipElement
|
||||
arkElement?: ArkElement
|
||||
fileElement?: FileElement
|
||||
liveGiftElement?: null
|
||||
liveGiftElement?: unknown
|
||||
markdownElement?: MarkdownElement
|
||||
structLongMsgElement?: any
|
||||
structLongMsgElement?: unknown
|
||||
multiForwardMsgElement?: MultiForwardMsgElement
|
||||
giphyElement?: any
|
||||
walletElement?: null
|
||||
giphyElement?: unknown
|
||||
walletElement?: unknown
|
||||
inlineKeyboardElement?: InlineKeyboardElement
|
||||
textGiftElement?: null //????
|
||||
calendarElement?: any
|
||||
yoloGameResultElement?: any
|
||||
avRecordElement?: any
|
||||
structMsgElement?: null
|
||||
faceBubbleElement?: any
|
||||
shareLocationElement?: any
|
||||
tofuRecordElement?: any
|
||||
taskTopMsgElement?: any
|
||||
recommendedMsgElement?: any
|
||||
actionBarElement?: any
|
||||
textGiftElement?: unknown //????
|
||||
calendarElement?: unknown
|
||||
yoloGameResultElement?: unknown
|
||||
avRecordElement?: unknown
|
||||
structMsgElement?: unknown
|
||||
faceBubbleElement?: unknown
|
||||
shareLocationElement?: unknown
|
||||
tofuRecordElement?: unknown
|
||||
taskTopMsgElement?: unknown
|
||||
recommendedMsgElement?: unknown
|
||||
actionBarElement?: unknown
|
||||
}
|
@ -45,8 +45,6 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnData> {
|
||||
message: '音乐消息不可以和其他消息混在一起发送',
|
||||
}
|
||||
}
|
||||
if (payload.user_id && payload.message_type !== 'group') {
|
||||
}
|
||||
return {
|
||||
valid: true,
|
||||
}
|
||||
@ -67,9 +65,9 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnData> {
|
||||
if (this.getSpecialMsgNum(messages, OB11MessageDataType.node)) {
|
||||
try {
|
||||
const returnMsg = await this.handleForwardNode(peer, messages as OB11MessageNode[])
|
||||
return { message_id: returnMsg?.msgShortId! }
|
||||
} catch (e: any) {
|
||||
throw '发送转发消息失败 ' + e.toString()
|
||||
return { message_id: returnMsg.msgShortId! }
|
||||
} catch (e) {
|
||||
throw '发送转发消息失败 ' + e
|
||||
}
|
||||
}
|
||||
else if (this.getSpecialMsgNum(messages, OB11MessageDataType.music)) {
|
||||
@ -144,26 +142,20 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnData> {
|
||||
|
||||
private async cloneMsg(msg: RawMessage): Promise<RawMessage | undefined> {
|
||||
this.ctx.logger.info('克隆的目标消息', msg)
|
||||
let sendElements: SendMessageElement[] = []
|
||||
const sendElements: SendMessageElement[] = []
|
||||
for (const ele of msg.elements) {
|
||||
sendElements.push(ele as SendMessageElement)
|
||||
// Object.keys(ele).forEach((eleKey) => {
|
||||
// if (eleKey.endsWith("Element")) {
|
||||
// }
|
||||
}
|
||||
if (sendElements.length === 0) {
|
||||
this.ctx.logger.warn('需要clone的消息无法解析,将会忽略掉', msg)
|
||||
}
|
||||
this.ctx.logger.info('克隆消息', sendElements)
|
||||
try {
|
||||
const nodeMsg = await this.ctx.ntMsgApi.sendMsg(
|
||||
{
|
||||
chatType: ChatType.friend,
|
||||
peerUid: selfInfo.uid,
|
||||
},
|
||||
sendElements,
|
||||
true,
|
||||
)
|
||||
const peer = {
|
||||
chatType: ChatType.friend,
|
||||
peerUid: selfInfo.uid
|
||||
}
|
||||
const nodeMsg = await this.ctx.ntMsgApi.sendMsg(peer, sendElements)
|
||||
await this.ctx.sleep(400)
|
||||
return nodeMsg
|
||||
} catch (e) {
|
||||
@ -181,7 +173,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnData> {
|
||||
// 先判断一遍是不是id和自定义混用
|
||||
for (const messageNode of messageNodes) {
|
||||
// 一个node表示一个人的消息
|
||||
let nodeId = messageNode.data.id
|
||||
const nodeId = messageNode.data.id
|
||||
// 有nodeId表示一个子转发消息卡片
|
||||
if (nodeId) {
|
||||
const nodeMsg = await MessageUnique.getMsgIdAndPeerByShortId(+nodeId) || await MessageUnique.getPeerByMsgId(nodeId)
|
||||
@ -201,7 +193,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnData> {
|
||||
destPeer
|
||||
)
|
||||
this.ctx.logger.info('开始生成转发节点', sendElements)
|
||||
let sendElementsSplit: SendMessageElement[][] = []
|
||||
const sendElementsSplit: SendMessageElement[][] = []
|
||||
let splitIndex = 0
|
||||
for (const ele of sendElements) {
|
||||
if (!sendElementsSplit[splitIndex]) {
|
||||
|
@ -42,7 +42,7 @@ import { OB11GroupRecallNoticeEvent } from './event/notice/OB11GroupRecallNotice
|
||||
import { OB11FriendPokeEvent, OB11GroupPokeEvent } from './event/notice/OB11PokeEvent'
|
||||
import { OB11BaseNoticeEvent } from './event/notice/OB11BaseNoticeEvent'
|
||||
import { OB11GroupEssenceEvent } from './event/notice/OB11GroupEssenceEvent'
|
||||
import { omit, isNullable, pick } from 'cosmokit'
|
||||
import { omit, isNullable, pick, Dict } from 'cosmokit'
|
||||
import { Context } from 'cordis'
|
||||
import { selfInfo } from '@/common/globalVars'
|
||||
import { pathToFileURL } from 'node:url'
|
||||
@ -96,14 +96,14 @@ export namespace OB11Entities {
|
||||
const ret = await ctx.ntMsgApi.getTempChatInfo(ChatType2.KCHATTYPETEMPC2CFROMGROUP, msg.senderUid)
|
||||
if (ret?.result === 0) {
|
||||
resMsg.temp_source = Number(ret.tmpChatInfo?.groupCode)
|
||||
resMsg.sender.nickname = ret.tmpChatInfo?.fromNick!
|
||||
resMsg.sender.nickname = ret.tmpChatInfo!.fromNick
|
||||
} else {
|
||||
resMsg.temp_source = 284840486 //兜底数据
|
||||
resMsg.sender.nickname = '临时会话'
|
||||
}
|
||||
}
|
||||
|
||||
for (let element of msg.elements) {
|
||||
for (const element of msg.elements) {
|
||||
let messageSegment: OB11MessageData | undefined
|
||||
if (element.textElement && element.textElement?.atType !== AtType.notAt) {
|
||||
let qq: string
|
||||
@ -404,7 +404,7 @@ export namespace OB11Entities {
|
||||
return
|
||||
}
|
||||
if (msg.senderUin) {
|
||||
let member = await ctx.ntGroupApi.getGroupMember(msg.peerUid, msg.senderUin)
|
||||
const member = await ctx.ntGroupApi.getGroupMember(msg.peerUid, msg.senderUin)
|
||||
if (member && member.cardName !== msg.sendMemberName) {
|
||||
const event = new OB11GroupCardEvent(
|
||||
parseInt(msg.peerUid),
|
||||
@ -416,12 +416,10 @@ export namespace OB11Entities {
|
||||
return event
|
||||
}
|
||||
}
|
||||
// log("group msg", msg)
|
||||
for (let element of msg.elements) {
|
||||
for (const element of msg.elements) {
|
||||
const grayTipElement = element.grayTipElement
|
||||
const groupElement = grayTipElement?.groupElement
|
||||
if (groupElement) {
|
||||
// log("收到群提示消息", groupElement)
|
||||
if (groupElement.type === TipGroupElementType.memberIncrease) {
|
||||
ctx.logger.info('收到群成员增加消息', groupElement)
|
||||
await ctx.sleep(1000)
|
||||
@ -430,14 +428,10 @@ export namespace OB11Entities {
|
||||
if (!memberUin) {
|
||||
memberUin = (await ctx.ntUserApi.getUserDetailInfo(groupElement.memberUid)).uin
|
||||
}
|
||||
// log("获取新群成员QQ", memberUin)
|
||||
const adminMember = await ctx.ntGroupApi.getGroupMember(msg.peerUid, groupElement.adminUid)
|
||||
// log("获取同意新成员入群的管理员", adminMember)
|
||||
if (memberUin) {
|
||||
const operatorUin = adminMember?.uin || memberUin
|
||||
let event = new OB11GroupIncreaseEvent(parseInt(msg.peerUid), parseInt(memberUin), parseInt(operatorUin))
|
||||
// log("构造群增加事件", event)
|
||||
return event
|
||||
return new OB11GroupIncreaseEvent(parseInt(msg.peerUid), parseInt(memberUin), parseInt(operatorUin))
|
||||
}
|
||||
}
|
||||
else if (groupElement.type === TipGroupElementType.ban) {
|
||||
@ -445,8 +439,8 @@ export namespace OB11Entities {
|
||||
const memberUid = groupElement.shutUp?.member.uid
|
||||
const adminUid = groupElement.shutUp?.admin.uid
|
||||
let memberUin: string = ''
|
||||
let duration = parseInt(groupElement.shutUp?.duration!)
|
||||
let sub_type: 'ban' | 'lift_ban' = duration > 0 ? 'ban' : 'lift_ban'
|
||||
let duration = Number(groupElement.shutUp?.duration)
|
||||
const subType = duration > 0 ? 'ban' : 'lift_ban'
|
||||
if (memberUid) {
|
||||
memberUin =
|
||||
(await ctx.ntGroupApi.getGroupMember(msg.peerUid, memberUid))?.uin ||
|
||||
@ -466,7 +460,7 @@ export namespace OB11Entities {
|
||||
parseInt(memberUin),
|
||||
parseInt(adminUin),
|
||||
duration,
|
||||
sub_type,
|
||||
subType,
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -542,8 +536,8 @@ export namespace OB11Entities {
|
||||
count: 1,
|
||||
}]
|
||||
)
|
||||
} catch (e: any) {
|
||||
ctx.logger.error('解析表情回应消息失败', e.stack)
|
||||
} catch (e) {
|
||||
ctx.logger.error('解析表情回应消息失败', (e as Error).stack)
|
||||
}
|
||||
}
|
||||
|
||||
@ -597,7 +591,7 @@ export namespace OB11Entities {
|
||||
if (grayTipElement.jsonGrayTipElement.busiId == 1061) {
|
||||
//判断业务类型
|
||||
//Poke事件
|
||||
const pokedetail: any[] = json.items
|
||||
const pokedetail: Dict[] = json.items
|
||||
//筛选item带有uid的元素
|
||||
const poke_uid = pokedetail.filter(item => item.uid)
|
||||
if (poke_uid.length == 2) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { CheckVersion, Config } from '../common/types'
|
||||
import { SettingButton, SettingItem, SettingList, SettingSwitch, SettingSelect } from './components'
|
||||
import { version } from '../version'
|
||||
// @ts-ignore
|
||||
// @ts-expect-error
|
||||
import StyleRaw from './style.css?raw'
|
||||
|
||||
type HostsType = 'httpHosts' | 'wsHosts'
|
||||
@ -15,7 +15,7 @@ async function onSettingWindowCreated(view: Element) {
|
||||
const config = await window.llonebot.getConfig()
|
||||
const ob11Config = { ...config.ob11 }
|
||||
|
||||
const setConfig = (key: string, value: any) => {
|
||||
const setConfig = (key: string, value: unknown) => {
|
||||
const configKey = key.split('.')
|
||||
if (key.startsWith('ob11')) {
|
||||
if (configKey.length === 2) Object.assign(ob11Config, { [configKey[1]]: value })
|
||||
@ -87,9 +87,8 @@ async function onSettingWindowCreated(view: Element) {
|
||||
<setting-text>HTTP 事件上报密钥</setting-text>
|
||||
</div>
|
||||
<div class="q-input">
|
||||
<input id="config-ob11-httpSecret" class="q-input__inner" data-config-key="ob11.httpSecret" type="text" value="${
|
||||
config.ob11.httpSecret
|
||||
}" placeholder="未设置" />
|
||||
<input id="config-ob11-httpSecret" class="q-input__inner" data-config-key="ob11.httpSecret" type="text" value="${config.ob11.httpSecret
|
||||
}" placeholder="未设置" />
|
||||
</div>
|
||||
</setting-item>
|
||||
<setting-item data-direction="row">
|
||||
@ -152,8 +151,7 @@ async function onSettingWindowCreated(view: Element) {
|
||||
),
|
||||
SettingItem(
|
||||
'FFmpeg 路径,发送语音、视频需要',
|
||||
`<a href="javascript:LiteLoader.api.openExternal(\'https://llonebot.github.io/zh-CN/guide/ffmpeg\');">可点此下载</a>, 路径: <span id="config-ffmpeg-path-text">${
|
||||
!isEmpty(config.ffmpeg) ? config.ffmpeg : '未指定'
|
||||
`<a href="javascript:LiteLoader.api.openExternal(\'https://llonebot.github.io/zh-CN/guide/ffmpeg\');">可点此下载</a>, 路径: <span id="config-ffmpeg-path-text">${!isEmpty(config.ffmpeg) ? config.ffmpeg : '未指定'
|
||||
}</span>, 需保证 FFprobe 和 FFmpeg 在一起`,
|
||||
SettingButton('选择 FFmpeg', 'config-ffmpeg-select'),
|
||||
),
|
||||
@ -254,7 +252,7 @@ async function onSettingWindowCreated(view: Element) {
|
||||
window.LiteLoader.api.openExternal('https://llonebot.github.io/')
|
||||
})
|
||||
// 生成反向地址列表
|
||||
const buildHostListItem = (type: HostsType, host: string, index: number, inputAttrs: any = {}) => {
|
||||
const buildHostListItem = (type: HostsType, host: string, index: number, inputAttrs = {}) => {
|
||||
const dom = {
|
||||
container: document.createElement('setting-item'),
|
||||
input: document.createElement('input'),
|
||||
@ -286,7 +284,7 @@ async function onSettingWindowCreated(view: Element) {
|
||||
|
||||
return dom.container
|
||||
}
|
||||
const buildHostList = (hosts: string[], type: HostsType, inputAttr: any = {}) => {
|
||||
const buildHostList = (hosts: string[], type: HostsType, inputAttr = {}) => {
|
||||
const result: HTMLElement[] = []
|
||||
|
||||
hosts.forEach((host, index) => {
|
||||
@ -295,14 +293,15 @@ async function onSettingWindowCreated(view: Element) {
|
||||
|
||||
return result
|
||||
}
|
||||
const addReverseHost = (type: HostsType, doc: Document = document, inputAttr: any = {}) => {
|
||||
const addReverseHost = (type: HostsType, doc: Document = document, inputAttr = {}) => {
|
||||
const hostContainerDom = doc.body.querySelector(`#config-ob11-${type}-list`)
|
||||
hostContainerDom?.appendChild(buildHostListItem(type, '', ob11Config[type].length, inputAttr))
|
||||
ob11Config[type].push('')
|
||||
}
|
||||
const initReverseHost = (type: HostsType, doc: Document = document) => {
|
||||
const hostContainerDom = doc.body.querySelector(`#config-ob11-${type}-list`)
|
||||
;[...hostContainerDom?.childNodes!].forEach((dom) => dom.remove())
|
||||
const hostContainerDom = doc.body.querySelector(`#config-ob11-${type}-list`)!
|
||||
const nodes = [...hostContainerDom.childNodes]
|
||||
nodes.forEach((dom) => dom.remove())
|
||||
buildHostList(ob11Config[type], type).forEach((dom) => {
|
||||
hostContainerDom?.appendChild(dom)
|
||||
})
|
||||
@ -427,14 +426,14 @@ async function onSettingWindowCreated(view: Element) {
|
||||
}
|
||||
}
|
||||
window.llonebot.checkVersion().then(checkVersionFunc)
|
||||
window.addEventListener('beforeunload', (event) => {
|
||||
window.addEventListener('beforeunload', () => {
|
||||
if (JSON.stringify(ob11Config) === JSON.stringify(config.ob11)) return
|
||||
config.ob11 = ob11Config
|
||||
window.llonebot.setConfig(true, config)
|
||||
})
|
||||
}
|
||||
|
||||
function init() {
|
||||
/**function init() {
|
||||
const hash = location.hash
|
||||
if (hash === '#/blank') {
|
||||
}
|
||||
@ -444,6 +443,6 @@ if (location.hash === '#/blank') {
|
||||
globalThis.navigation?.addEventListener('navigatesuccess', init, { once: true })
|
||||
} else {
|
||||
init()
|
||||
}
|
||||
}*/
|
||||
|
||||
export { onSettingWindowCreated }
|
||||
|
Loading…
x
Reference in New Issue
Block a user