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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user