From 0f10aa45088f09631657ae4e323fe14e2a982e5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E5=90=83=E7=82=B9=E8=8B=B9=E6=9E=9C?= <73388495+eatmoreapple@users.noreply.github.com> Date: Fri, 13 Jan 2023 12:34:20 +0800 Subject: [PATCH] =?UTF-8?q?[feat]:=20=E6=B7=BB=E5=8A=A0=E8=81=94=E7=B3=BB?= =?UTF-8?q?=E4=BA=BA=E5=8E=BB=E9=87=8D=E5=92=8C=E6=8E=92=E5=BA=8F=20(#201)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- relations.go | 31 +++++++++++++++++++++++++++++++ user.go | 3 +++ 2 files changed, 34 insertions(+) diff --git a/relations.go b/relations.go index a8cb9c1..5bbd6fa 100644 --- a/relations.go +++ b/relations.go @@ -103,6 +103,16 @@ func (f Friends) AsMembers() Members { return members } +// Sort 对好友进行排序 +func (f Friends) Sort() Friends { + return f.AsMembers().Sort().Friends() +} + +// Uniq 对好友进行去重 +func (f Friends) Uniq() Friends { + return f.AsMembers().Uniq().Friends() +} + // SendText 向slice的好友依次发送文本消息 func (f Friends) SendText(text string, delays ...time.Duration) error { if f.Count() == 0 { @@ -180,6 +190,7 @@ func (g *Group) Members() (Members, error) { // AddFriendsIn 拉好友入群 func (g *Group) AddFriendsIn(friends ...*Friend) error { + friends = Friends(friends).Uniq() return g.self.AddFriendsIntoGroup(g, friends...) } @@ -316,6 +327,16 @@ func (g Groups) AsMembers() Members { return members } +// Sort 对群组进行排序 +func (g Groups) Sort() Groups { + return g.AsMembers().Sort().Groups() +} + +// Uniq 对群组进行去重 +func (g Groups) Uniq() Groups { + return g.AsMembers().Uniq().Groups() +} + // Mp 公众号对象 type Mp struct{ *User } @@ -369,6 +390,16 @@ func (m Mps) AsMembers() Members { return members } +// Sort 对公众号进行排序 +func (m Mps) Sort() Mps { + return m.AsMembers().Sort().MPs() +} + +// Uniq 对公众号进行去重 +func (m Mps) Uniq() Mps { + return m.AsMembers().Uniq().MPs() +} + // SearchByUserName 根据用户名查找 func (m Mps) SearchByUserName(limit int, userName string) (results Mps) { return m.Search(limit, func(group *Mp) bool { return group.UserName == userName }) diff --git a/user.go b/user.go index de526e0..6d4cc41 100644 --- a/user.go +++ b/user.go @@ -394,6 +394,7 @@ func (s *Self) SetRemarkNameToFriend(friend *Friend, remarkName string) error { // topic 群昵称,可以传递字符串 // friends 群员,最少为2个,加上自己3个,三人才能成群 func (s *Self) CreateGroup(topic string, friends ...*Friend) (*Group, error) { + friends = Friends(friends).Uniq() if len(friends) < 2 { return nil, errors.New("a group must be at least 2 members") } @@ -414,6 +415,7 @@ func (s *Self) AddFriendsIntoGroup(group *Group, friends ...*Friend) error { if len(friends) == 0 { return nil } + friends = Friends(friends).Uniq() // 获取群的所有的群员 groupMembers, err := group.Members() if err != nil { @@ -466,6 +468,7 @@ func (s *Self) RemoveMemberFromGroup(group *Group, members Members) error { // AddFriendIntoManyGroups 拉好友进多个群聊 // AddFriendIntoGroups, 名字和上面的有点像 func (s *Self) AddFriendIntoManyGroups(friend *Friend, groups ...*Group) error { + groups = Groups(groups).Uniq() for _, group := range groups { if err := s.AddFriendsIntoGroup(group, friend); err != nil { return err