mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
release: 2.0.8
This commit is contained in:
@@ -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.7",
|
"version": "2.0.8",
|
||||||
"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.7",
|
"version": "2.0.8",
|
||||||
"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.7';
|
export const napcat_version = '2.0.8';
|
||||||
|
|
||||||
export class NapCatPathWrapper {
|
export class NapCatPathWrapper {
|
||||||
binaryPath: string;
|
binaryPath: string;
|
||||||
|
@@ -69,7 +69,7 @@ class GetGroupMemberInfo extends BaseAction<Payload, OB11GroupMember> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Mlikiowa V2.0.7 Refactor Todo
|
// Mlikiowa V2.0.8 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.7 Refactor Todo
|
// Mlikiowa V2.0.8 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());
|
||||||
|
@@ -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.7 Refactor Todo
|
// Mlikiowa V2.0.8 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.7 Refactor Todo
|
// Mlikiowa V2.0.8 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') {
|
||||||
|
@@ -408,7 +408,7 @@ export class OB11Constructor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//log("group msg", msg);
|
//log("group msg", msg);
|
||||||
// Mlikiowa V2.0.7 Refactor Todo
|
// Mlikiowa V2.0.8 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) {
|
||||||
|
@@ -6,6 +6,7 @@ import { ActionName } from '@/onebot/action/types';
|
|||||||
import { OB11Response } from '@/onebot/action/OB11Response';
|
import { OB11Response } from '@/onebot/action/OB11Response';
|
||||||
import { LogWrapper } from '@/common/utils/log';
|
import { LogWrapper } from '@/common/utils/log';
|
||||||
import { ActionMap } from '@/onebot/action';
|
import { ActionMap } from '@/onebot/action';
|
||||||
|
import { LifeCycleSubType, OB11LifeCycleEvent } from '../event/meta/OB11LifeCycleEvent';
|
||||||
|
|
||||||
export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter {
|
export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter {
|
||||||
isClosed: boolean = false;
|
isClosed: boolean = false;
|
||||||
@@ -76,14 +77,22 @@ export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter {
|
|||||||
'User-Agent': 'OneBot/11',
|
'User-Agent': 'OneBot/11',
|
||||||
},
|
},
|
||||||
|
|
||||||
|
});
|
||||||
|
this.connection.on('open', () => {
|
||||||
|
try{
|
||||||
|
this.connectEvent(this.coreContext);
|
||||||
|
}catch(e){
|
||||||
|
this.logger.logError('[OneBot] [WebSocket Client] 发送连接生命周期失败', e);
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
this.connection.on('message', (data) => {
|
this.connection.on('message', (data) => {
|
||||||
this.handleMessage(data);
|
this.handleMessage(data);
|
||||||
});
|
});
|
||||||
this.connection.once('close', () => {
|
this.connection.once('close', () => {
|
||||||
if (!isClosedByError) {
|
if (!isClosedByError) {
|
||||||
this.logger.logError(`反向WebSocket (${this.url}) 连接意外关闭`);
|
this.logger.logError(`[OneBot] [WebSocket Client] 反向WebSocket (${this.url}) 连接意外关闭`);
|
||||||
this.logger.logError(`在 ${Math.floor(this.reconnectIntervalInMillis / 1000)} 秒后尝试重新连接`);
|
this.logger.logError(`[OneBot] [WebSocket Client] 在 ${Math.floor(this.reconnectIntervalInMillis / 1000)} 秒后尝试重新连接`);
|
||||||
if (!this.isClosed) {
|
if (!this.isClosed) {
|
||||||
this.connection = null;
|
this.connection = null;
|
||||||
setTimeout(() => this.tryConnect(), this.reconnectIntervalInMillis);
|
setTimeout(() => this.tryConnect(), this.reconnectIntervalInMillis);
|
||||||
@@ -92,8 +101,8 @@ export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter {
|
|||||||
});
|
});
|
||||||
this.connection.on('error', (err) => {
|
this.connection.on('error', (err) => {
|
||||||
isClosedByError = true;
|
isClosedByError = true;
|
||||||
this.logger.logError(`反向WebSocket (${this.url}) 连接错误`, err);
|
this.logger.logError(`[OneBot] [WebSocket Client] 反向WebSocket (${this.url}) 连接错误`, err);
|
||||||
this.logger.logError(`在 ${Math.floor(this.reconnectIntervalInMillis / 1000)} 秒后尝试重新连接`);
|
this.logger.logError(`[OneBot] [WebSocket Client] 在 ${Math.floor(this.reconnectIntervalInMillis / 1000)} 秒后尝试重新连接`);
|
||||||
if (!this.isClosed) {
|
if (!this.isClosed) {
|
||||||
this.connection = null;
|
this.connection = null;
|
||||||
setTimeout(() => this.tryConnect(), this.reconnectIntervalInMillis);
|
setTimeout(() => this.tryConnect(), this.reconnectIntervalInMillis);
|
||||||
@@ -101,7 +110,13 @@ export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
connectEvent(core: NapCatCore) {
|
||||||
|
try {
|
||||||
|
this.checkStateAndReply<any>(new OB11LifeCycleEvent(core, LifeCycleSubType.CONNECT));
|
||||||
|
} catch (e) {
|
||||||
|
this.logger.logError('[OneBot] [WebSocket Client] 发送生命周期失败', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
private async handleMessage(message: any) {
|
private async handleMessage(message: any) {
|
||||||
let receiveData: { action: ActionName, params?: any, echo?: any } = { action: ActionName.Unknown, params: {} };
|
let receiveData: { action: ActionName, params?: any, echo?: any } = { action: ActionName.Unknown, params: {} };
|
||||||
let echo = undefined;
|
let echo = undefined;
|
||||||
@@ -109,7 +124,7 @@ export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter {
|
|||||||
try {
|
try {
|
||||||
receiveData = JSON.parse(message.toString());
|
receiveData = JSON.parse(message.toString());
|
||||||
echo = receiveData.echo;
|
echo = receiveData.echo;
|
||||||
this.logger.logDebug('收到正向Websocket消息', receiveData);
|
this.logger.logDebug('[OneBot] [WebSocket Client] 收到正向Websocket消息', receiveData);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.checkStateAndReply<any>(OB11Response.error('json解析失败,请检查数据格式', 1400, echo));
|
this.checkStateAndReply<any>(OB11Response.error('json解析失败,请检查数据格式', 1400, echo));
|
||||||
}
|
}
|
||||||
|
@@ -11,6 +11,7 @@ import { LogWrapper } from '@/common/utils/log';
|
|||||||
import { OB11HeartbeatEvent } from '../event/meta/OB11HeartbeatEvent';
|
import { OB11HeartbeatEvent } from '../event/meta/OB11HeartbeatEvent';
|
||||||
import { IncomingMessage } from 'http';
|
import { IncomingMessage } from 'http';
|
||||||
import { ActionMap } from '@/onebot/action';
|
import { ActionMap } from '@/onebot/action';
|
||||||
|
import { LifeCycleSubType, OB11LifeCycleEvent } from '../event/meta/OB11LifeCycleEvent';
|
||||||
|
|
||||||
export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter {
|
export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter {
|
||||||
wsServer: WebSocketServer;
|
wsServer: WebSocketServer;
|
||||||
@@ -36,6 +37,7 @@ export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter {
|
|||||||
|
|
||||||
this.heartbeatInterval = heartbeatInterval;
|
this.heartbeatInterval = heartbeatInterval;
|
||||||
this.wsServer = new WebSocketServer({ port: port, host: ip });
|
this.wsServer = new WebSocketServer({ port: port, host: ip });
|
||||||
|
let core = coreContext;
|
||||||
this.wsServer.on('connection', async (wsClient, wsReq) => {
|
this.wsServer.on('connection', async (wsClient, wsReq) => {
|
||||||
if (!this.isOpen) {
|
if (!this.isOpen) {
|
||||||
wsClient.close();
|
wsClient.close();
|
||||||
@@ -43,9 +45,8 @@ export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter {
|
|||||||
}
|
}
|
||||||
//鉴权
|
//鉴权
|
||||||
this.authorize(token, wsClient, wsReq);
|
this.authorize(token, wsClient, wsReq);
|
||||||
|
this.connectEvent(core, wsClient);
|
||||||
wsClient.on('error', (err) => this.logger.log('[OneBot] [WebSocket Server] Client Error:', err.message));
|
wsClient.on('error', (err) => this.logger.log('[OneBot] [WebSocket Server] Client Error:', err.message));
|
||||||
|
|
||||||
wsClient.on('message', (message) => {
|
wsClient.on('message', (message) => {
|
||||||
this.handleMessage(wsClient, message).then().catch(this.logger.logError);
|
this.handleMessage(wsClient, message).then().catch(this.logger.logError);
|
||||||
});
|
});
|
||||||
@@ -62,6 +63,14 @@ export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter {
|
|||||||
});
|
});
|
||||||
}).on('error', (err) => this.logger.log('[OneBot] [WebSocket Server] Server Error:', err.message));
|
}).on('error', (err) => this.logger.log('[OneBot] [WebSocket Server] Server Error:', err.message));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
connectEvent(core: NapCatCore, wsClient: WebSocket) {
|
||||||
|
try {
|
||||||
|
this.checkStateAndReply<any>(new OB11LifeCycleEvent(core, LifeCycleSubType.CONNECT), wsClient);
|
||||||
|
} catch (e) {
|
||||||
|
this.logger.logError('[OneBot] [WebSocket Server] 发送生命周期失败', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onEvent<T extends OB11EmitEventContent>(event: T) {
|
onEvent<T extends OB11EmitEventContent>(event: T) {
|
||||||
this.wsClientsMutex.runExclusive(async () => {
|
this.wsClientsMutex.runExclusive(async () => {
|
||||||
@@ -82,7 +91,7 @@ export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter {
|
|||||||
}
|
}
|
||||||
const addressInfo = this.wsServer.address();
|
const addressInfo = this.wsServer.address();
|
||||||
this.logger.log('[OneBot] [WebSocket Server] Server Started', typeof (addressInfo) === 'string' ? addressInfo : addressInfo?.address + ':' + addressInfo?.port);
|
this.logger.log('[OneBot] [WebSocket Server] Server Started', typeof (addressInfo) === 'string' ? addressInfo : addressInfo?.address + ':' + addressInfo?.port);
|
||||||
|
|
||||||
this.isOpen = true;
|
this.isOpen = true;
|
||||||
this.registerHeartBeat();
|
this.registerHeartBeat();
|
||||||
}
|
}
|
||||||
|
@@ -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.7', 'napcat-update-button', 'secondary'),
|
SettingButton('V2.0.8', '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.7", "napcat-update-button", "secondary")
|
SettingButton("V2.0.8", "napcat-update-button", "secondary")
|
||||||
)
|
)
|
||||||
]),
|
]),
|
||||||
SettingList([
|
SettingList([
|
||||||
|
Reference in New Issue
Block a user