mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
refactor: extract emoji like parsing logic
This commit is contained in:
parent
3d39fd1580
commit
3a03e455c6
@ -112,8 +112,10 @@ export class OneBotGroupApi {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
async parseGroupEmjioLikeEvent(GroupCode: string, grayTipElement: GrayTipElement) {
|
async parseGroupEmojiLikeEventByGrayTip(
|
||||||
const NTQQMsgApi = this.core.apis.MsgApi;
|
groupCode: string,
|
||||||
|
grayTipElement: GrayTipElement
|
||||||
|
) {
|
||||||
const emojiLikeData = new fastXmlParser.XMLParser({
|
const emojiLikeData = new fastXmlParser.XMLParser({
|
||||||
ignoreAttributes: false,
|
ignoreAttributes: false,
|
||||||
attributeNamePrefix: '',
|
attributeNamePrefix: '',
|
||||||
@ -122,16 +124,27 @@ export class OneBotGroupApi {
|
|||||||
const senderUin = emojiLikeData.gtip.qq.jp;
|
const senderUin = emojiLikeData.gtip.qq.jp;
|
||||||
const msgSeq = emojiLikeData.gtip.url.msgseq;
|
const msgSeq = emojiLikeData.gtip.url.msgseq;
|
||||||
const emojiId = emojiLikeData.gtip.face.id;
|
const emojiId = emojiLikeData.gtip.face.id;
|
||||||
|
return await this.createGroupEmojiLikeEvent(groupCode, senderUin, msgSeq, emojiId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async createGroupEmojiLikeEvent(
|
||||||
|
groupCode: string,
|
||||||
|
senderUin: string,
|
||||||
|
msgSeq: string,
|
||||||
|
emojiId: string,
|
||||||
|
) {
|
||||||
const peer = {
|
const peer = {
|
||||||
chatType: ChatType.KCHATTYPEGROUP,
|
chatType: ChatType.KCHATTYPEGROUP,
|
||||||
guildId: '',
|
guildId: '',
|
||||||
peerUid: GroupCode,
|
peerUid: groupCode,
|
||||||
};
|
};
|
||||||
const replyMsgList = (await NTQQMsgApi.getMsgExBySeq(peer, msgSeq)).msgList;
|
const replyMsgList = (await this.core.apis.MsgApi.getMsgExBySeq(peer, msgSeq)).msgList;
|
||||||
if (replyMsgList.length < 1) {
|
if (replyMsgList.length < 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const replyMsg = replyMsgList.filter(e => e.msgSeq == msgSeq).sort((a, b) => parseInt(a.msgTime) - parseInt(b.msgTime))[0];
|
const replyMsg = replyMsgList
|
||||||
|
.filter(e => e.msgSeq == msgSeq)
|
||||||
|
.sort((a, b) => parseInt(a.msgTime) - parseInt(b.msgTime))[0];
|
||||||
//console.log("表情回应消息长度检测", msgSeq, replyMsg.elements);
|
//console.log("表情回应消息长度检测", msgSeq, replyMsg.elements);
|
||||||
if (!replyMsg) {
|
if (!replyMsg) {
|
||||||
this.core.context.logger.logError('解析表情回应消息失败: 未找到回应消息');
|
this.core.context.logger.logError('解析表情回应消息失败: 未找到回应消息');
|
||||||
@ -139,7 +152,7 @@ export class OneBotGroupApi {
|
|||||||
}
|
}
|
||||||
return new OB11GroupMsgEmojiLikeEvent(
|
return new OB11GroupMsgEmojiLikeEvent(
|
||||||
this.core,
|
this.core,
|
||||||
parseInt(GroupCode),
|
parseInt(groupCode),
|
||||||
parseInt(senderUin),
|
parseInt(senderUin),
|
||||||
MessageUnique.getShortIdByMsgId(replyMsg.msgId)!,
|
MessageUnique.getShortIdByMsgId(replyMsg.msgId)!,
|
||||||
[{
|
[{
|
||||||
|
@ -90,7 +90,7 @@ export async function NT2GroupEvent(core: NapCatCore, obContext: NapCatOneBot11A
|
|||||||
}
|
}
|
||||||
if (element.grayTipElement) {
|
if (element.grayTipElement) {
|
||||||
if (element.grayTipElement.xmlElement?.templId === '10382') {
|
if (element.grayTipElement.xmlElement?.templId === '10382') {
|
||||||
const emojiLikeEvent = await obContext.apis.GroupApi.parseGroupEmjioLikeEvent(msg.peerUid, element.grayTipElement);
|
const emojiLikeEvent = await obContext.apis.GroupApi.parseGroupEmojiLikeEventByGrayTip(msg.peerUid, element.grayTipElement);
|
||||||
if (emojiLikeEvent) return emojiLikeEvent;
|
if (emojiLikeEvent) return emojiLikeEvent;
|
||||||
}
|
}
|
||||||
if (element.grayTipElement.subElementType == NTGrayTipElementSubTypeV2.GRAYTIP_ELEMENT_SUBTYPE_XMLMSG) {
|
if (element.grayTipElement.subElementType == NTGrayTipElementSubTypeV2.GRAYTIP_ELEMENT_SUBTYPE_XMLMSG) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user