@@ -152,23 +152,61 @@ func (m *AutoRecapService) sendChatHistoriesRecapTimeCapsuleHandler(
152
152
}
153
153
154
154
func (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
+ )
156
160
157
161
chat , err := m .botService .GetChat (tgbotapi.ChatInfoConfig {
158
162
ChatConfig : tgbotapi.ChatConfig {
159
163
ChatID : chatID ,
160
164
},
161
165
})
162
166
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
+
164
174
return
165
175
}
166
176
167
177
chatType := telegram .ChatType (chat .Type )
168
178
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 )
170
202
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
+
172
210
return
173
211
}
174
212
if len (histories ) <= 5 {
@@ -180,25 +218,49 @@ func (m *AutoRecapService) summarize(chatID int64, options *ent.TelegramChatReca
180
218
181
219
logID , summarizations , err := m .chathistories .SummarizeChatHistories (chatID , chatType , histories )
182
220
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
+
184
228
return
185
229
}
186
230
187
231
counts , err := m .chathistories .FindFeedbackRecapsReactionCountsForChatIDAndLogID (chatID , logID )
188
232
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
+
190
240
return
191
241
}
192
242
193
243
inlineKeyboardMarkup , err := m .chathistories .NewVoteRecapInlineKeyboardMarkup (m .botService .Bot (), chatID , logID , counts .UpVotes , counts .DownVotes , counts .Lmao )
194
244
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
+
196
253
return
197
254
}
198
255
199
256
summarizations = lo .Filter (summarizations , func (item string , _ int ) bool { return item != "" })
200
257
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
+
202
264
return
203
265
}
204
266
@@ -245,6 +307,8 @@ func (m *AutoRecapService) summarize(chatID int64, options *ent.TelegramChatReca
245
307
zap .String ("status" , member .Status ),
246
308
zap .Int64 ("chat_id" , chatID ),
247
309
zap .Int64 ("user_id" , subscriber .UserID ),
310
+ zap .String ("module" , "autorecap" ),
311
+ zap .Int ("auto_recap_rates" , options .AutoRecapRatesPerDay ),
248
312
)
249
313
250
314
_ , _ , 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
257
321
zap .Int64 ("user_id" , subscriber .UserID ),
258
322
zap .Int ("iter" , iter ),
259
323
zap .Int ("max_iter" , 100 ),
324
+ zap .String ("module" , "autorecap" ),
325
+ zap .Int ("auto_recap_rates" , options .AutoRecapRatesPerDay ),
260
326
)
261
327
262
328
return err
@@ -265,15 +331,24 @@ func (m *AutoRecapService) summarize(chatID int64, options *ent.TelegramChatReca
265
331
return nil
266
332
})
267
333
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
+ )
269
339
}
270
340
271
341
msg := tgbotapi .NewMessage (subscriber .UserID , fmt .Sprintf ("由于您已不再是 <b>%s</b> 的成员,因此已自动帮您取消了您所订阅的聊天记录回顾。" , tgbot .EscapeHTMLSymbols (chatTitle )))
272
342
msg .ParseMode = tgbotapi .ModeHTML
273
343
274
344
_ , err = m .botService .Send (msg )
275
345
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
+ )
277
352
}
278
353
279
354
continue
@@ -313,7 +388,12 @@ func (m *AutoRecapService) summarize(chatID int64, options *ent.TelegramChatReca
313
388
314
389
inlineKeyboardMarkup , err := m .chathistories .NewVoteRecapWithUnsubscribeInlineKeyboardMarkup (m .botService .Bot (), chatID , chatTitle , targetChat .chatID , logID , counts .UpVotes , counts .DownVotes , counts .Lmao )
315
390
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
+
317
397
continue
318
398
}
319
399
@@ -325,7 +405,11 @@ func (m *AutoRecapService) summarize(chatID int64, options *ent.TelegramChatReca
325
405
326
406
_ , err = m .botService .Send (msg )
327
407
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
+ )
329
413
}
330
414
}
331
415
}
0 commit comments