From d1c91be167b485335a88a3442fd703469979efcc Mon Sep 17 00:00:00 2001 From: linyuchen Date: Sat, 27 Apr 2024 19:51:59 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=A1=A8=E6=83=85=E5=9B=9E=E5=BA=94api?= =?UTF-8?q?=E5=92=8C=E4=B8=8A=E6=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + src/core | 2 +- src/onebot11/action/index.ts | 2 ++ src/onebot11/action/msg/SetMsgEmojiLike.ts | 27 +++++++++++++++ src/onebot11/action/types.ts | 2 ++ src/onebot11/constructor.ts | 34 +++++++++++++++++++ .../event/notice/OB11MsgEmojiLikeEvent.ts | 21 ++++++++++++ 7 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 src/onebot11/action/msg/SetMsgEmojiLike.ts create mode 100644 src/onebot11/event/notice/OB11MsgEmojiLikeEvent.ts diff --git a/package.json b/package.json index 5caeb6883..ceac2f08d 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,7 @@ "commander": "^12.0.0", "cors": "^2.8.5", "express": "^5.0.0-beta.2", + "fast-xml-parser": "^4.3.6", "file-type": "^19.0.0", "fluent-ffmpeg": "^2.1.2", "image-size": "^1.1.1", diff --git a/src/core b/src/core index 5d6d44606..142df7622 160000 --- a/src/core +++ b/src/core @@ -1 +1 @@ -Subproject commit 5d6d446065f5f4963aad96f94f6e36ff5c9e0986 +Subproject commit 142df7622b7e8805ca666d3180b4c57844f2ea1e diff --git a/src/onebot11/action/index.ts b/src/onebot11/action/index.ts index 45a8016bf..4ee9a8aed 100644 --- a/src/onebot11/action/index.ts +++ b/src/onebot11/action/index.ts @@ -45,6 +45,7 @@ import GoCQHTTPGetGroupMsgHistory from './go-cqhttp/GetGroupMsgHistory'; import GetFile from './file/GetFile'; import { GoCQHTTGetForwardMsgAction } from './go-cqhttp/GetForwardMsg'; import GetFriendMsgHistory from './go-cqhttp/GetFriendMsgHistory'; +import { SetMsgEmojiLike } from '@/onebot11/action/msg/SetMsgEmojiLike'; export const actionHandlers = [ new GetFile(), @@ -79,6 +80,7 @@ export const actionHandlers = [ new SetGroupCard(), new GetImage(), new GetRecord(), + new SetMsgEmojiLike(), // new CleanCache(), //以下为go-cqhttp api diff --git a/src/onebot11/action/msg/SetMsgEmojiLike.ts b/src/onebot11/action/msg/SetMsgEmojiLike.ts new file mode 100644 index 000000000..fe31c9341 --- /dev/null +++ b/src/onebot11/action/msg/SetMsgEmojiLike.ts @@ -0,0 +1,27 @@ +import { ActionName } from '../types'; +import BaseAction from '../BaseAction'; +import { dbUtil } from '@/common/utils/db'; +import { NTQQMsgApi } from '@/core/apis'; + +interface Payload { + message_id: number, + emoji_id: string +} + +export class SetMsgEmojiLike extends BaseAction { + actionName = ActionName.SetMsgEmojiLike; + + protected async _handle(payload: Payload) { + const msg = await dbUtil.getMsgByShortId(payload.message_id); + if (!msg) { + throw new Error('msg not found'); + } + if (!payload.emoji_id){ + throw new Error('emojiId not found'); + } + return await NTQQMsgApi.setEmojiLike({ + chatType: msg.chatType, + peerUid: msg.peerUid + }, msg.msgSeq, payload.emoji_id, true); + } +} diff --git a/src/onebot11/action/types.ts b/src/onebot11/action/types.ts index 138a54684..c436e6611 100644 --- a/src/onebot11/action/types.ts +++ b/src/onebot11/action/types.ts @@ -34,6 +34,7 @@ export enum ActionName { SendGroupMsg = 'send_group_msg', SendPrivateMsg = 'send_private_msg', DeleteMsg = 'delete_msg', + SetMsgEmojiLike = 'set_msg_emoji_like', SetGroupAddRequest = 'set_group_add_request', SetFriendAddRequest = 'set_friend_add_request', SetGroupLeave = 'set_group_leave', @@ -50,6 +51,7 @@ export enum ActionName { GetImage = 'get_image', GetRecord = 'get_record', CleanCache = 'clean_cache', + // 以下为go-cqhttp api GoCQHTTP_SendForwardMsg = 'send_forward_msg', GoCQHTTP_SendGroupForwardMsg = 'send_group_forward_msg', diff --git a/src/onebot11/constructor.ts b/src/onebot11/constructor.ts index f3e23b2e5..e70cd1055 100644 --- a/src/onebot11/constructor.ts +++ b/src/onebot11/constructor.ts @@ -1,3 +1,4 @@ +import fastXmlParser, { XMLParser } from 'fast-xml-parser'; import { OB11Group, OB11GroupMember, @@ -42,6 +43,7 @@ import { ob11Config } from '@/onebot11/config'; import { deleteGroup, getFriend, getGroupMember, groupMembers, selfInfo, tempGroupCodeMap } from '@/common/data'; import { NTQQFileApi, NTQQGroupApi, NTQQUserApi } from '../core/src/apis'; import http from 'http'; +import { OB11GroupMsgEmojiLikeEvent } from '@/onebot11/event/notice/OB11MsgEmojiLikeEvent'; export class OB11Constructor { @@ -320,6 +322,38 @@ export class OB11Constructor { } if (grayTipElement) { + const xmlElement = grayTipElement.xmlElement; + + if (xmlElement?.templId === '10382') { + // 表情回应消息 + // "content": + // " + // + // + // + // + // ", + const emojiLikeData = new fastXmlParser.XMLParser({ + ignoreAttributes: false, + attributeNamePrefix: '' + }).parse(xmlElement.content); + logDebug('收到表情回应我的消息', emojiLikeData); + try { + const senderUin = emojiLikeData.gtip.qq.jp; + const msgSeq = emojiLikeData.gtip.url.msgseq; + const emojiId = emojiLikeData.gtip.face.id; + const replyMsg = await dbUtil.getMsgBySeq(msg.peerUid, msgSeq); + if (!replyMsg) { + return; + } + return new OB11GroupMsgEmojiLikeEvent(parseInt(msg.peerUid), parseInt(senderUin), replyMsg.id!, [{ + emoji_id: emojiId, + count: 1 + }]); + } catch (e: any) { + logError('解析表情回应消息失败', e.stack); + } + } if (grayTipElement.subElementType == GrayTipElementSubType.INVITE_NEW_MEMBER) { logDebug('收到新人被邀请进群消息', grayTipElement); const xmlElement = grayTipElement.xmlElement; diff --git a/src/onebot11/event/notice/OB11MsgEmojiLikeEvent.ts b/src/onebot11/event/notice/OB11MsgEmojiLikeEvent.ts new file mode 100644 index 000000000..0351f4683 --- /dev/null +++ b/src/onebot11/event/notice/OB11MsgEmojiLikeEvent.ts @@ -0,0 +1,21 @@ +import {OB11GroupNoticeEvent} from "./OB11GroupNoticeEvent"; + +export interface MsgEmojiLike { + emoji_id: string, + count: number +} + +export class OB11GroupMsgEmojiLikeEvent extends OB11GroupNoticeEvent { + notice_type = "group_msg_emoji_like"; + message_id: number; + sub_type: "ban" | "lift_ban"; + likes: MsgEmojiLike[] + + constructor(groupId: number, userId: number, messageId: number, likes: MsgEmojiLike[]) { + super(); + this.group_id = groupId; + this.user_id = userId; // 可为空,表示是对别人的消息操作,如果是对bot自己的消息则不为空 + this.message_id = messageId; + this.likes = likes; + } +}