Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 调整自动清理群聊的间隔时间单位,同时不清理从未发言过的群防止新加群被立即清理 #354

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions dice/dice.go
Original file line number Diff line number Diff line change
Expand Up @@ -721,8 +721,9 @@ func (d *Dice) ResetQuitInactiveCron() {
if d.QuitInactiveThreshold > 0 {
var err error
d.quitInactiveCronEntry, err = dm.Cron.AddFunc("0 4 * * *", func() {
thr := time.Now().Add(-d.QuitInactiveThreshold)
hint := thr.Add(d.QuitInactiveThreshold / 10) // 进入退出判定线的9/10开始提醒
threshold := d.QuitInactiveThreshold * time.Second
thr := time.Now().Add(-threshold)
hint := thr.Add(threshold / 10) // 进入退出判定线的9/10开始提醒
d.ImSession.QuitInactiveGroup(thr, hint)
})
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions dice/im_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,10 @@ func (s *IMSession) QuitInactiveGroup(threshold, hint time.Time) {
if strings.HasPrefix(grp.GroupID, "PG-") {
continue
}
if grp.RecentDiceSendTime == 0 {
// 防止骰子从未发言过的新加群被立即清理掉
continue
}
last := time.Unix(grp.RecentDiceSendTime, 0)
if last.Before(threshold) {
match := platformRE.FindStringSubmatch(grp.GroupID)
Expand Down