@@ -58,66 +58,13 @@ export class MessageService {
5858 this . isUseGptReply = isUseGptReply ;
5959 }
6060
61- /**
62- * 获取回复消息
63- * @param ctx
64- * @param messages
65- * @returns
66- */
67- public async getReply (
68- ctx : Context ,
69- messages : MessageDTO [ ] ,
70- ) : Promise < ReplyDTO > {
71- const cfg = await this . configController . get ( ctx ) ;
72-
73- // 提取消息中的信息
74- await this . extractMsgInfo ( cfg , ctx , messages ) ;
75-
76- // 先检查是否存在用户的消息
77- const lastUserMsg = messages
78- . slice ( )
79- . reverse ( )
80- . find ( ( msg ) => msg . role === 'OTHER' ) ;
81- if ( ! lastUserMsg ) {
82- return {
83- type : 'TEXT' ,
84- content : cfg . default_reply ,
85- } ;
86- }
87-
88- // 先等待随机时间
89- await new Promise ( ( resolve ) => {
90- const min = cfg . reply_speed ; // 5 seconds
91- const max = cfg . reply_random_speed + cfg . reply_speed ; // 10 seconds
92- const randomTime = min + Math . random ( ) * ( max - min ) ;
93- setTimeout ( resolve , randomTime * 1000 ) ;
94- } ) ;
95-
96- // 再检查是否使用关键词匹配
97- if ( this . isKeywordMatch ) {
98- const data = await this . matchKeyword ( ctx , lastUserMsg ) ;
99- if ( data ) return data ;
100- }
101-
102- // 最后检查是否使用 GPT 生成回复
103- if ( this . isUseGptReply ) {
104- const data = await this . getLLMResponse ( cfg , ctx , messages ) ;
105- if ( data ) return data ;
106- }
107-
108- return {
109- type : 'TEXT' ,
110- content : cfg . default_reply ,
111- } ;
112- }
113-
11461 /**
11562 * 匹配关键词
11663 * @param ctx
11764 * @param message
11865 * @returns
11966 */
120- private async matchKeyword (
67+ public async matchKeyword (
12168 ctx : Context ,
12269 message : MessageDTO ,
12370 ) : Promise < ReplyDTO | null > {
@@ -167,7 +114,7 @@ export class MessageService {
167114 * @param messages
168115 * @returns
169116 */
170- private async getLLMResponse (
117+ public async getLLMResponse (
171118 cfg : Config ,
172119 ctx : Context ,
173120 messages : MessageDTO [ ] ,
@@ -262,7 +209,11 @@ export class MessageService {
262209 * @param messages
263210 * @returns
264211 */
265- async extractMsgInfo ( cfg : Config , ctx : Context , messages : MessageDTO [ ] ) {
212+ public async extractMsgInfo (
213+ cfg : Config ,
214+ ctx : Context ,
215+ messages : MessageDTO [ ] ,
216+ ) {
266217 if ( ! cfg . extract_phone && ! cfg . extract_product ) return ;
267218 if ( cfg . save_path === '' ) return ;
268219
0 commit comments