fix: get group list

fix: 兼容 cc
This commit is contained in:
linyuchen
2024-03-24 11:57:02 +08:00
parent 94c928905e
commit 6542f2e63b
6 changed files with 41 additions and 14 deletions

View File

@@ -18,7 +18,7 @@ import {
friendRequests,
getFriend,
getGroup,
getGroupMember,
getGroupMember, groups,
llonebotError,
refreshGroupMembers,
selfInfo, uidMaps
@@ -364,7 +364,13 @@ function onLoad() {
}
})
startReceiveHook().then();
NTQQGroupApi.getGroups(true).then()
// NTQQGroupApi.getGroups(true).then(_groups => {
// _groups.map(group => {
// if (!groups.find(g => g.groupCode == group.groupCode)) {
// groups.push(group)
// }
// })
// })
const config = getConfigUtil().getConfig()
if (config.ob11.enableHttp) {
ob11HTTPServer.start(config.ob11.httpPort)
@@ -413,6 +419,7 @@ function onLoad() {
return setTimeout(getUserNick, 1000);
}
}
getUserNick().then()
start().then();
} else {

View File

@@ -10,7 +10,7 @@ export class NTQQGroupApi{
static async getGroups(forced = false) {
let cbCmd = ReceiveCmdS.GROUPS
if (process.platform != "win32") {
cbCmd = ReceiveCmdS.GROUPS_UNIX
cbCmd = ReceiveCmdS.GROUPS_STORE
}
const result = await callNTQQApi<{
updateType: number,

View File

@@ -25,7 +25,7 @@ export let ReceiveCmdS = {
USER_INFO: "nodeIKernelProfileListener/onProfileSimpleChanged",
USER_DETAIL_INFO: "nodeIKernelProfileListener/onProfileDetailInfoChanged",
GROUPS: "nodeIKernelGroupListener/onGroupListUpdate",
GROUPS_UNIX: "onGroupListUpdate",
GROUPS_STORE: "onGroupListUpdate",
GROUP_MEMBER_INFO_UPDATE: "nodeIKernelGroupListener/onMemberInfoChange",
FRIENDS: "onBuddyListChange",
MEDIA_DOWNLOAD_COMPLETE: "nodeIKernelMsgListener/onRichMediaDownloadComplete",
@@ -229,7 +229,6 @@ async function processGroupEvent(payload: {groupList: Group[]}) {
for (const group of newGroupList) {
let existGroup = groups.find(g => g.groupCode == group.groupCode);
if (existGroup) {
if (existGroup.memberCount > group.memberCount) {
log(`群(${group.groupCode})成员数量减少${existGroup.memberCount} -> ${group.memberCount}`);
const oldMembers = existGroup.members;
@@ -263,13 +262,23 @@ async function processGroupEvent(payload: {groupList: Group[]}) {
}
// 群列表变动
registerReceiveHook<{ groupList: Group[], updateType: number }>(process.platform == "win32" ? ReceiveCmdS.GROUPS : ReceiveCmdS.GROUPS_UNIX, (payload) => {
log("群列表变动", payload)
registerReceiveHook<{ groupList: Group[], updateType: number }>(ReceiveCmdS.GROUPS, (payload) => {
if (payload.updateType != 2) {
updateGroups(payload.groupList).then();
} else {
if (process.platform == "win32") {
processGroupEvent(payload).then();
}
}
})
registerReceiveHook<{ groupList: Group[], updateType: number }>(ReceiveCmdS.GROUPS_STORE, (payload) => {
if (payload.updateType != 2) {
updateGroups(payload.groupList).then();
} else {
if (process.platform != "win32") {
processGroupEvent(payload).then();
}
}
})
registerReceiveHook<{groupCode: string, dataSource: number, members: Set<GroupMember>}>(ReceiveCmdS.GROUP_MEMBER_INFO_UPDATE, (payload) => {

View File

@@ -162,7 +162,12 @@ export function callNTQQApi<ReturnType>(params: NTQQApiParams) {
ipcMain.emit(
channel,
{},
{
sender: {
send: (..._args: unknown[]) => {
},
},
},
{type: 'request', callbackId: uuid, eventName},
apiArgs
)

View File

@@ -3,12 +3,18 @@ import {OB11Constructor} from "../../constructor";
import {groups} from "../../../common/data";
import BaseAction from "../BaseAction";
import {ActionName} from "../types";
import {NTQQGroupApi} from "../../../ntqqapi/api";
import {log} from "../../../common/utils";
class GetGroupList extends BaseAction<null, OB11Group[]> {
actionName = ActionName.GetGroupList
protected async _handle(payload: null) {
// if (groups.length === 0) {
// const groups = await NTQQGroupApi.getGroups(true)
// log("get groups", groups)
// }
return OB11Constructor.groups(groups);
}
}

View File

@@ -150,7 +150,7 @@ async function onSettingWindowCreated(view: Element) {
),
SettingItem(
'日志文件目录',
`${window.LiteLoader.plugins['LLOneBot'].path.data}`,
`${window.LiteLoader.plugins['LLOneBot'].path.data}/logs`,
SettingButton('打开', 'config-open-log-path'),
),
]),