fix: group member role change not sync group member list

This commit is contained in:
linyuchen 2024-03-04 22:58:25 +08:00
parent 15fe2837dc
commit 8417450c3c
2 changed files with 27 additions and 16 deletions

View File

@ -16,11 +16,11 @@ export const selfInfo: SelfInfo = {
nick: '',
online: true
}
export const groups: Group[] = []
export const friends: Friend[] = []
export const msgHistory: Record<string, RawMessage> = {} // msgId: RawMessage
export const groupNotifies: Map<string, GroupNotify> = new Map<string, GroupNotify>()
export const friendRequests: Map<number, FriendRequest> = new Map<number, FriendRequest>()
export let groups: Group[] = []
export let friends: Friend[] = []
export let msgHistory: Record<string, RawMessage> = {} // msgId: RawMessage
export let groupNotifies: Map<string, GroupNotify> = new Map<string, GroupNotify>()
export let friendRequests: Map<number, FriendRequest> = new Map<number, FriendRequest>()
export const llonebotError: LLOneBotError = {
ffmpegError: '',
otherError: ''
@ -47,20 +47,20 @@ export function getHistoryMsgByShortId(shortId: number | string) {
}
export async function getFriend(qq: string): Promise<Friend | undefined> {
const friend = friends.find(friend => friend.uin === qq)
// if (!friend){
// friends = (await NTQQApi.getFriends(true))
// friend = friends.find(friend => friend.uin === qq)
// }
let friend = friends.find(friend => friend.uin === qq)
if (!friend){
friends = (await NTQQApi.getFriends(true))
friend = friends.find(friend => friend.uin === qq)
}
return friend
}
export async function getGroup(qq: string): Promise<Group | undefined> {
const group = groups.find(group => group.groupCode === qq)
// if (!group){
// groups = await NTQQApi.getGroups(true);
// group = groups.find(group => group.groupCode === qq)
// }
let group = groups.find(group => group.groupCode === qq)
if (!group){
groups = await NTQQApi.getGroups(true);
group = groups.find(group => group.groupCode === qq)
}
return group
}
@ -89,6 +89,13 @@ export async function getGroupMember(groupQQ: string | number, memberQQ: string
}
}
export async function refreshGroupMembers(groupQQ: string) {
const group = groups.find(group => group.groupCode === groupQQ)
if (group) {
group.members = await NTQQApi.getGroupMembers(groupQQ)
}
}
export function getHistoryMsgBySeq(seq: string) {
return Object.values(msgHistory).find(msg => msg.msgSeq === seq)
}

View File

@ -19,7 +19,7 @@ import {
getGroupMember,
groupNotifies,
llonebotError,
msgHistory,
msgHistory, refreshGroupMembers,
selfInfo
} from "../common/data";
import {hookNTQQApiCall, hookNTQQApiReceive, ReceiveCmd, registerReceiveHook} from "../ntqqapi/hook";
@ -262,6 +262,7 @@ function onLoad() {
log("收到群通知", notify);
groupNotifies[notify.seq] = notify;
const member1 = await getGroupMember(notify.group.groupCode, null, notify.user1.uid);
refreshGroupMembers(notify.group.groupCode).then()
let member2: GroupMember;
if (notify.user2.uid) {
member2 = await getGroupMember(notify.group.groupCode, null, notify.user2.uid);
@ -312,6 +313,9 @@ function onLoad() {
log("解析群通知失败", e.stack);
}
}
else if (payload.doubt){
// 可能有群管理员变动
}
})
registerReceiveHook<FriendRequestNotify>(ReceiveCmd.FRIEND_REQUEST, async (payload) => {