@@ -152,23 +152,61 @@ func (m *AutoRecapService) sendChatHistoriesRecapTimeCapsuleHandler(
152152}
153153
154154func (m * AutoRecapService ) summarize (chatID int64 , options * ent.TelegramChatRecapsOptions , subscribers []* ent.TelegramChatAutoRecapsSubscribers ) {
155- m .logger .Info ("generating chat histories recap for chat" , zap .Int64 ("chat_id" , chatID ))
155+ m .logger .Info ("generating chat histories recap for chat" ,
156+ zap .Int64 ("chat_id" , chatID ),
157+ zap .String ("module" , "autorecap" ),
158+ zap .Int ("auto_recap_rates" , options .AutoRecapRatesPerDay ),
159+ )
156160
157161 chat , err := m .botService .GetChat (tgbotapi.ChatInfoConfig {
158162 ChatConfig : tgbotapi.ChatConfig {
159163 ChatID : chatID ,
160164 },
161165 })
162166 if err != nil {
163- m .logger .Error ("failed to get chat" , zap .Error (err ), zap .Int64 ("chat_id" , chatID ))
167+ m .logger .Error ("failed to get chat" ,
168+ zap .Int64 ("chat_id" , chatID ),
169+ zap .String ("module" , "autorecap" ),
170+ zap .Int ("auto_recap_rates" , options .AutoRecapRatesPerDay ),
171+ zap .Error (err ),
172+ )
173+
164174 return
165175 }
166176
167177 chatType := telegram .ChatType (chat .Type )
168178
169- histories , err := m .chathistories .FindLastSixHourChatHistories (chatID )
179+ mAutoRecapRatesPerDayHours := map [int ]int {
180+ 4 : 6 ,
181+ 3 : 8 ,
182+ 2 : 12 ,
183+ }
184+
185+ hours , ok := mAutoRecapRatesPerDayHours [options .AutoRecapRatesPerDay ]
186+ if ! ok {
187+ hours = 6
188+ }
189+
190+ mFindChatHistoriesHoursBefore := map [int ]func (chatID int64 ) ([]* ent.ChatHistories , error ){
191+ 6 : m .chathistories .FindLast6HourChatHistories ,
192+ 8 : m .chathistories .FindLast8HourChatHistories ,
193+ 12 : m .chathistories .FindLast12HourChatHistories ,
194+ }
195+
196+ findChatHistories , ok := mFindChatHistoriesHoursBefore [hours ]
197+ if ! ok {
198+ findChatHistories = m .chathistories .FindLast6HourChatHistories
199+ }
200+
201+ histories , err := findChatHistories (chatID )
170202 if err != nil {
171- m .logger .Error ("failed to find last six hour chat histories" , zap .Error (err ), zap .Int64 ("chat_id" , chatID ))
203+ m .logger .Error (fmt .Sprintf ("failed to find last %d hour chat histories" , hours ),
204+ zap .Int64 ("chat_id" , chatID ),
205+ zap .String ("module" , "autorecap" ),
206+ zap .Int ("auto_recap_rates" , options .AutoRecapRatesPerDay ),
207+ zap .Error (err ),
208+ )
209+
172210 return
173211 }
174212 if len (histories ) <= 5 {
@@ -180,25 +218,49 @@ func (m *AutoRecapService) summarize(chatID int64, options *ent.TelegramChatReca
180218
181219 logID , summarizations , err := m .chathistories .SummarizeChatHistories (chatID , chatType , histories )
182220 if err != nil {
183- m .logger .Error ("failed to summarize last six hour chat histories" , zap .Error (err ), zap .Int64 ("chat_id" , chatID ))
221+ m .logger .Error ("failed to summarize last six hour chat histories" ,
222+ zap .Int64 ("chat_id" , chatID ),
223+ zap .String ("module" , "autorecap" ),
224+ zap .Int ("auto_recap_rates" , options .AutoRecapRatesPerDay ),
225+ zap .Error (err ),
226+ )
227+
184228 return
185229 }
186230
187231 counts , err := m .chathistories .FindFeedbackRecapsReactionCountsForChatIDAndLogID (chatID , logID )
188232 if err != nil {
189- m .logger .Error ("failed to find feedback recaps votes for chat" , zap .Error (err ), zap .Int64 ("chat_id" , chatID ))
233+ m .logger .Error ("failed to find feedback recaps votes for chat" ,
234+ zap .Int64 ("chat_id" , chatID ),
235+ zap .String ("module" , "autorecap" ),
236+ zap .Int ("auto_recap_rates" , options .AutoRecapRatesPerDay ),
237+ zap .Error (err ),
238+ )
239+
190240 return
191241 }
192242
193243 inlineKeyboardMarkup , err := m .chathistories .NewVoteRecapInlineKeyboardMarkup (m .botService .Bot (), chatID , logID , counts .UpVotes , counts .DownVotes , counts .Lmao )
194244 if err != nil {
195- m .logger .Error ("failed to create vote recap inline keyboard markup" , zap .Error (err ), zap .Int64 ("chat_id" , chatID ), zap .String ("log_id" , logID .String ()))
245+ m .logger .Error ("failed to create vote recap inline keyboard markup" ,
246+ zap .Int64 ("chat_id" , chatID ),
247+ zap .String ("log_id" , logID .String ()),
248+ zap .String ("module" , "autorecap" ),
249+ zap .Int ("auto_recap_rates" , options .AutoRecapRatesPerDay ),
250+ zap .Error (err ),
251+ )
252+
196253 return
197254 }
198255
199256 summarizations = lo .Filter (summarizations , func (item string , _ int ) bool { return item != "" })
200257 if len (summarizations ) == 0 {
201- m .logger .Warn ("summarization is empty" , zap .Int64 ("chat_id" , chatID ))
258+ m .logger .Warn ("summarization is empty" ,
259+ zap .Int64 ("chat_id" , chatID ),
260+ zap .String ("module" , "autorecap" ),
261+ zap .Int ("auto_recap_rates" , options .AutoRecapRatesPerDay ),
262+ )
263+
202264 return
203265 }
204266
@@ -245,6 +307,8 @@ func (m *AutoRecapService) summarize(chatID int64, options *ent.TelegramChatReca
245307 zap .String ("status" , member .Status ),
246308 zap .Int64 ("chat_id" , chatID ),
247309 zap .Int64 ("user_id" , subscriber .UserID ),
310+ zap .String ("module" , "autorecap" ),
311+ zap .Int ("auto_recap_rates" , options .AutoRecapRatesPerDay ),
248312 )
249313
250314 _ , _ , err := lo .AttemptWithDelay (1000 , time .Minute , func (iter int , _ time.Duration ) error {
@@ -257,6 +321,8 @@ func (m *AutoRecapService) summarize(chatID int64, options *ent.TelegramChatReca
257321 zap .Int64 ("user_id" , subscriber .UserID ),
258322 zap .Int ("iter" , iter ),
259323 zap .Int ("max_iter" , 100 ),
324+ zap .String ("module" , "autorecap" ),
325+ zap .Int ("auto_recap_rates" , options .AutoRecapRatesPerDay ),
260326 )
261327
262328 return err
@@ -265,15 +331,24 @@ func (m *AutoRecapService) summarize(chatID int64, options *ent.TelegramChatReca
265331 return nil
266332 })
267333 if err != nil {
268- m .logger .Error ("failed to unsubscribe to auto recaps" , zap .Error (err ), zap .Int64 ("chat_id" , chatID ))
334+ m .logger .Error ("failed to unsubscribe to auto recaps" ,
335+ zap .Int64 ("chat_id" , chatID ),
336+ zap .Int ("auto_recap_rates" , options .AutoRecapRatesPerDay ),
337+ zap .Error (err ),
338+ )
269339 }
270340
271341 msg := tgbotapi .NewMessage (subscriber .UserID , fmt .Sprintf ("由于您已不再是 <b>%s</b> 的成员,因此已自动帮您取消了您所订阅的聊天记录回顾。" , tgbot .EscapeHTMLSymbols (chatTitle )))
272342 msg .ParseMode = tgbotapi .ModeHTML
273343
274344 _ , err = m .botService .Send (msg )
275345 if err != nil {
276- m .logger .Error ("failed to send the auto un-subscription message" , zap .Error (err ), zap .Int64 ("user_id" , subscriber .UserID ), zap .Int64 ("chat_id" , chatID ))
346+ m .logger .Error ("failed to send the auto un-subscription message" ,
347+ zap .Int64 ("user_id" , subscriber .UserID ),
348+ zap .Int64 ("chat_id" , chatID ),
349+ zap .Int ("auto_recap_rates" , options .AutoRecapRatesPerDay ),
350+ zap .Error (err ),
351+ )
277352 }
278353
279354 continue
@@ -313,7 +388,12 @@ func (m *AutoRecapService) summarize(chatID int64, options *ent.TelegramChatReca
313388
314389 inlineKeyboardMarkup , err := m .chathistories .NewVoteRecapWithUnsubscribeInlineKeyboardMarkup (m .botService .Bot (), chatID , chatTitle , targetChat .chatID , logID , counts .UpVotes , counts .DownVotes , counts .Lmao )
315390 if err != nil {
316- m .logger .Error ("failed to assign callback query data" , zap .Error (err ), zap .Int64 ("chat_id" , chatID ))
391+ m .logger .Error ("failed to assign callback query data" ,
392+ zap .Int64 ("chat_id" , chatID ),
393+ zap .Int ("auto_recap_rates" , options .AutoRecapRatesPerDay ),
394+ zap .Error (err ),
395+ )
396+
317397 continue
318398 }
319399
@@ -325,7 +405,11 @@ func (m *AutoRecapService) summarize(chatID int64, options *ent.TelegramChatReca
325405
326406 _ , err = m .botService .Send (msg )
327407 if err != nil {
328- m .logger .Error ("failed to send chat histories recap" , zap .Error (err ), zap .Int64 ("chat_id" , chatID ))
408+ m .logger .Error ("failed to send chat histories recap" ,
409+ zap .Int64 ("chat_id" , chatID ),
410+ zap .Int ("auto_recap_rates" , options .AutoRecapRatesPerDay ),
411+ zap .Error (err ),
412+ )
329413 }
330414 }
331415 }
0 commit comments