mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-12-19 05:05:44 +08:00
feat: 支持不是自己的表情回应
This commit is contained in:
parent
91e633b0fb
commit
d5e6afc7b9
@ -74,6 +74,36 @@ export const GroupChange = {
|
||||
field7: ProtoField(7, ScalarType.BYTES, true),
|
||||
};
|
||||
|
||||
// Group Reaction Related
|
||||
export const GroupReactionDataInnerDataTarget = {
|
||||
seq: ProtoField(1, ScalarType.UINT64, true),
|
||||
};
|
||||
|
||||
export const GroupReactionDataContent = {
|
||||
code: ProtoField(1, ScalarType.STRING, true),
|
||||
count: ProtoField(3, ScalarType.UINT32, true),
|
||||
operatorUid: ProtoField(4, ScalarType.STRING, true),
|
||||
type: ProtoField(5, ScalarType.UINT32, true),
|
||||
};
|
||||
|
||||
export const GroupReactionDataInnerData = {
|
||||
groupReactionTarget: ProtoField(2, () => GroupReactionDataInnerDataTarget, true),
|
||||
groupReactionDataContent: ProtoField(3, () => GroupReactionDataContent, true),
|
||||
};
|
||||
export const GroupReactionDataInner = {
|
||||
data: ProtoField(1, () => GroupReactionDataInnerData, true),
|
||||
};
|
||||
export const GroupReactionData = {
|
||||
data: ProtoField(1, () => GroupReactionDataInner, true),
|
||||
};
|
||||
|
||||
export const GroupReactNotify = {
|
||||
groupUin: ProtoField(4, ScalarType.UINT64, true),
|
||||
field13: ProtoField(13, ScalarType.UINT32, true),
|
||||
groupReactionData: ProtoField(44, () => GroupReactionData, true),
|
||||
};
|
||||
|
||||
// Group Invite Related
|
||||
export const GroupInvite = {
|
||||
groupUin: ProtoField(1, ScalarType.UINT32),
|
||||
field2: ProtoField(2, ScalarType.UINT32),
|
||||
|
||||
@ -24,6 +24,8 @@ import { OB11GroupUploadNoticeEvent } from '../event/notice/OB11GroupUploadNotic
|
||||
import { OB11GroupNameEvent } from '../event/notice/OB11GroupNameEvent';
|
||||
import { FileNapCatOneBotUUID } from '@/common/file-uuid';
|
||||
import { OB11GroupIncreaseEvent } from '../event/notice/OB11GroupIncreaseEvent';
|
||||
import { NapProtoMsg } from '@napneko/nap-proto-core';
|
||||
import { GroupReactNotify, PushMsg } from '@/core/packet/transformer/proto';
|
||||
|
||||
export class OneBotGroupApi {
|
||||
obContext: NapCatOneBot11Adapter;
|
||||
@ -68,6 +70,10 @@ export class OneBotGroupApi {
|
||||
groupCode: string,
|
||||
grayTipElement: GrayTipElement
|
||||
) {
|
||||
if (this.core.apis.PacketApi.packetStatus === true) {
|
||||
return;
|
||||
//Raw包解析支持时禁用NT解析
|
||||
}
|
||||
const emojiLikeData = new fastXmlParser.XMLParser({
|
||||
ignoreAttributes: false,
|
||||
attributeNamePrefix: '',
|
||||
@ -76,7 +82,7 @@ export class OneBotGroupApi {
|
||||
const senderUin = emojiLikeData.gtip.qq.jp;
|
||||
const msgSeq = emojiLikeData.gtip.url.msgseq;
|
||||
const emojiId = emojiLikeData.gtip.face.id;
|
||||
return await this.createGroupEmojiLikeEvent(groupCode, senderUin, msgSeq, emojiId);
|
||||
return await this.createGroupEmojiLikeEvent(groupCode, senderUin, msgSeq, emojiId, true, 1);
|
||||
}
|
||||
|
||||
async createGroupEmojiLikeEvent(
|
||||
@ -84,6 +90,8 @@ export class OneBotGroupApi {
|
||||
senderUin: string,
|
||||
msgSeq: string,
|
||||
emojiId: string,
|
||||
isAdd: boolean = true,
|
||||
count: number = 1,
|
||||
) {
|
||||
const peer = {
|
||||
chatType: ChatType.KCHATTYPEGROUP,
|
||||
@ -106,8 +114,9 @@ export class OneBotGroupApi {
|
||||
MessageUnique.getShortIdByMsgId(replyMsg.msgId)!,
|
||||
[{
|
||||
emoji_id: emojiId,
|
||||
count: 1,
|
||||
count: count,
|
||||
}],
|
||||
isAdd
|
||||
);
|
||||
}
|
||||
|
||||
@ -128,7 +137,36 @@ export class OneBotGroupApi {
|
||||
}
|
||||
async registerParseGroupReactEvent() {
|
||||
this.obContext.core.context.packetHandler.onCmd('trpc.msg.olpush.OlPushService.MsgPush', async (packet) => {
|
||||
console.log(packet.seq, packet.hex_data);
|
||||
let data = new NapProtoMsg(PushMsg).decode(Buffer.from(packet.hex_data, 'hex'));
|
||||
if (data.message.contentHead.type === 732 && data.message.contentHead.subType === 16) {
|
||||
let pbNotify = data.message.body?.msgContent?.slice(7);
|
||||
if (!pbNotify) {
|
||||
return;
|
||||
}
|
||||
// 开始解析Notify
|
||||
const notify = new NapProtoMsg(GroupReactNotify).decode(pbNotify);
|
||||
if ((notify.field13 ?? 0) === 35) {
|
||||
// Group React Notify
|
||||
const groupCode = notify.groupUin?.toString() ?? '';
|
||||
const operatorUid = notify.groupReactionData?.data?.data?.groupReactionDataContent?.operatorUid ?? '';
|
||||
const type = notify.groupReactionData?.data?.data?.groupReactionDataContent?.type ?? 0;
|
||||
const seq = notify.groupReactionData?.data?.data?.groupReactionTarget?.seq?.toString() ?? '';
|
||||
const code = notify.groupReactionData?.data?.data?.groupReactionDataContent?.code ?? '';
|
||||
//const count = notify.groupReactionData?.data?.data?.groupReactionDataContent?.count ?? 0;
|
||||
const senderUin = await this.core.apis.UserApi.getUinByUidV2(operatorUid);
|
||||
const event = await this.createGroupEmojiLikeEvent(
|
||||
groupCode,
|
||||
senderUin,
|
||||
seq,
|
||||
code,
|
||||
type === 1,
|
||||
1
|
||||
);
|
||||
if (event) {
|
||||
this.obContext.networkManager.emitEvent(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
async parsePaiYiPai(msg: RawMessage, jsonStr: string) {
|
||||
|
||||
@ -10,12 +10,14 @@ export class OB11GroupMsgEmojiLikeEvent extends OB11GroupNoticeEvent {
|
||||
notice_type = 'group_msg_emoji_like';
|
||||
message_id: number;
|
||||
likes: MsgEmojiLike[];
|
||||
is_add: boolean;
|
||||
|
||||
constructor(core: NapCatCore, groupId: number, userId: number, messageId: number, likes: MsgEmojiLike[]) {
|
||||
constructor(core: NapCatCore, groupId: number, userId: number, messageId: number, likes: MsgEmojiLike[], isAdd: boolean) {
|
||||
super(core, groupId, userId);
|
||||
this.group_id = groupId;
|
||||
this.user_id = userId; // 可为空,表示是对别人的消息操作,如果是对bot自己的消息则不为空
|
||||
this.message_id = messageId;
|
||||
this.likes = likes;
|
||||
this.is_add = isAdd;
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ export class NapCatOneBot11Adapter {
|
||||
actions: ActionMap;
|
||||
private readonly bootTime = Date.now() / 1000;
|
||||
recallEventCache = new Map<string, NodeJS.Timeout>();
|
||||
constructor (core: NapCatCore, context: InstanceContext, pathWrapper: NapCatPathWrapper) {
|
||||
constructor(core: NapCatCore, context: InstanceContext, pathWrapper: NapCatPathWrapper) {
|
||||
this.core = core;
|
||||
this.context = context;
|
||||
this.configLoader = new OB11ConfigLoader(core, pathWrapper.configPath, OneBotConfigSchema);
|
||||
@ -80,7 +80,7 @@ export class NapCatOneBot11Adapter {
|
||||
this.actions = createActionMap(this, core);
|
||||
this.networkManager = new OB11NetworkManager();
|
||||
}
|
||||
async creatOneBotLog (ob11Config: OneBotConfig) {
|
||||
async creatOneBotLog(ob11Config: OneBotConfig) {
|
||||
let log = '[network] 配置加载\n';
|
||||
for (const key of ob11Config.network.httpServers) {
|
||||
log += `HTTP服务: ${key.host}:${key.port}, : ${key.enable ? '已启动' : '未启动'}\n`;
|
||||
@ -99,14 +99,14 @@ export class NapCatOneBot11Adapter {
|
||||
}
|
||||
return log;
|
||||
}
|
||||
async InitOneBot () {
|
||||
async InitOneBot() {
|
||||
const selfInfo = this.core.selfInfo;
|
||||
const ob11Config = this.configLoader.configData;
|
||||
this.core.apis.UserApi.getUserDetailInfo(selfInfo.uid, false)
|
||||
.then(async (user) => {
|
||||
selfInfo.nick = user.nick;
|
||||
this.context.logger.setLogSelfInfo(selfInfo);
|
||||
|
||||
|
||||
// 检查是否有待发送的token
|
||||
if (pendingTokenToSend) {
|
||||
this.context.logger.log('[NapCat] [OneBot] 🔐 检测到待发送的WebUI Token,开始发送');
|
||||
@ -117,10 +117,10 @@ export class NapCatOneBot11Adapter {
|
||||
elementType: ElementType.TEXT,
|
||||
elementId: '',
|
||||
textElement: {
|
||||
content:
|
||||
'[NapCat] 温馨提示:\n'+
|
||||
'WebUI密码为默认密码,已进行强制修改\n'+
|
||||
'新密码: ' +pendingTokenToSend,
|
||||
content:
|
||||
'[NapCat] 温馨提示:\n' +
|
||||
'WebUI密码为默认密码,已进行强制修改\n' +
|
||||
'新密码: ' + pendingTokenToSend,
|
||||
atType: NTMsgAtType.ATTYPEUNKNOWN,
|
||||
atUid: '',
|
||||
atTinyId: '',
|
||||
@ -134,7 +134,7 @@ export class NapCatOneBot11Adapter {
|
||||
this.context.logger.logError('[NapCat] [OneBot] ❌ WebUI Token 消息发送失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
WebUiDataRuntime.getQQLoginCallback()(true);
|
||||
})
|
||||
.catch(e => this.context.logger.logError(e));
|
||||
@ -216,10 +216,13 @@ export class NapCatOneBot11Adapter {
|
||||
//this.context.logger.log(`OneBot11 配置更改:${JSON.stringify(prev)} -> ${JSON.stringify(newConfig)}`);
|
||||
await this.reloadNetwork(prev, newConfig);
|
||||
});
|
||||
this.apis.GroupApi.registerParseGroupReactEvent().catch(e =>
|
||||
this.context.logger.logError('注册群消息反应表情失败', e)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
private async reloadNetwork (prev: OneBotConfig, now: OneBotConfig): Promise<void> {
|
||||
private async reloadNetwork(prev: OneBotConfig, now: OneBotConfig): Promise<void> {
|
||||
const prevLog = await this.creatOneBotLog(prev);
|
||||
const newLog = await this.creatOneBotLog(now);
|
||||
this.context.logger.log(`[Notice] [OneBot11] 配置变更前:\n${prevLog}`);
|
||||
@ -232,7 +235,7 @@ export class NapCatOneBot11Adapter {
|
||||
await this.handleConfigChange(prev.network.websocketClients, now.network.websocketClients, OB11WebSocketClientAdapter);
|
||||
}
|
||||
|
||||
private async handleConfigChange<CT extends NetworkAdapterConfig> (
|
||||
private async handleConfigChange<CT extends NetworkAdapterConfig>(
|
||||
prevConfig: NetworkAdapterConfig[],
|
||||
nowConfig: NetworkAdapterConfig[],
|
||||
adapterClass: new (
|
||||
@ -264,7 +267,7 @@ export class NapCatOneBot11Adapter {
|
||||
}
|
||||
}
|
||||
|
||||
private initMsgListener () {
|
||||
private initMsgListener() {
|
||||
const msgListener = new NodeIKernelMsgListener();
|
||||
msgListener.onRecvSysMsg = (msg) => {
|
||||
this.apis.MsgApi.parseSysMessage(msg)
|
||||
@ -378,7 +381,7 @@ export class NapCatOneBot11Adapter {
|
||||
this.context.session.getMsgService().addKernelMsgListener(proxiedListenerOf(msgListener, this.context.logger));
|
||||
}
|
||||
|
||||
private initBuddyListener () {
|
||||
private initBuddyListener() {
|
||||
const buddyListener = new NodeIKernelBuddyListener();
|
||||
|
||||
buddyListener.onBuddyReqChange = async (reqs) => {
|
||||
@ -409,7 +412,7 @@ export class NapCatOneBot11Adapter {
|
||||
.addKernelBuddyListener(proxiedListenerOf(buddyListener, this.context.logger));
|
||||
}
|
||||
|
||||
private initGroupListener () {
|
||||
private initGroupListener() {
|
||||
const groupListener = new NodeIKernelGroupListener();
|
||||
|
||||
groupListener.onGroupNotifiesUpdated = async (_, notifies) => {
|
||||
@ -502,7 +505,7 @@ export class NapCatOneBot11Adapter {
|
||||
.addKernelGroupListener(proxiedListenerOf(groupListener, this.context.logger));
|
||||
}
|
||||
|
||||
private async emitMsg (message: RawMessage) {
|
||||
private async emitMsg(message: RawMessage) {
|
||||
const network = await this.networkManager.getAllConfig();
|
||||
this.context.logger.logDebug('收到新消息 RawMessage', message);
|
||||
await Promise.allSettled([
|
||||
@ -511,7 +514,7 @@ export class NapCatOneBot11Adapter {
|
||||
]);
|
||||
}
|
||||
|
||||
private async handleMsg (message: RawMessage, network: Array<NetworkAdapterConfig>) {
|
||||
private async handleMsg(message: RawMessage, network: Array<NetworkAdapterConfig>) {
|
||||
// 过滤无效消息
|
||||
if (message.msgType === NTMsgType.KMSGTYPENULL) {
|
||||
return;
|
||||
@ -532,7 +535,7 @@ export class NapCatOneBot11Adapter {
|
||||
}
|
||||
}
|
||||
|
||||
private isSelfMessage (ob11Msg: {
|
||||
private isSelfMessage(ob11Msg: {
|
||||
stringMsg: OB11Message
|
||||
arrayMsg: OB11Message
|
||||
}): boolean {
|
||||
@ -540,7 +543,7 @@ export class NapCatOneBot11Adapter {
|
||||
ob11Msg.arrayMsg.user_id.toString() == this.core.selfInfo.uin;
|
||||
}
|
||||
|
||||
private createMsgMap (network: Array<NetworkAdapterConfig>, ob11Msg: {
|
||||
private createMsgMap(network: Array<NetworkAdapterConfig>, ob11Msg: {
|
||||
stringMsg: OB11Message
|
||||
arrayMsg: OB11Message
|
||||
}, isSelfMsg: boolean, message: RawMessage): Map<string, OB11Message> {
|
||||
@ -560,7 +563,7 @@ export class NapCatOneBot11Adapter {
|
||||
return msgMap;
|
||||
}
|
||||
|
||||
private handleDebugNetwork (network: Array<NetworkAdapterConfig>, msgMap: Map<string, OB11Message>, message: RawMessage) {
|
||||
private handleDebugNetwork(network: Array<NetworkAdapterConfig>, msgMap: Map<string, OB11Message>, message: RawMessage) {
|
||||
const debugNetwork = network.filter(e => e.enable && e.debug);
|
||||
if (debugNetwork.length > 0) {
|
||||
debugNetwork.forEach(adapter => {
|
||||
@ -574,7 +577,7 @@ export class NapCatOneBot11Adapter {
|
||||
}
|
||||
}
|
||||
|
||||
private handleNotReportSelfNetwork (network: Array<NetworkAdapterConfig>, msgMap: Map<string, OB11Message>, isSelfMsg: boolean) {
|
||||
private handleNotReportSelfNetwork(network: Array<NetworkAdapterConfig>, msgMap: Map<string, OB11Message>, isSelfMsg: boolean) {
|
||||
if (isSelfMsg) {
|
||||
const notReportSelfNetwork = network.filter(e => e.enable && (('reportSelfMessage' in e && !e.reportSelfMessage) || !('reportSelfMessage' in e)));
|
||||
notReportSelfNetwork.forEach(adapter => {
|
||||
@ -583,7 +586,7 @@ export class NapCatOneBot11Adapter {
|
||||
}
|
||||
}
|
||||
|
||||
private async handleGroupEvent (message: RawMessage) {
|
||||
private async handleGroupEvent(message: RawMessage) {
|
||||
try {
|
||||
// 群名片修改事件解析 任何都该判断
|
||||
if (message.senderUin && message.senderUin !== '0') {
|
||||
@ -616,7 +619,7 @@ export class NapCatOneBot11Adapter {
|
||||
}
|
||||
}
|
||||
|
||||
private async handlePrivateMsgEvent (message: RawMessage) {
|
||||
private async handlePrivateMsgEvent(message: RawMessage) {
|
||||
try {
|
||||
if (message.msgType === NTMsgType.KMSGTYPEGRAYTIPS) {
|
||||
// 灰条为单元素消息
|
||||
@ -634,7 +637,7 @@ export class NapCatOneBot11Adapter {
|
||||
}
|
||||
}
|
||||
|
||||
private async emitRecallMsg (message: RawMessage, element: MessageElement) {
|
||||
private async emitRecallMsg(message: RawMessage, element: MessageElement) {
|
||||
const peer: Peer = { chatType: message.chatType, peerUid: message.peerUid, guildId: '' };
|
||||
const oriMessageId = MessageUnique.getShortIdByMsgId(message.msgId) ?? MessageUnique.createUniqueMsgId(peer, message.msgId);
|
||||
if (message.chatType == ChatType.KCHATTYPEC2C) {
|
||||
@ -645,7 +648,7 @@ export class NapCatOneBot11Adapter {
|
||||
return;
|
||||
}
|
||||
|
||||
private async emitFriendRecallMsg (message: RawMessage, oriMessageId: number, element: MessageElement) {
|
||||
private async emitFriendRecallMsg(message: RawMessage, oriMessageId: number, element: MessageElement) {
|
||||
const operatorUid = element.grayTipElement?.revokeElement.operatorUid;
|
||||
if (!operatorUid) return undefined;
|
||||
return new OB11FriendRecallNoticeEvent(
|
||||
@ -655,7 +658,7 @@ export class NapCatOneBot11Adapter {
|
||||
);
|
||||
}
|
||||
|
||||
private async emitGroupRecallMsg (message: RawMessage, oriMessageId: number, element: MessageElement) {
|
||||
private async emitGroupRecallMsg(message: RawMessage, oriMessageId: number, element: MessageElement) {
|
||||
const operatorUid = element.grayTipElement?.revokeElement.operatorUid;
|
||||
if (!operatorUid) return undefined;
|
||||
const operatorId = await this.core.apis.UserApi.getUinByUidV2(operatorUid);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user