@@ -4,9 +4,9 @@ import { createWindow } from './helpers';
44import { summarize } from './summarize' ;
55import { getAllDirs } from './helpers/getAllDirs' ;
66import { getConfig , setConfig } from './config' ;
7- import { botStatus , sendAudio , sendImage , sendText , startBot } from './startBot' ;
7+ import { botAccount , botStatus , logoutBot , sendAudio , sendImage , sendText , startBot } from './startBot' ;
88import path from 'path' ;
9- import { BASE_PATH , delay , PUBLIC_PATH , saveData } from './util' ;
9+ import { BASE_PATH , delay , getChatHistoryFromFile , PUBLIC_PATH , saveData } from './util' ;
1010import fs from 'fs' ;
1111
1212const isProd : boolean = process . env . NODE_ENV === 'production' ;
@@ -38,8 +38,25 @@ if (isProd) {
3838 ipcMain . on ( 'get-bot-status' , ( event , title ) => {
3939 mainWindow . webContents . send ( 'bot-status-reply' , {
4040 status : botStatus ,
41+ account : botAccount ,
4142 } ) ;
4243 } ) ;
44+ ipcMain . on ( 'get-chat-content' , ( event , args ) => {
45+ const date = args . date ;
46+ const roomName = args . roomName ;
47+ const filePath = path . join ( BASE_PATH , date , roomName ) ;
48+ const chats = getChatHistoryFromFile ( filePath ) ;
49+
50+ mainWindow . webContents . send ( 'chat-content-replay' , {
51+ date,
52+ roomName,
53+ chats,
54+ } ) ;
55+
56+ } ) ;
57+ ipcMain . on ( 'logout-bot' , ( event , title ) => {
58+ logoutBot ( ) ;
59+ } ) ;
4360 ipcMain . on ( 'summarize' , ( event , { dateDir, chatFileName } ) => {
4461 const summarizeEvent = summarize ( path . join ( BASE_PATH , dateDir , chatFileName ) ) ;
4562 summarizeEvent . addListener ( 'update' , ( info ) => {
@@ -86,41 +103,48 @@ if (isProd) {
86103 ipcMain . on ( 'send-summarize' , async ( e , { dateDir, chatFileName } ) => {
87104 await sendImage (
88105 chatFileName . replace ( '.txt' , '' ) ,
89- path . join ( BASE_PATH , dateDir , chatFileName . replace ( '.txt' , ' 的今日群聊总结.png' ) )
106+ path . join ( BASE_PATH , dateDir , chatFileName . replace ( '.txt' , ' 的今日群聊总结.png' ) ) ,
90107 ) ;
91- await delay ( 2000 ) ;
108+ await delay ( 5000 ) ;
92109 await sendAudio (
93110 chatFileName . replace ( '.txt' , '' ) ,
94- path . join ( BASE_PATH , dateDir , chatFileName . replace ( '.txt' , ' 的今日群聊总结.mp3' ) )
111+ path . join ( BASE_PATH , dateDir , chatFileName . replace ( '.txt' , ' 的今日群聊总结.mp3' ) ) ,
95112 ) ;
96- await delay ( 2000 ) ;
113+ await delay ( 5000 ) ;
97114 await sendText (
98115 chatFileName . replace ( '.txt' , '' ) ,
99116 getConfig ( ) . LAST_MESSAGE ||
100- '主人们,智囊 AI 为您奉上今日群聊总结,祝您用餐愉快!由开源项目 https://github.com/aoao-eth/wechat-ai-summarize-bot 生成'
117+ '主人们,智囊 AI 为您奉上今日群聊总结,祝您用餐愉快!由开源项目 https://github.com/aoao-eth/wechat-ai-summarize-bot 生成' ,
101118 ) ;
102119
103120 try {
104121 const file = path . join ( BASE_PATH , dateDir , chatFileName . replace ( '.txt' , ' 的今日群聊总结.txt' ) ) ;
105122 const summarized = fs . readFileSync ( file ) . toString ( ) ;
106123 const 评价 = summarized . match ( / 整 体 评 价 .* ?\n / ) ;
124+ const 我的建议 = summarized . match ( / 我 的 建 议 .* ?\n / ) ;
107125 const 活跃发言者 = summarized . match ( / 今 日 最 活 跃 的 前 五 名 发 言 者 .* ?\n / ) ;
108126 if ( 活跃发言者 ) {
109- await delay ( 2000 ) ;
127+ await delay ( 5000 ) ;
110128 await sendText ( chatFileName . replace ( '.txt' , '' ) , 活跃发言者 [ 0 ] ) ;
111129 }
112130 if ( 评价 ) {
113- await delay ( 2000 ) ;
114- await sendText ( chatFileName . replace ( '.txt' , '' ) , 评价 [ 0 ] ) ;
131+ await delay ( 5000 ) ;
132+ await sendText ( chatFileName . replace ( '.txt' , '' ) , 评价 [ 0 ] + ( 我的建议 ? 我的建议 [ 0 ] : '' ) ) ;
115133 }
116- } catch ( e ) { }
134+ } catch ( e ) {
135+ }
117136
118137 mainWindow . webContents . send ( 'toast' , `发送成功` ) ;
119138 saveData ( dateDir , chatFileName . replace ( '.txt' , '' ) , {
120139 sended : true ,
121140 send_time : new Date ( ) . getTime ( ) ,
122141 } ) ;
123142 } ) ;
143+ ipcMain . on ( 'send-chat-content' , ( event , arg ) => {
144+ const roomName = arg . roomName ;
145+ const content = arg . content ;
146+ sendText ( roomName , content ) ;
147+ } ) ;
124148} ) ( ) ;
125149
126150app . on ( 'window-all-closed' , ( ) => {
0 commit comments