mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
chore: clean code for group.ts
This commit is contained in:
parent
03c056702c
commit
b406bdfc37
@ -34,17 +34,20 @@ export class NTQQGroupApi {
|
|||||||
}
|
}
|
||||||
this.context.logger.logDebug(`加载${this.groups.length}个群组缓存完成`);
|
this.context.logger.logDebug(`加载${this.groups.length}个群组缓存完成`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchGroupEssenceList(groupCode: string) {
|
async fetchGroupEssenceList(groupCode: string) {
|
||||||
const pskey = (await this.core.apis.UserApi.getPSkey(['qun.qq.com'])).domainPskeyMap.get('qun.qq.com')!;
|
const pskey = (await this.core.apis.UserApi.getPSkey(['qun.qq.com'])).domainPskeyMap.get('qun.qq.com')!;
|
||||||
return this.context.session.getGroupService().fetchGroupEssenceList({
|
return this.context.session.getGroupService().fetchGroupEssenceList({
|
||||||
groupCode: groupCode,
|
groupCode: groupCode,
|
||||||
pageStart: 0,
|
pageStart: 0,
|
||||||
pageLimit: 300
|
pageLimit: 300,
|
||||||
}, pskey);
|
}, pskey);
|
||||||
}
|
}
|
||||||
|
|
||||||
async clearGroupNotifiesUnreadCount(unk: boolean) {
|
async clearGroupNotifiesUnreadCount(unk: boolean) {
|
||||||
return this.context.session.getGroupService().clearGroupNotifiesUnreadCount(unk);
|
return this.context.session.getGroupService().clearGroupNotifiesUnreadCount(unk);
|
||||||
}
|
}
|
||||||
|
|
||||||
async setGroupAvatar(gc: string, filePath: string) {
|
async setGroupAvatar(gc: string, filePath: string) {
|
||||||
return this.context.session.getGroupService().setHeader(gc, filePath);
|
return this.context.session.getGroupService().setHeader(gc, filePath);
|
||||||
}
|
}
|
||||||
@ -57,6 +60,7 @@ export class NTQQGroupApi {
|
|||||||
);
|
);
|
||||||
return groupList;
|
return groupList;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getGroupExtFE0Info(GroupCode: string[], forced = true) {
|
async getGroupExtFE0Info(GroupCode: string[], forced = true) {
|
||||||
return this.context.session.getGroupService().getGroupExt0xEF0Info(
|
return this.context.session.getGroupService().getGroupExt0xEF0Info(
|
||||||
GroupCode,
|
GroupCode,
|
||||||
@ -93,11 +97,12 @@ export class NTQQGroupApi {
|
|||||||
showPlayTogetherSwitch: 1,
|
showPlayTogetherSwitch: 1,
|
||||||
starId: 1,
|
starId: 1,
|
||||||
todoSeq: 1,
|
todoSeq: 1,
|
||||||
viewedMsgDisappearTime: 1
|
viewedMsgDisappearTime: 1,
|
||||||
},
|
},
|
||||||
forced
|
forced,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getGroup(groupCode: string, forced = false) {
|
async getGroup(groupCode: string, forced = false) {
|
||||||
let group = this.groupCache.get(groupCode.toString());
|
let group = this.groupCache.get(groupCode.toString());
|
||||||
if (!group) {
|
if (!group) {
|
||||||
@ -120,24 +125,13 @@ export class NTQQGroupApi {
|
|||||||
return this.getGroupMemberLatestSendTime(GroupCode, uids);
|
return this.getGroupMemberLatestSendTime(GroupCode, uids);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 通过QQ自带数据库获取群成员最后发言时间(仅返回有效数据 且消耗延迟大 需要进行缓存)
|
|
||||||
* @param GroupCode 群号
|
|
||||||
* @param uids QQ号
|
|
||||||
* @returns Map<string, string> key: uin value: sendTime
|
|
||||||
* @example
|
|
||||||
* let ret = await NTQQGroupApi.getGroupMemberLastestSendTime('123456');
|
|
||||||
* for (let [uin, sendTime] of ret) {
|
|
||||||
* console.log(uin, sendTime);
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
async getGroupMemberLatestSendTime(GroupCode: string, uids: string[]) {
|
async getGroupMemberLatestSendTime(GroupCode: string, uids: string[]) {
|
||||||
const getdata = async (uid: string) => {
|
const getData = async (uid: string) => {
|
||||||
const NTRet = await this.getLatestMsgByUids(GroupCode, [uid]);
|
const msgListWrapper = await this.getLatestMsgByUids(GroupCode, [uid]);
|
||||||
if (NTRet.result != 0 && NTRet.msgList.length < 1) {
|
if (msgListWrapper.result !== 0 && msgListWrapper.msgList.length < 1) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
return { sendUin: NTRet.msgList[0].senderUin, sendTime: NTRet.msgList[0].msgTime };
|
return { sendUin: msgListWrapper.msgList[0].senderUin, sendTime: msgListWrapper.msgList[0].msgTime };
|
||||||
};
|
};
|
||||||
const PromiseData: Promise<({
|
const PromiseData: Promise<({
|
||||||
sendUin: string;
|
sendUin: string;
|
||||||
@ -145,7 +139,7 @@ export class NTQQGroupApi {
|
|||||||
} | undefined)>[] = [];
|
} | undefined)>[] = [];
|
||||||
const ret: Map<string, string> = new Map();
|
const ret: Map<string, string> = new Map();
|
||||||
for (const uid of uids) {
|
for (const uid of uids) {
|
||||||
PromiseData.push(getdata(uid).catch(() => undefined));
|
PromiseData.push(getData(uid).catch(() => undefined));
|
||||||
}
|
}
|
||||||
const allRet = await runAllWithTimeout(PromiseData, 2500);
|
const allRet = await runAllWithTimeout(PromiseData, 2500);
|
||||||
for (const PromiseDo of allRet) {
|
for (const PromiseDo of allRet) {
|
||||||
@ -249,8 +243,7 @@ export class NTQQGroupApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async addGroupEssence(GroupCode: string, msgId: string) {
|
async addGroupEssence(GroupCode: string, msgId: string) {
|
||||||
// 代码没测过
|
// 需要 ob11msgId -> msgId + (peer) -> msgSeq + msgRandom
|
||||||
// 需要 ob11msgid->msgId + (peer) -> msgSeq + msgRandom
|
|
||||||
const MsgData = await this.context.session.getMsgService().getMsgsIncludeSelf({
|
const MsgData = await this.context.session.getMsgService().getMsgsIncludeSelf({
|
||||||
chatType: 2,
|
chatType: 2,
|
||||||
guildId: '',
|
guildId: '',
|
||||||
@ -261,7 +254,7 @@ export class NTQQGroupApi {
|
|||||||
msgRandom: parseInt(MsgData.msgList[0].msgRandom),
|
msgRandom: parseInt(MsgData.msgList[0].msgRandom),
|
||||||
msgSeq: parseInt(MsgData.msgList[0].msgSeq),
|
msgSeq: parseInt(MsgData.msgList[0].msgSeq),
|
||||||
};
|
};
|
||||||
// GetMsgByShoretID(ShoretID); -> MsgService.getMsgs(Peer,MsgId,1,false); -> 组出参数
|
// GetMsgByShortID(shortID); -> MsgService.getMsgs(Peer,MsgId,1,false); -> 组出参数
|
||||||
return this.context.session.getGroupService().addGroupEssence(param);
|
return this.context.session.getGroupService().addGroupEssence(param);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,8 +263,8 @@ export class NTQQGroupApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async deleteGroupBulletin(GroupCode: string, noticeId: string) {
|
async deleteGroupBulletin(GroupCode: string, noticeId: string) {
|
||||||
const _Pskey = (await this.core.apis.UserApi.getPSkey(['qun.qq.com'])).domainPskeyMap.get('qun.qq.com')!;
|
const psKey = (await this.core.apis.UserApi.getPSkey(['qun.qq.com'])).domainPskeyMap.get('qun.qq.com')!;
|
||||||
return this.context.session.getGroupService().deleteGroupBulletin(GroupCode, _Pskey, noticeId);
|
return this.context.session.getGroupService().deleteGroupBulletin(GroupCode, psKey, noticeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
async quitGroupV2(GroupCode: string, needDeleteLocalMsg: boolean) {
|
async quitGroupV2(GroupCode: string, needDeleteLocalMsg: boolean) {
|
||||||
@ -282,18 +275,17 @@ export class NTQQGroupApi {
|
|||||||
//应该是直接返回不需要Listener的 未经测试 需测试再发布
|
//应该是直接返回不需要Listener的 未经测试 需测试再发布
|
||||||
return this.context.session.getGroupService().quitGroupV2(param);
|
return this.context.session.getGroupService().quitGroupV2(param);
|
||||||
}
|
}
|
||||||
|
|
||||||
async removeGroupEssenceBySeq(GroupCode: string, msgRandom: string, msgSeq: string) {
|
async removeGroupEssenceBySeq(GroupCode: string, msgRandom: string, msgSeq: string) {
|
||||||
const param = {
|
const param = {
|
||||||
groupCode: GroupCode,
|
groupCode: GroupCode,
|
||||||
msgRandom: parseInt(msgRandom),
|
msgRandom: parseInt(msgRandom),
|
||||||
msgSeq: parseInt(msgSeq),
|
msgSeq: parseInt(msgSeq),
|
||||||
};
|
};
|
||||||
// GetMsgByShoretID(ShoretID); -> MsgService.getMsgs(Peer,MsgId,1,false); -> 组出参数
|
|
||||||
return this.context.session.getGroupService().removeGroupEssence(param);
|
return this.context.session.getGroupService().removeGroupEssence(param);
|
||||||
}
|
}
|
||||||
|
|
||||||
async removeGroupEssence(GroupCode: string, msgId: string) {
|
async removeGroupEssence(GroupCode: string, msgId: string) {
|
||||||
// 代码没测过
|
|
||||||
// 需要 ob11msgid->msgId + (peer) -> msgSeq + msgRandom
|
|
||||||
const MsgData = await this.context.session.getMsgService().getMsgsIncludeSelf({
|
const MsgData = await this.context.session.getMsgService().getMsgsIncludeSelf({
|
||||||
chatType: 2,
|
chatType: 2,
|
||||||
guildId: '',
|
guildId: '',
|
||||||
@ -304,7 +296,6 @@ export class NTQQGroupApi {
|
|||||||
msgRandom: parseInt(MsgData.msgList[0].msgRandom),
|
msgRandom: parseInt(MsgData.msgList[0].msgRandom),
|
||||||
msgSeq: parseInt(MsgData.msgList[0].msgSeq),
|
msgSeq: parseInt(MsgData.msgList[0].msgSeq),
|
||||||
};
|
};
|
||||||
// GetMsgByShoretID(ShoretID); -> MsgService.getMsgs(Peer,MsgId,1,false); -> 组出参数
|
|
||||||
return this.context.session.getGroupService().removeGroupEssence(param);
|
return this.context.session.getGroupService().removeGroupEssence(param);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -361,7 +352,7 @@ export class NTQQGroupApi {
|
|||||||
if (membersFromFunc.status === 'fulfilled' && membersFromListener.status === 'fulfilled') {
|
if (membersFromFunc.status === 'fulfilled' && membersFromListener.status === 'fulfilled') {
|
||||||
return new Map([
|
return new Map([
|
||||||
...membersFromFunc.value.result.infos,
|
...membersFromFunc.value.result.infos,
|
||||||
...membersFromListener.value[0].infos
|
...membersFromListener.value[0].infos,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
if (membersFromFunc.status === 'fulfilled') {
|
if (membersFromFunc.status === 'fulfilled') {
|
||||||
@ -386,19 +377,6 @@ export class NTQQGroupApi {
|
|||||||
|
|
||||||
this.context.logger.logDebug(`获取群(${groupQQ})成员列表结果:`, `members: ${result.result.infos.size}`); //, Array.from(result.result.infos.values()));
|
this.context.logger.logDebug(`获取群(${groupQQ})成员列表结果:`, `members: ${result.result.infos.size}`); //, Array.from(result.result.infos.values()));
|
||||||
return result.result.infos;
|
return result.result.infos;
|
||||||
/*
|
|
||||||
console.log(sceneId);
|
|
||||||
const result = await napCatCore.getGroupService().getNextMemberList(sceneId, num);
|
|
||||||
console.log(result);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
async getGroupNotifies() {
|
|
||||||
// 获取管理员变更
|
|
||||||
// 加群通知,退出通知,需要管理员权限
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getGroupFileCount(Gids: Array<string>) {
|
async getGroupFileCount(Gids: Array<string>) {
|
||||||
@ -470,19 +448,12 @@ export class NTQQGroupApi {
|
|||||||
return this.context.session.getGroupService().modifyGroupName(groupQQ, groupName, false);
|
return this.context.session.getGroupService().modifyGroupName(groupQQ, groupName, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 头衔不可用
|
|
||||||
/*
|
|
||||||
async setGroupTitle(groupQQ: string, uid: string, title: string) {
|
|
||||||
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
async publishGroupBulletin(groupQQ: string, content: string, picInfo: {
|
async publishGroupBulletin(groupQQ: string, content: string, picInfo: {
|
||||||
id: string,
|
id: string,
|
||||||
width: number,
|
width: number,
|
||||||
height: number
|
height: number
|
||||||
} | undefined = undefined, pinned: number = 0, confirmRequired: number = 0) {
|
} | undefined = undefined, pinned: number = 0, confirmRequired: number = 0) {
|
||||||
const _Pskey = (await this.core.apis.UserApi.getPSkey(['qun.qq.com'])).domainPskeyMap.get('qun.qq.com');
|
const psKey = (await this.core.apis.UserApi.getPSkey(['qun.qq.com'])).domainPskeyMap.get('qun.qq.com');
|
||||||
//text是content内容url编码
|
//text是content内容url编码
|
||||||
const data = {
|
const data = {
|
||||||
text: encodeURI(content),
|
text: encodeURI(content),
|
||||||
@ -491,7 +462,7 @@ export class NTQQGroupApi {
|
|||||||
pinned: pinned,
|
pinned: pinned,
|
||||||
confirmRequired: confirmRequired,
|
confirmRequired: confirmRequired,
|
||||||
};
|
};
|
||||||
return this.context.session.getGroupService().publishGroupBulletin(groupQQ, _Pskey!, data);
|
return this.context.session.getGroupService().publishGroupBulletin(groupQQ, psKey!, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getGroupRemainAtTimes(GroupCode: string) {
|
async getGroupRemainAtTimes(GroupCode: string) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user