mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
fix: adaptation 27187
This commit is contained in:
parent
b16bea9548
commit
235a986253
@ -28,6 +28,7 @@ import { OnRichMediaDownloadCompleteParams } from '@/ntqqapi/listeners'
|
|||||||
import { Time } from 'cosmokit'
|
import { Time } from 'cosmokit'
|
||||||
|
|
||||||
export class NTQQFileApi {
|
export class NTQQFileApi {
|
||||||
|
/** 27187 TODO */
|
||||||
static async getVideoUrl(peer: Peer, msgId: string, elementId: string) {
|
static async getVideoUrl(peer: Peer, msgId: string, elementId: string) {
|
||||||
const session = getSession()
|
const session = getSession()
|
||||||
return (await session?.getRichMediaService().getVideoPlayUrlV2(peer,
|
return (await session?.getRichMediaService().getVideoPlayUrlV2(peer,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { ReceiveCmdS } from '../hook'
|
import { ReceiveCmdS } from '../hook'
|
||||||
import { Group, GroupMember, GroupMemberRole, GroupNotifies, GroupRequestOperateTypes, GroupNotify } from '../types'
|
import { Group, GroupMember, GroupMemberRole, GroupNotifies, GroupRequestOperateTypes, GroupNotify } from '../types'
|
||||||
import { invoke, NTMethod } from '../ntcall'
|
import { invoke, NTClass, NTMethod } from '../ntcall'
|
||||||
import { GeneralCallResult } from '../services'
|
import { GeneralCallResult } from '../services'
|
||||||
import { NTQQWindowApi, NTQQWindows } from './window'
|
import { NTQQWindowApi, NTQQWindows } from './window'
|
||||||
import { getSession } from '../wrapper'
|
import { getSession } from '../wrapper'
|
||||||
@ -10,6 +10,7 @@ import { NodeIKernelGroupService } from '../services'
|
|||||||
|
|
||||||
export class NTQQGroupApi {
|
export class NTQQGroupApi {
|
||||||
static async getGroups(forced = false): Promise<Group[]> {
|
static async getGroups(forced = false): Promise<Group[]> {
|
||||||
|
if (NTEventDispatch.initialised) {
|
||||||
type ListenerType = NodeIKernelGroupListener['onGroupListUpdate']
|
type ListenerType = NodeIKernelGroupListener['onGroupListUpdate']
|
||||||
const [, , groupList] = await NTEventDispatch.CallNormalEvent
|
const [, , groupList] = await NTEventDispatch.CallNormalEvent
|
||||||
<(force: boolean) => Promise<any>, ListenerType>
|
<(force: boolean) => Promise<any>, ListenerType>
|
||||||
@ -22,6 +23,18 @@ export class NTQQGroupApi {
|
|||||||
forced
|
forced
|
||||||
)
|
)
|
||||||
return groupList
|
return groupList
|
||||||
|
} else {
|
||||||
|
const result = await invoke<{
|
||||||
|
updateType: number
|
||||||
|
groupList: Group[]
|
||||||
|
}>({
|
||||||
|
className: NTClass.NODE_STORE_API,
|
||||||
|
methodName: 'getGroupList',
|
||||||
|
cbCmd: ReceiveCmdS.GROUPS_STORE,
|
||||||
|
afterFirstCmd: false,
|
||||||
|
})
|
||||||
|
return result.groupList
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getGroupMembers(groupQQ: string, num = 3000): Promise<Map<string, GroupMember>> {
|
static async getGroupMembers(groupQQ: string, num = 3000): Promise<Map<string, GroupMember>> {
|
||||||
@ -60,23 +73,8 @@ export class NTQQGroupApi {
|
|||||||
return result.result.infos
|
return result.result.infos
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getGroupNotifies() {
|
|
||||||
// 获取管理员变更
|
|
||||||
// 加群通知,退出通知,需要管理员权限
|
|
||||||
invoke<GeneralCallResult>({
|
|
||||||
methodName: ReceiveCmdS.GROUP_NOTIFY,
|
|
||||||
classNameIsRegister: true,
|
|
||||||
}).then()
|
|
||||||
return await invoke<GroupNotifies>({
|
|
||||||
methodName: NTMethod.GET_GROUP_NOTICE,
|
|
||||||
cbCmd: ReceiveCmdS.GROUP_NOTIFY,
|
|
||||||
afterFirstCmd: false,
|
|
||||||
args: [{ doubt: false, startSeq: '', number: 14 }, null],
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
static async getGroupIgnoreNotifies() {
|
static async getGroupIgnoreNotifies() {
|
||||||
await NTQQGroupApi.getGroupNotifies()
|
await NTQQGroupApi.getSingleScreenNotifies(14)
|
||||||
return await NTQQWindowApi.openWindow<GeneralCallResult & GroupNotifies>(
|
return await NTQQWindowApi.openWindow<GeneralCallResult & GroupNotifies>(
|
||||||
NTQQWindows.GroupNotifyFilterWindow,
|
NTQQWindows.GroupNotifyFilterWindow,
|
||||||
[],
|
[],
|
||||||
@ -85,6 +83,7 @@ export class NTQQGroupApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async getSingleScreenNotifies(num: number) {
|
static async getSingleScreenNotifies(num: number) {
|
||||||
|
if (NTEventDispatch.initialised) {
|
||||||
const [_retData, _doubt, _seq, notifies] = await NTEventDispatch.CallNormalEvent
|
const [_retData, _doubt, _seq, notifies] = await NTEventDispatch.CallNormalEvent
|
||||||
<(arg1: boolean, arg2: string, arg3: number) => Promise<any>, (doubt: boolean, seq: string, notifies: GroupNotify[]) => void>
|
<(arg1: boolean, arg2: string, arg3: number) => Promise<any>, (doubt: boolean, seq: string, notifies: GroupNotify[]) => void>
|
||||||
(
|
(
|
||||||
@ -98,22 +97,30 @@ export class NTQQGroupApi {
|
|||||||
num,
|
num,
|
||||||
)
|
)
|
||||||
return notifies
|
return notifies
|
||||||
|
} else {
|
||||||
|
return await invoke<GroupNotifies>({
|
||||||
|
methodName: NTMethod.GET_GROUP_NOTICE,
|
||||||
|
cbCmd: ReceiveCmdS.GROUP_NOTIFY,
|
||||||
|
afterFirstCmd: false,
|
||||||
|
args: [{ doubt: false, startSeq: '', number: num }, null],
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 27187 TODO */
|
||||||
static async delGroupFile(groupCode: string, files: string[]) {
|
static async delGroupFile(groupCode: string, files: string[]) {
|
||||||
const session = getSession()
|
const session = getSession()
|
||||||
return session?.getRichMediaService().deleteGroupFile(groupCode, [102], files)!
|
return session?.getRichMediaService().deleteGroupFile(groupCode, [102], files)!
|
||||||
}
|
}
|
||||||
|
|
||||||
static DelGroupFile = NTQQGroupApi.delGroupFile
|
|
||||||
|
|
||||||
static async handleGroupRequest(flag: string, operateType: GroupRequestOperateTypes, reason?: string) {
|
static async handleGroupRequest(flag: string, operateType: GroupRequestOperateTypes, reason?: string) {
|
||||||
const flagitem = flag.split('|')
|
const flagitem = flag.split('|')
|
||||||
const groupCode = flagitem[0]
|
const groupCode = flagitem[0]
|
||||||
const seq = flagitem[1]
|
const seq = flagitem[1]
|
||||||
const type = parseInt(flagitem[2])
|
const type = parseInt(flagitem[2])
|
||||||
const session = getSession()
|
const session = getSession()
|
||||||
return session?.getGroupService().operateSysNotify(
|
if (session) {
|
||||||
|
return session.getGroupService().operateSysNotify(
|
||||||
false,
|
false,
|
||||||
{
|
{
|
||||||
'operateType': operateType, // 2 拒绝
|
'operateType': operateType, // 2 拒绝
|
||||||
@ -124,11 +131,38 @@ export class NTQQGroupApi {
|
|||||||
'postscript': reason || ' ' // 仅传空值可能导致处理失败,故默认给个空格
|
'postscript': reason || ' ' // 仅传空值可能导致处理失败,故默认给个空格
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
return await invoke({
|
||||||
|
methodName: NTMethod.HANDLE_GROUP_REQUEST,
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
doubt: false,
|
||||||
|
operateMsg: {
|
||||||
|
operateType,
|
||||||
|
targetMsg: {
|
||||||
|
seq,
|
||||||
|
type,
|
||||||
|
groupCode,
|
||||||
|
postscript: reason || ' ' // 仅传空值可能导致处理失败,故默认给个空格
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
],
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async quitGroup(groupQQ: string) {
|
static async quitGroup(groupQQ: string) {
|
||||||
const session = getSession()
|
const session = getSession()
|
||||||
return session?.getGroupService().quitGroup(groupQQ)
|
if (session) {
|
||||||
|
return session.getGroupService().quitGroup(groupQQ)
|
||||||
|
} else {
|
||||||
|
return await invoke({
|
||||||
|
methodName: NTMethod.QUIT_GROUP,
|
||||||
|
args: [{ groupCode: groupQQ }, null],
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async kickMember(
|
static async kickMember(
|
||||||
@ -138,33 +172,113 @@ export class NTQQGroupApi {
|
|||||||
kickReason = '',
|
kickReason = '',
|
||||||
) {
|
) {
|
||||||
const session = getSession()
|
const session = getSession()
|
||||||
return session?.getGroupService().kickMember(groupQQ, kickUids, refuseForever, kickReason)
|
if (session) {
|
||||||
|
return session.getGroupService().kickMember(groupQQ, kickUids, refuseForever, kickReason)
|
||||||
|
} else {
|
||||||
|
return await invoke({
|
||||||
|
methodName: NTMethod.KICK_MEMBER,
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
groupCode: groupQQ,
|
||||||
|
kickUids,
|
||||||
|
refuseForever,
|
||||||
|
kickReason,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async banMember(groupQQ: string, memList: Array<{ uid: string, timeStamp: number }>) {
|
static async banMember(groupQQ: string, memList: Array<{ uid: string, timeStamp: number }>) {
|
||||||
// timeStamp为秒数, 0为解除禁言
|
// timeStamp为秒数, 0为解除禁言
|
||||||
const session = getSession()
|
const session = getSession()
|
||||||
return session?.getGroupService().setMemberShutUp(groupQQ, memList)
|
if (session) {
|
||||||
|
return session.getGroupService().setMemberShutUp(groupQQ, memList)
|
||||||
|
} else {
|
||||||
|
return await invoke({
|
||||||
|
methodName: NTMethod.MUTE_MEMBER,
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
groupCode: groupQQ,
|
||||||
|
memList,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async banGroup(groupQQ: string, shutUp: boolean) {
|
static async banGroup(groupQQ: string, shutUp: boolean) {
|
||||||
const session = getSession()
|
const session = getSession()
|
||||||
return session?.getGroupService().setGroupShutUp(groupQQ, shutUp)
|
if (session) {
|
||||||
|
return session.getGroupService().setGroupShutUp(groupQQ, shutUp)
|
||||||
|
} else {
|
||||||
|
return await invoke({
|
||||||
|
methodName: NTMethod.MUTE_GROUP,
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
groupCode: groupQQ,
|
||||||
|
shutUp,
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
],
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async setMemberCard(groupQQ: string, memberUid: string, cardName: string) {
|
static async setMemberCard(groupQQ: string, memberUid: string, cardName: string) {
|
||||||
const session = getSession()
|
const session = getSession()
|
||||||
return session?.getGroupService().modifyMemberCardName(groupQQ, memberUid, cardName)
|
if (session) {
|
||||||
|
return session.getGroupService().modifyMemberCardName(groupQQ, memberUid, cardName)
|
||||||
|
} else {
|
||||||
|
return await invoke({
|
||||||
|
methodName: NTMethod.SET_MEMBER_CARD,
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
groupCode: groupQQ,
|
||||||
|
uid: memberUid,
|
||||||
|
cardName,
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
],
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async setMemberRole(groupQQ: string, memberUid: string, role: GroupMemberRole) {
|
static async setMemberRole(groupQQ: string, memberUid: string, role: GroupMemberRole) {
|
||||||
const session = getSession()
|
const session = getSession()
|
||||||
return session?.getGroupService().modifyMemberRole(groupQQ, memberUid, role)
|
if (session) {
|
||||||
|
return session.getGroupService().modifyMemberRole(groupQQ, memberUid, role)
|
||||||
|
} else {
|
||||||
|
return await invoke({
|
||||||
|
methodName: NTMethod.SET_MEMBER_ROLE,
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
groupCode: groupQQ,
|
||||||
|
uid: memberUid,
|
||||||
|
role,
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
],
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async setGroupName(groupQQ: string, groupName: string) {
|
static async setGroupName(groupQQ: string, groupName: string) {
|
||||||
const session = getSession()
|
const session = getSession()
|
||||||
return session?.getGroupService().modifyGroupName(groupQQ, groupName, false)
|
if (session) {
|
||||||
|
return session.getGroupService().modifyGroupName(groupQQ, groupName, false)
|
||||||
|
} else {
|
||||||
|
return await invoke({
|
||||||
|
methodName: NTMethod.SET_GROUP_NAME,
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
groupCode: groupQQ,
|
||||||
|
groupName,
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
],
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getGroupAtAllRemainCount(groupCode: string) {
|
static async getGroupAtAllRemainCount(groupCode: string) {
|
||||||
@ -189,6 +303,7 @@ export class NTQQGroupApi {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 27187 TODO */
|
||||||
static async removeGroupEssence(GroupCode: string, msgId: string) {
|
static async removeGroupEssence(GroupCode: string, msgId: string) {
|
||||||
const session = getSession()
|
const session = getSession()
|
||||||
// 代码没测过
|
// 代码没测过
|
||||||
@ -203,6 +318,7 @@ export class NTQQGroupApi {
|
|||||||
return session?.getGroupService().removeGroupEssence(param)
|
return session?.getGroupService().removeGroupEssence(param)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 27187 TODO */
|
||||||
static async addGroupEssence(GroupCode: string, msgId: string) {
|
static async addGroupEssence(GroupCode: string, msgId: string) {
|
||||||
const session = getSession()
|
const session = getSession()
|
||||||
// 代码没测过
|
// 代码没测过
|
||||||
|
@ -118,12 +118,15 @@ export function invoke<ReturnType>(params: InvokeParams<ReturnType>) {
|
|||||||
}
|
}
|
||||||
const apiArgs = [params.methodName, ...(params.args ?? [])]
|
const apiArgs = [params.methodName, ...(params.args ?? [])]
|
||||||
//log('callNTQQApi', channel, eventName, apiArgs, uuid)
|
//log('callNTQQApi', channel, eventName, apiArgs, uuid)
|
||||||
return new Promise((resolve: (data: ReturnType) => void, reject) => {
|
return Promise.race([
|
||||||
let success = false
|
new Promise<ReturnType>((_, reject) => setTimeout(() => {
|
||||||
|
log(`ntqq api timeout ${channel}, ${eventName}, ${params.methodName}`, apiArgs)
|
||||||
|
reject(`ntqq api timeout ${channel}, ${eventName}, ${params.methodName}, ${apiArgs}`)
|
||||||
|
}, timeout)),
|
||||||
|
new Promise<ReturnType>((resolve: (data: ReturnType) => void, reject) => {
|
||||||
if (!params.cbCmd) {
|
if (!params.cbCmd) {
|
||||||
// QQ后端会返回结果,并且可以根据uuid识别
|
// QQ后端会返回结果,并且可以根据uuid识别
|
||||||
hookApiCallbacks[uuid] = (r: ReturnType) => {
|
hookApiCallbacks[uuid] = (r: ReturnType) => {
|
||||||
success = true
|
|
||||||
resolve(r)
|
resolve(r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -135,13 +138,11 @@ export function invoke<ReturnType>(params: InvokeParams<ReturnType>) {
|
|||||||
if (!!params.cmdCB) {
|
if (!!params.cmdCB) {
|
||||||
if (params.cmdCB(payload)) {
|
if (params.cmdCB(payload)) {
|
||||||
removeReceiveHook(hookId)
|
removeReceiveHook(hookId)
|
||||||
success = true
|
|
||||||
resolve(payload)
|
resolve(payload)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
removeReceiveHook(hookId)
|
removeReceiveHook(hookId)
|
||||||
success = true
|
|
||||||
resolve(payload)
|
resolve(payload)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -153,18 +154,10 @@ export function invoke<ReturnType>(params: InvokeParams<ReturnType>) {
|
|||||||
afterFirstCmd && secondCallback()
|
afterFirstCmd && secondCallback()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
success = true
|
|
||||||
reject(`ntqq api call failed, ${result.errMsg}`)
|
reject(`ntqq api call failed, ${result.errMsg}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setTimeout(() => {
|
|
||||||
if (!success) {
|
|
||||||
log(`ntqq api timeout ${channel}, ${eventName}, ${params.methodName}`, apiArgs)
|
|
||||||
reject(`ntqq api timeout ${channel}, ${eventName}, ${params.methodName}, ${apiArgs}`)
|
|
||||||
}
|
|
||||||
}, timeout)
|
|
||||||
|
|
||||||
ipcMain.emit(
|
ipcMain.emit(
|
||||||
channel,
|
channel,
|
||||||
{
|
{
|
||||||
@ -177,4 +170,5 @@ export function invoke<ReturnType>(params: InvokeParams<ReturnType>) {
|
|||||||
apiArgs,
|
apiArgs,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
])
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user