@@ -8,6 +8,7 @@ import axios from 'axios';
88import { ConfigController } from '../controllers/configController' ;
99import { MessageDTO , ReplyDTO , Context } from '../types' ;
1010import { MessageService } from './messageService' ;
11+ import { LoggerService } from './loggerService' ;
1112
1213interface PreloadedModules {
1314 [ key : string ] : any ;
@@ -38,15 +39,17 @@ const createSandbox = (contextOverrides: Record<string, any> = {}) => {
3839} ;
3940
4041export class PluginService {
41- private configController : ConfigController ;
42-
4342 constructor (
44- configController : ConfigController ,
45- messageService : MessageService ,
43+ private log : LoggerService ,
44+ private configController : ConfigController ,
45+ private messageService : MessageService ,
4646 ) {
47+ this . log = log ;
4748 this . configController = configController ;
48- preloadedModules . config_srv = configController ;
49- preloadedModules . reply_srv = messageService ;
49+ this . messageService = messageService ;
50+
51+ preloadedModules . config_srv = this . configController ;
52+ preloadedModules . reply_srv = this . messageService ;
5053 }
5154
5255 async checkPlugin (
@@ -162,6 +165,7 @@ export class PluginService {
162165 console : customConsole ,
163166 messages,
164167 require : ( module : string ) => {
168+ console . log ( 'Require:' , module ) ;
165169 if ( preloadedModules [ module ] ) {
166170 return preloadedModules [ module ] ;
167171 }
@@ -178,10 +182,12 @@ export class PluginService {
178182 vm . runInContext ( pluginCode , sandbox ) ;
179183
180184 if ( typeof sandbox . module . exports !== 'function' ) {
185+ this . log . error ( '插件格式错误,请检查是否导出函数' ) ;
181186 throw new Error ( 'Plugin does not export a function' ) ;
182187 }
183188
184189 if ( ! messages || messages . length === 0 ) {
190+ this . log . error ( '未提供消息给插件' ) ;
185191 throw new Error ( 'No messages provided to the plugin' ) ;
186192 }
187193
@@ -204,9 +210,15 @@ export class PluginService {
204210 return { data : data as ReplyDTO , consoleOutput } ;
205211 }
206212
213+ this . log . error ( '未返回有效响应' ) ;
214+
207215 throw new Error ( 'Plugin function did not return a valid response' ) ;
208216 } catch ( error : any ) {
209217 console . error ( 'Plugin execution error:' , error ) ;
218+
219+ this . log . error (
220+ `回复失败: ${ error instanceof Error ? error . message : String ( error ) } ` ,
221+ ) ;
210222 error . consoleOutput = consoleOutput ;
211223 throw error ;
212224 }
0 commit comments