File tree Expand file tree Collapse file tree
napcat-onebot/action/packet Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ export class NTQQPacketApi {
3636 } )
3737 . catch ( ( err ) => {
3838 this . logger . logError ( err ) ;
39- this . errStack . push ( err ) ;
39+ this . pushError ( err ) ;
4040 return false ;
4141 } ) ) && this . pkt ?. available ;
4242 }
@@ -46,7 +46,15 @@ export class NTQQPacketApi {
4646 }
4747
4848 get clientLogStack ( ) {
49- return this . pkt ?. clientLogStack + '\n' + this . errStack . join ( '\n' ) ;
49+ return [ this . pkt ?. clientLogStack , ...this . errStack ] . filter ( Boolean ) . join ( '\n' ) ;
50+ }
51+
52+ private pushError ( error : unknown ) {
53+ if ( error instanceof Error ) {
54+ this . errStack . push ( error . stack || error . message ) ;
55+ return ;
56+ }
57+ this . errStack . push ( String ( error ) ) ;
5058 }
5159
5260 async InitSendPacket ( qqVer : string ) {
@@ -67,10 +75,17 @@ export class NTQQPacketApi {
6775 }
6876 this . pkt = new PacketClientSession ( this . core ) ;
6977 await this . pkt . init ( process . pid , table . recv , table . send ) ;
78+ if ( ! this . pkt . available ) {
79+ const err = '[Core] [Packet] NativePacketClient 初始化失败,PacketBackend 发包能力不可用!' ;
80+ this . logger . logError ( err ) ;
81+ this . errStack . push ( err ) ;
82+ return false ;
83+ }
7084 try {
7185 await this . pkt . operation . FetchRkey ( 3000 ) ;
7286 } catch ( error ) {
7387 this . logger . logError ( '测试Packet状态异常' , error ) ;
88+ this . pushError ( error ) ;
7489 return false ;
7590 }
7691 return true ;
Original file line number Diff line number Diff line change @@ -39,12 +39,17 @@ export class NativePacketClient {
3939
4040 async init ( _pid : number , recv : string , send : string ) : Promise < void > {
4141 const isNewQQ = this . napcore . basicInfo . requireMinNTQQBuild ( '40824' ) ;
42- if ( isNewQQ ) {
43- const success = this . napi2nativeLoader . initHook ( send , recv ) ;
44- if ( success ) {
45- this . available = true ;
46- }
42+ if ( ! isNewQQ ) {
43+ this . logStack . pushLogWarn ( '[PacketClient] 当前 QQ 版本低于 NativePacketClient 要求,跳过 Hook 初始化' ) ;
44+ return ;
4745 }
46+ const success = this . napi2nativeLoader . initHook ( send , recv ) ;
47+ if ( success ) {
48+ this . available = true ;
49+ this . logStack . pushLogInfo ( `[PacketClient] NativePacketClient Hook 初始化成功 platform=${ process . platform } .${ process . arch } ` ) ;
50+ return ;
51+ }
52+ this . logStack . pushLogError ( `[PacketClient] NativePacketClient Hook 初始化失败 platform=${ process . platform } .${ process . arch } send=${ send } recv=${ recv } ` ) ;
4853 }
4954
5055 async sendPacket (
Original file line number Diff line number Diff line change @@ -4,14 +4,31 @@ import { Type } from '@sinclair/typebox';
44
55export abstract class GetPacketStatusDepends < PT , RT > extends OneBotAction < PT , RT > {
66 protected override async check ( payload : PT ) : Promise < BaseCheckResult > {
7+ const schemaResult = await super . check ( payload ) ;
8+ if ( ! schemaResult . valid ) return schemaResult ;
79 if ( ! this . core . apis . PacketApi . packetStatus ) {
810 return {
911 valid : false ,
1012 message : 'packetBackend不可用,请参照文档 https://napneko.github.io/config/advanced 和启动日志检查packetBackend状态或进行配置!' +
1113 '错误堆栈信息:' + this . core . apis . PacketApi . clientLogStack ,
1214 } ;
1315 }
14- return await super . check ( payload ) ;
16+ return { valid : true } ;
17+ }
18+ }
19+
20+ export abstract class PacketSendAvailableDepends < PT , RT > extends OneBotAction < PT , RT > {
21+ protected override async check ( payload : PT ) : Promise < BaseCheckResult > {
22+ const schemaResult = await super . check ( payload ) ;
23+ if ( ! schemaResult . valid ) return schemaResult ;
24+ if ( ! this . core . apis . PacketApi . available ) {
25+ return {
26+ valid : false ,
27+ message : 'packetBackend发包能力不可用,请参照文档 https://napneko.github.io/config/advanced 和启动日志检查packetBackend状态或进行配置!' +
28+ '错误堆栈信息:' + this . core . apis . PacketApi . clientLogStack ,
29+ } ;
30+ }
31+ return { valid : true } ;
1532 }
1633}
1734
Original file line number Diff line number Diff line change 11import { ActionName } from '@/napcat-onebot/action/router' ;
2- import { GetPacketStatusDepends } from '@/napcat-onebot/action/packet/GetPacketStatus' ;
2+ import { PacketSendAvailableDepends } from '@/napcat-onebot/action/packet/GetPacketStatus' ;
33import { Static , Type } from '@sinclair/typebox' ;
44
55import { PacketActionsExamples } from '../example/PacketActionsExamples' ;
@@ -11,7 +11,7 @@ export const SendPokePayloadSchema = Type.Object({
1111} ) ;
1212
1313export type SendPokePayload = Static < typeof SendPokePayloadSchema > ;
14- export class SendPokeBase extends GetPacketStatusDepends < SendPokePayload , void > {
14+ export class SendPokeBase extends PacketSendAvailableDepends < SendPokePayload , void > {
1515 override payloadSchema = SendPokePayloadSchema ;
1616 override returnSchema = Type . Null ( ) ;
1717 override actionSummary = '发送戳一戳' ;
You can’t perform that action at this time.
0 commit comments