mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
bbc58f3671 | ||
![]() |
fcd620283f | ||
![]() |
a78def3d2d | ||
![]() |
43e94a5db0 |
@@ -4,7 +4,7 @@
|
|||||||
"name": "NapCat",
|
"name": "NapCat",
|
||||||
"slug": "NapCat",
|
"slug": "NapCat",
|
||||||
"description": "OneBot v11 protocol implementation with NapCat logic",
|
"description": "OneBot v11 protocol implementation with NapCat logic",
|
||||||
"version": "2.0.8",
|
"version": "2.0.9",
|
||||||
"icon": "./logo.png",
|
"icon": "./logo.png",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
"name": "napcat",
|
"name": "napcat",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "2.0.8",
|
"version": "2.0.9",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build:framework": "vite build --mode framework",
|
"build:framework": "vite build --mode framework",
|
||||||
"build:shell": "vite build --mode shell",
|
"build:shell": "vite build --mode shell",
|
||||||
|
@@ -2,7 +2,7 @@ import path, { dirname } from 'path';
|
|||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
|
||||||
export const napcat_version = '2.0.8';
|
export const napcat_version = '2.0.9';
|
||||||
|
|
||||||
export class NapCatPathWrapper {
|
export class NapCatPathWrapper {
|
||||||
binaryPath: string;
|
binaryPath: string;
|
||||||
|
@@ -39,15 +39,16 @@ export class GoCQHTTPGetForwardMsgAction extends BaseAction<Payload, any> {
|
|||||||
throw Error('找不到相关的聊天记录' + data?.errMsg);
|
throw Error('找不到相关的聊天记录' + data?.errMsg);
|
||||||
}
|
}
|
||||||
const msgList = data.msgList;
|
const msgList = data.msgList;
|
||||||
const messages = await Promise.all(msgList.map(async msg => {
|
const messages = (await Promise.all(msgList.map(async msg => {
|
||||||
const resMsg = await OB11Constructor.message(this.CoreContext, msg, 'array');
|
const resMsg = await OB11Constructor.message(this.CoreContext, msg, 'array');
|
||||||
|
if (!resMsg) return;
|
||||||
resMsg.message_id = MessageUnique.createMsg({
|
resMsg.message_id = MessageUnique.createMsg({
|
||||||
guildId: '',
|
guildId: '',
|
||||||
chatType: msg.chatType,
|
chatType: msg.chatType,
|
||||||
peerUid: msg.peerUid,
|
peerUid: msg.peerUid,
|
||||||
}, msg.msgId)!;
|
}, msg.msgId)!;
|
||||||
return resMsg;
|
return resMsg;
|
||||||
}));
|
}))).filter(msg => !!msg);
|
||||||
messages.map(msg => {
|
messages.map(msg => {
|
||||||
(<OB11ForwardMessage>msg).content = msg.message;
|
(<OB11ForwardMessage>msg).content = msg.message;
|
||||||
delete (<any>msg).message;
|
delete (<any>msg).message;
|
||||||
|
@@ -53,7 +53,7 @@ export default class GetFriendMsgHistory extends BaseAction<Payload, Response> {
|
|||||||
msg.id = MessageUnique.createMsg({ guildId: '', chatType: msg.chatType, peerUid: msg.peerUid }, msg.msgId);
|
msg.id = MessageUnique.createMsg({ guildId: '', chatType: msg.chatType, peerUid: msg.peerUid }, msg.msgId);
|
||||||
}));
|
}));
|
||||||
//转换消息
|
//转换消息
|
||||||
const ob11MsgList = await Promise.all(msgList.map(msg => OB11Constructor.message(this.CoreContext, msg, 'array')));
|
const ob11MsgList = (await Promise.all(msgList.map(msg => OB11Constructor.message(this.CoreContext, msg, 'array')))).filter(msg => !!msg);
|
||||||
return { 'messages': ob11MsgList };
|
return { 'messages': ob11MsgList };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -48,7 +48,7 @@ export default class GoCQHTTPGetGroupMsgHistory extends BaseAction<Payload, Resp
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
//转换消息
|
//转换消息
|
||||||
const ob11MsgList = await Promise.all(msgList.map(msg => OB11Constructor.message(this.CoreContext, msg, 'array')));
|
const ob11MsgList = (await Promise.all(msgList.map(msg => OB11Constructor.message(this.CoreContext, msg, 'array')))).filter(msg => !!msg);
|
||||||
return { 'messages': ob11MsgList };
|
return { 'messages': ob11MsgList };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -69,7 +69,7 @@ class GetGroupMemberInfo extends BaseAction<Payload, OB11GroupMember> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Mlikiowa V2.0.8 Refactor Todo
|
// Mlikiowa V2.0.9 Refactor Todo
|
||||||
// retMember.last_sent_time = parseInt((await getGroupMember(payload.group_id.toString(), retMember.user_id))?.lastSpeakTime || date.toString());
|
// retMember.last_sent_time = parseInt((await getGroupMember(payload.group_id.toString(), retMember.user_id))?.lastSpeakTime || date.toString());
|
||||||
// retMember.join_time = parseInt((await getGroupMember(payload.group_id.toString(), retMember.user_id))?.joinTime || date.toString());
|
// retMember.join_time = parseInt((await getGroupMember(payload.group_id.toString(), retMember.user_id))?.joinTime || date.toString());
|
||||||
}
|
}
|
||||||
|
@@ -83,7 +83,7 @@ class GetGroupMemberList extends BaseAction<Payload, OB11GroupMember[]> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Mlikiowa V2.0.8 Refactor Todo
|
// Mlikiowa V2.0.9 Refactor Todo
|
||||||
// _groupMembers.forEach(async item => {
|
// _groupMembers.forEach(async item => {
|
||||||
// item.last_sent_time = parseInt((await getGroupMember(payload.group_id.toString(), item.user_id))?.lastSpeakTime || date.toString());
|
// item.last_sent_time = parseInt((await getGroupMember(payload.group_id.toString(), item.user_id))?.lastSpeakTime || date.toString());
|
||||||
// item.join_time = parseInt((await getGroupMember(payload.group_id.toString(), item.user_id))?.joinTime || date.toString());
|
// item.join_time = parseInt((await getGroupMember(payload.group_id.toString(), item.user_id))?.joinTime || date.toString());
|
||||||
|
@@ -38,6 +38,7 @@ class GetMsg extends BaseAction<Payload, OB11Message> {
|
|||||||
peer,
|
peer,
|
||||||
[msgIdWithPeer?.MsgId || payload.message_id.toString()]);
|
[msgIdWithPeer?.MsgId || payload.message_id.toString()]);
|
||||||
const retMsg = await OB11Constructor.message(this.CoreContext, msg.msgList[0], 'array');
|
const retMsg = await OB11Constructor.message(this.CoreContext, msg.msgList[0], 'array');
|
||||||
|
if(!retMsg) throw Error('消息为空');
|
||||||
try {
|
try {
|
||||||
retMsg.message_id = MessageUnique.createMsg(peer, msg.msgList[0].msgId)!;
|
retMsg.message_id = MessageUnique.createMsg(peer, msg.msgList[0].msgId)!;
|
||||||
retMsg.message_seq = retMsg.message_id;
|
retMsg.message_seq = retMsg.message_id;
|
||||||
|
@@ -56,7 +56,7 @@ const _handlers: {
|
|||||||
if (atQQ === 'all') return SendMsgElementConstructor.at(coreContext, atQQ, atQQ, AtType.atAll, '全体成员');
|
if (atQQ === 'all') return SendMsgElementConstructor.at(coreContext, atQQ, atQQ, AtType.atAll, '全体成员');
|
||||||
|
|
||||||
// then the qq is a group member
|
// then the qq is a group member
|
||||||
// Mlikiowa V2.0.8 Refactor Todo
|
// Mlikiowa V2.0.9 Refactor Todo
|
||||||
const uid = await coreContext.apis.UserApi.getUidByUinV2(atQQ);
|
const uid = await coreContext.apis.UserApi.getUidByUinV2(atQQ);
|
||||||
if (!uid) throw new Error('Get Uid Error');
|
if (!uid) throw new Error('Get Uid Error');
|
||||||
return SendMsgElementConstructor.at(coreContext, atQQ, uid, AtType.atUser, '');
|
return SendMsgElementConstructor.at(coreContext, atQQ, uid, AtType.atUser, '');
|
||||||
@@ -161,7 +161,7 @@ const _handlers: {
|
|||||||
} else {
|
} else {
|
||||||
postData = data;
|
postData = data;
|
||||||
}
|
}
|
||||||
// Mlikiowa V2.0.8 Refactor Todo
|
// Mlikiowa V2.0.9 Refactor Todo
|
||||||
const signUrl = obContext.configLoader.configData.musicSignUrl;
|
const signUrl = obContext.configLoader.configData.musicSignUrl;
|
||||||
if (!signUrl) {
|
if (!signUrl) {
|
||||||
if (data.type === 'qq') {
|
if (data.type === 'qq') {
|
||||||
|
@@ -43,9 +43,11 @@ import { OB11GroupEssenceEvent } from '../event/notice/OB11GroupEssenceEvent';
|
|||||||
import { MessageUnique } from '@/common/utils/MessageUnique';
|
import { MessageUnique } from '@/common/utils/MessageUnique';
|
||||||
import { NapCatCore } from '@/core';
|
import { NapCatCore } from '@/core';
|
||||||
|
|
||||||
|
|
||||||
export class OB11Constructor {
|
export class OB11Constructor {
|
||||||
static async message(core: NapCatCore, msg: RawMessage, messagePostFormat: any): Promise<OB11Message> {
|
static async message(core: NapCatCore, msg: RawMessage, messagePostFormat: any): Promise<OB11Message | undefined> {
|
||||||
|
if (msg.senderUin == "0") return;
|
||||||
|
if (msg.peerUin == "0") return;
|
||||||
|
//跳过空消息
|
||||||
const NTQQGroupApi = core.apis.GroupApi;
|
const NTQQGroupApi = core.apis.GroupApi;
|
||||||
const NTQQUserApi = core.apis.UserApi;
|
const NTQQUserApi = core.apis.UserApi;
|
||||||
const NTQQFileApi = core.apis.FileApi;
|
const NTQQFileApi = core.apis.FileApi;
|
||||||
@@ -141,7 +143,7 @@ export class OB11Constructor {
|
|||||||
message_data['type'] = OB11MessageDataType.reply;
|
message_data['type'] = OB11MessageDataType.reply;
|
||||||
//log("收到回复消息", element.replyElement);
|
//log("收到回复消息", element.replyElement);
|
||||||
try {
|
try {
|
||||||
const records = msg.records.find(msgRecord => msgRecord.msgId === element.replyElement.sourceMsgIdInRecords);
|
const records = msg.records.find(msgRecord => msgRecord.msgId === element?.replyElement?.sourceMsgIdInRecords);
|
||||||
const peer = {
|
const peer = {
|
||||||
chatType: msg.chatType,
|
chatType: msg.chatType,
|
||||||
peerUid: msg.peerUid,
|
peerUid: msg.peerUid,
|
||||||
@@ -278,13 +280,13 @@ export class OB11Constructor {
|
|||||||
chatType: msg.chatType,
|
chatType: msg.chatType,
|
||||||
guildId: '',
|
guildId: '',
|
||||||
},
|
},
|
||||||
msg.msgId,
|
msg.msgId,
|
||||||
msg.msgSeq,
|
msg.msgSeq,
|
||||||
msg.senderUid,
|
msg.senderUid,
|
||||||
element.elementId,
|
element.elementId,
|
||||||
element.elementType.toString(),
|
element.elementType.toString(),
|
||||||
element.pttElement.fileSize || '0',
|
element.pttElement.fileSize || '0',
|
||||||
element.pttElement.fileUuid || '',
|
element.pttElement.fileUuid || '',
|
||||||
);
|
);
|
||||||
//以uuid作为文件名
|
//以uuid作为文件名
|
||||||
} else if (element.arkElement) {
|
} else if (element.arkElement) {
|
||||||
@@ -343,6 +345,7 @@ export class OB11Constructor {
|
|||||||
MultiMsg.parentMsgIdList = msg.parentMsgIdList;
|
MultiMsg.parentMsgIdList = msg.parentMsgIdList;
|
||||||
MultiMsg.id = MessageUnique.createMsg(ParentMsgPeer, MultiMsg.msgId);//该ID仅用查看 无法调用
|
MultiMsg.id = MessageUnique.createMsg(ParentMsgPeer, MultiMsg.msgId);//该ID仅用查看 无法调用
|
||||||
const msgList = await OB11Constructor.message(core, MultiMsg, 'array');
|
const msgList = await OB11Constructor.message(core, MultiMsg, 'array');
|
||||||
|
if (!msgList) continue;
|
||||||
message_data['data']['content'].push(msgList);
|
message_data['data']['content'].push(msgList);
|
||||||
//console.log("合并消息", msgList);
|
//console.log("合并消息", msgList);
|
||||||
}
|
}
|
||||||
@@ -408,7 +411,7 @@ export class OB11Constructor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//log("group msg", msg);
|
//log("group msg", msg);
|
||||||
// Mlikiowa V2.0.8 Refactor Todo
|
// Mlikiowa V2.0.9 Refactor Todo
|
||||||
// if (msg.senderUin && msg.senderUin !== '0') {
|
// if (msg.senderUin && msg.senderUin !== '0') {
|
||||||
// const member = await getGroupMember(msg.peerUid, msg.senderUin);
|
// const member = await getGroupMember(msg.peerUid, msg.senderUin);
|
||||||
// if (member && member.cardName !== msg.sendMemberName) {
|
// if (member && member.cardName !== msg.sendMemberName) {
|
||||||
|
@@ -255,6 +255,7 @@ export class NapCatOneBot11Adapter {
|
|||||||
// 完成后再post
|
// 完成后再post
|
||||||
OB11Constructor.message(this.core, msg, this.configLoader.configData.messagePostFormat)
|
OB11Constructor.message(this.core, msg, this.configLoader.configData.messagePostFormat)
|
||||||
.then((ob11Msg) => {
|
.then((ob11Msg) => {
|
||||||
|
if(!ob11Msg) return;
|
||||||
ob11Msg.target_id = parseInt(msg.peerUin);
|
ob11Msg.target_id = parseInt(msg.peerUin);
|
||||||
if (this.configLoader.configData.reportSelfMessage) {
|
if (this.configLoader.configData.reportSelfMessage) {
|
||||||
msg.id = MessageUnique.createMsg({
|
msg.id = MessageUnique.createMsg({
|
||||||
@@ -425,6 +426,7 @@ export class NapCatOneBot11Adapter {
|
|||||||
const { debug, reportSelfMessage, messagePostFormat } = this.configLoader.configData;
|
const { debug, reportSelfMessage, messagePostFormat } = this.configLoader.configData;
|
||||||
this.context.logger.logDebug('收到新消息 RawMessage', message);
|
this.context.logger.logDebug('收到新消息 RawMessage', message);
|
||||||
OB11Constructor.message(this.core, message, messagePostFormat).then((ob11Msg) => {
|
OB11Constructor.message(this.core, message, messagePostFormat).then((ob11Msg) => {
|
||||||
|
if(!ob11Msg) return;
|
||||||
this.context.logger.logDebug('转化为 OB11Message', ob11Msg);
|
this.context.logger.logDebug('转化为 OB11Message', ob11Msg);
|
||||||
if (debug) {
|
if (debug) {
|
||||||
ob11Msg.raw = message;
|
ob11Msg.raw = message;
|
||||||
|
@@ -26,7 +26,7 @@ export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onEvent<T extends OB11EmitEventContent>(event: T) {
|
onEvent<T extends OB11EmitEventContent>(event: T) {
|
||||||
if (this.connection) {
|
if (this.connection && this.connection.readyState === WebSocket.OPEN) {
|
||||||
this.connection.send(JSON.stringify(event));
|
this.connection.send(JSON.stringify(event));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -30,7 +30,7 @@ async function onSettingWindowCreated(view: Element) {
|
|||||||
SettingItem(
|
SettingItem(
|
||||||
'<span id="napcat-update-title">Napcat</span>',
|
'<span id="napcat-update-title">Napcat</span>',
|
||||||
undefined,
|
undefined,
|
||||||
SettingButton('V2.0.8', 'napcat-update-button', 'secondary'),
|
SettingButton('V2.0.9', 'napcat-update-button', 'secondary'),
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
SettingList([
|
SettingList([
|
||||||
|
@@ -164,7 +164,7 @@ async function onSettingWindowCreated(view) {
|
|||||||
SettingItem(
|
SettingItem(
|
||||||
'<span id="napcat-update-title">Napcat</span>',
|
'<span id="napcat-update-title">Napcat</span>',
|
||||||
void 0,
|
void 0,
|
||||||
SettingButton("V2.0.8", "napcat-update-button", "secondary")
|
SettingButton("V2.0.9", "napcat-update-button", "secondary")
|
||||||
)
|
)
|
||||||
]),
|
]),
|
||||||
SettingList([
|
SettingList([
|
||||||
|
Reference in New Issue
Block a user