feat: implement chat merging and logging in Safew

- Introduced a new function `mergeAndLog` in the Watcher to handle merging Safew chats and logging newly discovered chats.
- Added a test `TestNewSafewChatsSkipsKnownIDs` to ensure that known chat IDs are skipped during the merging process.
- Enhanced the polling mechanism to improve chat management and reduce duplicates.
This commit is contained in:
2026-08-15 01:10:35 +08:00
parent e369f398d8
commit 5e783adf7a
2 changed files with 50 additions and 1 deletions
+12
View File
@@ -115,6 +115,18 @@ func TestEnsurePollsInBackground(t *testing.T) {
w.Stop()
}
func TestNewSafewChatsSkipsKnownIDs(t *testing.T) {
known := map[string]struct{}{"1": {}}
got := newSafewChats(known, []adapter.SafewChat{
{ID: "1", Title: "old"},
{ID: "2", Title: "测试AI", Type: "group"},
{ID: "2", Title: "dup"},
})
if len(got) != 1 || got[0].ID != "2" || got[0].Title != "测试AI" {
t.Fatalf("%#v", got)
}
}
func TestPollConflictIsRetryable(t *testing.T) {
err := errors.New("safew getUpdates status 400: BAD_REQUEST: Conflict: terminated by other getUpdates request; make sure that only one bot instance is running")
if !isGetUpdatesConflict(err) {