mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
e77bcc1267 | ||
![]() |
9b458958b8 | ||
![]() |
35419ade29 | ||
![]() |
15bd2ee887 | ||
![]() |
9394bafa8e | ||
![]() |
94150a0c48 | ||
![]() |
8955fdfc23 | ||
![]() |
c13aa6a545 | ||
![]() |
c73b50bd4a |
@@ -4,7 +4,7 @@
|
||||
"name": "NapCat",
|
||||
"slug": "NapCat",
|
||||
"description": "OneBot v11 protocol implementation with NapCat logic",
|
||||
"version": "2.0.6",
|
||||
"version": "2.0.8",
|
||||
"icon": "./logo.png",
|
||||
"authors": [
|
||||
{
|
||||
|
@@ -2,7 +2,7 @@
|
||||
"name": "napcat",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"version": "2.0.6",
|
||||
"version": "2.0.8",
|
||||
"scripts": {
|
||||
"build:framework": "vite build --mode framework",
|
||||
"build:shell": "vite build --mode shell",
|
||||
|
@@ -2,7 +2,7 @@ import path, { dirname } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import fs from 'fs';
|
||||
|
||||
export const napcat_version = '2.0.6';
|
||||
export const napcat_version = '2.0.8';
|
||||
|
||||
export class NapCatPathWrapper {
|
||||
binaryPath: string;
|
||||
|
@@ -69,7 +69,7 @@ class GetGroupMemberInfo extends BaseAction<Payload, OB11GroupMember> {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Mlikiowa V2.0.6 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.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 {
|
||||
// Mlikiowa V2.0.6 Refactor Todo
|
||||
// Mlikiowa V2.0.8 Refactor Todo
|
||||
// _groupMembers.forEach(async item => {
|
||||
// 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());
|
||||
|
@@ -56,7 +56,7 @@ const _handlers: {
|
||||
if (atQQ === 'all') return SendMsgElementConstructor.at(coreContext, atQQ, atQQ, AtType.atAll, '全体成员');
|
||||
|
||||
// then the qq is a group member
|
||||
// Mlikiowa V2.0.6 Refactor Todo
|
||||
// Mlikiowa V2.0.8 Refactor Todo
|
||||
const uid = await coreContext.apis.UserApi.getUidByUinV2(atQQ);
|
||||
if (!uid) throw new Error('Get Uid Error');
|
||||
return SendMsgElementConstructor.at(coreContext, atQQ, uid, AtType.atUser, '');
|
||||
@@ -161,7 +161,7 @@ const _handlers: {
|
||||
} else {
|
||||
postData = data;
|
||||
}
|
||||
// Mlikiowa V2.0.6 Refactor Todo
|
||||
// Mlikiowa V2.0.8 Refactor Todo
|
||||
const signUrl = obContext.configLoader.configData.musicSignUrl;
|
||||
if (!signUrl) {
|
||||
if (data.type === 'qq') {
|
||||
|
@@ -408,7 +408,7 @@ export class OB11Constructor {
|
||||
return;
|
||||
}
|
||||
//log("group msg", msg);
|
||||
// Mlikiowa V2.0.6 Refactor Todo
|
||||
// Mlikiowa V2.0.8 Refactor Todo
|
||||
// if (msg.senderUin && msg.senderUin !== '0') {
|
||||
// const member = await getGroupMember(msg.peerUid, msg.senderUin);
|
||||
// if (member && member.cardName !== msg.sendMemberName) {
|
||||
|
@@ -6,6 +6,7 @@ import { ActionName } from '@/onebot/action/types';
|
||||
import { OB11Response } from '@/onebot/action/OB11Response';
|
||||
import { LogWrapper } from '@/common/utils/log';
|
||||
import { ActionMap } from '@/onebot/action';
|
||||
import { LifeCycleSubType, OB11LifeCycleEvent } from '../event/meta/OB11LifeCycleEvent';
|
||||
|
||||
export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter {
|
||||
isClosed: boolean = false;
|
||||
@@ -76,14 +77,22 @@ export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter {
|
||||
'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.handleMessage(data);
|
||||
});
|
||||
this.connection.once('close', () => {
|
||||
if (!isClosedByError) {
|
||||
this.logger.logError(`反向WebSocket (${this.url}) 连接意外关闭`);
|
||||
this.logger.logError(`在 ${Math.floor(this.reconnectIntervalInMillis / 1000)} 秒后尝试重新连接`);
|
||||
this.logger.logError(`[OneBot] [WebSocket Client] 反向WebSocket (${this.url}) 连接意外关闭`);
|
||||
this.logger.logError(`[OneBot] [WebSocket Client] 在 ${Math.floor(this.reconnectIntervalInMillis / 1000)} 秒后尝试重新连接`);
|
||||
if (!this.isClosed) {
|
||||
this.connection = null;
|
||||
setTimeout(() => this.tryConnect(), this.reconnectIntervalInMillis);
|
||||
@@ -92,8 +101,8 @@ export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter {
|
||||
});
|
||||
this.connection.on('error', (err) => {
|
||||
isClosedByError = true;
|
||||
this.logger.logError(`反向WebSocket (${this.url}) 连接错误`, err);
|
||||
this.logger.logError(`在 ${Math.floor(this.reconnectIntervalInMillis / 1000)} 秒后尝试重新连接`);
|
||||
this.logger.logError(`[OneBot] [WebSocket Client] 反向WebSocket (${this.url}) 连接错误`, err);
|
||||
this.logger.logError(`[OneBot] [WebSocket Client] 在 ${Math.floor(this.reconnectIntervalInMillis / 1000)} 秒后尝试重新连接`);
|
||||
if (!this.isClosed) {
|
||||
this.connection = null;
|
||||
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) {
|
||||
let receiveData: { action: ActionName, params?: any, echo?: any } = { action: ActionName.Unknown, params: {} };
|
||||
let echo = undefined;
|
||||
@@ -109,7 +124,7 @@ export class OB11ActiveWebSocketAdapter implements IOB11NetworkAdapter {
|
||||
try {
|
||||
receiveData = JSON.parse(message.toString());
|
||||
echo = receiveData.echo;
|
||||
this.logger.logDebug('收到正向Websocket消息', receiveData);
|
||||
this.logger.logDebug('[OneBot] [WebSocket Client] 收到正向Websocket消息', receiveData);
|
||||
} catch (e) {
|
||||
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 { IncomingMessage } from 'http';
|
||||
import { ActionMap } from '@/onebot/action';
|
||||
import { LifeCycleSubType, OB11LifeCycleEvent } from '../event/meta/OB11LifeCycleEvent';
|
||||
|
||||
export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter {
|
||||
wsServer: WebSocketServer;
|
||||
@@ -36,6 +37,7 @@ export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter {
|
||||
|
||||
this.heartbeatInterval = heartbeatInterval;
|
||||
this.wsServer = new WebSocketServer({ port: port, host: ip });
|
||||
let core = coreContext;
|
||||
this.wsServer.on('connection', async (wsClient, wsReq) => {
|
||||
if (!this.isOpen) {
|
||||
wsClient.close();
|
||||
@@ -43,9 +45,8 @@ export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter {
|
||||
}
|
||||
//鉴权
|
||||
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('message', (message) => {
|
||||
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));
|
||||
}
|
||||
|
||||
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) {
|
||||
this.wsClientsMutex.runExclusive(async () => {
|
||||
@@ -82,7 +91,7 @@ export class OB11PassiveWebSocketAdapter implements IOB11NetworkAdapter {
|
||||
}
|
||||
const addressInfo = this.wsServer.address();
|
||||
this.logger.log('[OneBot] [WebSocket Server] Server Started', typeof (addressInfo) === 'string' ? addressInfo : addressInfo?.address + ':' + addressInfo?.port);
|
||||
|
||||
|
||||
this.isOpen = true;
|
||||
this.registerHeartBeat();
|
||||
}
|
||||
|
@@ -175,10 +175,10 @@ export async function NCoreInitShell() {
|
||||
.then(result => {
|
||||
if (result.loginErrorInfo.errMsg) {
|
||||
logger.logError('快速登录错误:', result.loginErrorInfo.errMsg);
|
||||
reject();
|
||||
loginService.getQRCodePicture();
|
||||
}
|
||||
})
|
||||
.catch(e => reject(e));
|
||||
.catch();
|
||||
}, 1000);
|
||||
} else {
|
||||
logger.log('没有 -q 指令指定快速登录,或未曾登录过这个 QQ,将使用二维码登录方式');
|
||||
|
@@ -30,7 +30,7 @@ async function onSettingWindowCreated(view: Element) {
|
||||
SettingItem(
|
||||
'<span id="napcat-update-title">Napcat</span>',
|
||||
undefined,
|
||||
SettingButton('V2.0.6', 'napcat-update-button', 'secondary'),
|
||||
SettingButton('V2.0.8', 'napcat-update-button', 'secondary'),
|
||||
),
|
||||
]),
|
||||
SettingList([
|
||||
|
@@ -164,7 +164,7 @@ async function onSettingWindowCreated(view) {
|
||||
SettingItem(
|
||||
'<span id="napcat-update-title">Napcat</span>',
|
||||
void 0,
|
||||
SettingButton("V2.0.6", "napcat-update-button", "secondary")
|
||||
SettingButton("V2.0.8", "napcat-update-button", "secondary")
|
||||
)
|
||||
]),
|
||||
SettingList([
|
||||
|
Reference in New Issue
Block a user