mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
feat: code style
This commit is contained in:
parent
b1ecf13f8e
commit
04593e9d9a
@ -1,4 +1,4 @@
|
|||||||
import { ChatType, GroupEssenceMsgRet, Peer } from '@/core';
|
import { ChatType, Peer } from '@/core';
|
||||||
import BaseAction from '../BaseAction';
|
import BaseAction from '../BaseAction';
|
||||||
import { ActionName } from '../types';
|
import { ActionName } from '../types';
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||||
@ -18,64 +18,30 @@ type Payload = FromSchema<typeof SchemaData>;
|
|||||||
export class GetGroupEssence extends BaseAction<Payload, any> {
|
export class GetGroupEssence extends BaseAction<Payload, any> {
|
||||||
actionName = ActionName.GoCQHTTP_GetEssenceMsg;
|
actionName = ActionName.GoCQHTTP_GetEssenceMsg;
|
||||||
payloadSchema = SchemaData;
|
payloadSchema = SchemaData;
|
||||||
async parseEssenceMsgImage(ele: any) {
|
|
||||||
return {
|
private async msgSeqToMsgId(peer: Peer, msgSeq: string, msgRandom: string) {
|
||||||
type: 'image',
|
const replyMsgList = (await this.core.apis.MsgApi.getMsgsBySeqAndCount(peer, msgSeq, 1, true, true)).msgList.find((msg) => msg.msgSeq === msgSeq && msg.msgRandom === msgRandom);
|
||||||
data: {
|
|
||||||
url: ele?.image_url,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
async parseEssenceMsgText(ele: any) {
|
|
||||||
return {
|
|
||||||
type: 'text',
|
|
||||||
data: {
|
|
||||||
text: ele?.text
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
async parseEssenceMsg(msgs: any) {
|
|
||||||
let handledMsg: any[] = [];
|
|
||||||
for (let msg of msgs) {
|
|
||||||
switch (msg.msg_type) {
|
|
||||||
case 1:
|
|
||||||
handledMsg.push(await this.parseEssenceMsgText(msg));
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
handledMsg.push(await this.parseEssenceMsgImage(msg));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return handledMsg;
|
|
||||||
}
|
|
||||||
async msgSeqToMsgId(peer: Peer, msgSeq: string, msgRandom: string) {
|
|
||||||
const NTQQMsgApi = this.core.apis.MsgApi;
|
|
||||||
const replyMsgList = (await NTQQMsgApi.getMsgsBySeqAndCount(peer, msgSeq, 1, true, true)).msgList.find((msg) => msg.msgSeq === msgSeq && msg.msgRandom === msgRandom);
|
|
||||||
if (!replyMsgList) {
|
if (!replyMsgList) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
id: MessageUnique.createUniqueMsgId(peer, replyMsgList.msgId),
|
id: MessageUnique.createUniqueMsgId(peer, replyMsgList.msgId),
|
||||||
msg: replyMsgList
|
msg: replyMsgList
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async _handle(payload: Payload) {
|
async _handle(payload: Payload) {
|
||||||
const NTQQWebApi = this.core.apis.WebApi;
|
const NTQQWebApi = this.core.apis.WebApi;
|
||||||
const NTQQGroupApi = this.core.apis.GroupApi;
|
const NTQQGroupApi = this.core.apis.GroupApi;
|
||||||
//await NTQQGroupApi.fetchGroupEssenceList(payload.group_id.toString());
|
|
||||||
let peer = {
|
|
||||||
chatType: ChatType.KCHATTYPEGROUP,
|
|
||||||
peerUid: payload.group_id.toString(),
|
|
||||||
};
|
|
||||||
|
|
||||||
const ret = await NTQQWebApi.getGroupEssenceMsg(payload.group_id.toString());
|
const ret = await NTQQWebApi.getGroupEssenceMsg(payload.group_id.toString());
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
throw new Error('获取失败');
|
throw new Error('获取失败');
|
||||||
}
|
}
|
||||||
const Ob11Ret = await Promise.all(ret.data.msg_list.map(async (msg) => {
|
return await Promise.all(ret.data.msg_list.map(async (msg) => {
|
||||||
let msgOriginData = await this.msgSeqToMsgId(peer, msg.msg_seq.toString(), msg.msg_random.toString());
|
const msgOriginData = await this.msgSeqToMsgId({
|
||||||
|
chatType: ChatType.KCHATTYPEGROUP,
|
||||||
|
peerUid: payload.group_id.toString(),
|
||||||
|
}, msg.msg_seq.toString(), msg.msg_random.toString());
|
||||||
if (msgOriginData) {
|
if (msgOriginData) {
|
||||||
const { id: message_id, msg: rawMessage } = msgOriginData;
|
const { id: message_id, msg: rawMessage } = msgOriginData;
|
||||||
return {
|
return {
|
||||||
@ -109,9 +75,25 @@ export class GetGroupEssence extends BaseAction<Payload, any> {
|
|||||||
operator_nick: msg.add_digest_nick,
|
operator_nick: msg.add_digest_nick,
|
||||||
message_id: shortId,
|
message_id: shortId,
|
||||||
operator_time: msg.add_digest_time,
|
operator_time: msg.add_digest_time,
|
||||||
content: await this.parseEssenceMsg(msg.msg_content)
|
content: msg.msg_content.map((msg) => {
|
||||||
|
if (msg.msg_type === 1) {
|
||||||
|
return {
|
||||||
|
type: 'text',
|
||||||
|
data: {
|
||||||
|
text: msg?.text
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} else if (msg.msg_type === 3) {
|
||||||
|
return {
|
||||||
|
type: 'image',
|
||||||
|
data: {
|
||||||
|
url: msg?.image_url,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}).filter(e => e !== undefined),
|
||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
return Ob11Ret;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user