修复一个好友匹配的问题
This commit is contained in:
parent
dd01e45ad5
commit
7fbb5e6db0
@ -23,7 +23,7 @@ func TestDefaultBot(t *testing.T) {
|
|||||||
group, _ := self.Groups()
|
group, _ := self.Groups()
|
||||||
friends, _ := self.Friends()
|
friends, _ := self.Friends()
|
||||||
fmt.Println(group.Search(Cond{"NickName": "厉害了"}))
|
fmt.Println(group.Search(Cond{"NickName": "厉害了"}))
|
||||||
fmt.Println(friends.Search(Cond{"RemarkName": "阿青"}))
|
fmt.Println(friends.Search(Cond{"RemarkName": "阿青", "Sex": 2}))
|
||||||
fmt.Println(bot.Block())
|
fmt.Println(bot.Block())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
42
relations.go
42
relations.go
@ -72,7 +72,7 @@ func (f Friends) Search(cond Cond) (friends Friends, found bool) {
|
|||||||
switch k {
|
switch k {
|
||||||
case "UserName":
|
case "UserName":
|
||||||
if value, ok := v.(string); ok {
|
if value, ok := v.(string); ok {
|
||||||
return f.SearchByNickName(value)
|
return f.SearchByUserName(value)
|
||||||
}
|
}
|
||||||
case "NickName":
|
case "NickName":
|
||||||
if value, ok := v.(string); ok {
|
if value, ok := v.(string); ok {
|
||||||
@ -85,19 +85,21 @@ func (f Friends) Search(cond Cond) (friends Friends, found bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, member := range f {
|
for _, friend := range f {
|
||||||
value := reflect.ValueOf(member).Elem()
|
value := reflect.ValueOf(friend).Elem()
|
||||||
|
var matchCount int
|
||||||
for k, v := range cond {
|
for k, v := range cond {
|
||||||
if field := value.FieldByName(k); field.IsValid() {
|
if field := value.FieldByName(k); field.IsValid() {
|
||||||
if field.Interface() == v {
|
if field.Interface() != v {
|
||||||
found = true
|
break
|
||||||
if friends == nil {
|
|
||||||
friends = make(Friends, 0)
|
|
||||||
}
|
|
||||||
friends = append(friends, member)
|
|
||||||
}
|
}
|
||||||
|
matchCount++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if matchCount == len(cond) {
|
||||||
|
found = true
|
||||||
|
friends = append(friends, friend)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -184,14 +186,14 @@ func (g Groups) SearchByRemarkName(remarkName string) (results Groups, found boo
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g Groups) Search(cond Cond) (groups Groups, found bool) {
|
func (g Groups) Search(cond Cond) (results Groups, found bool) {
|
||||||
|
|
||||||
if len(cond) == 1 {
|
if len(cond) == 1 {
|
||||||
for k, v := range cond {
|
for k, v := range cond {
|
||||||
switch k {
|
switch k {
|
||||||
case "UserName":
|
case "UserName":
|
||||||
if value, ok := v.(string); ok {
|
if value, ok := v.(string); ok {
|
||||||
return g.SearchByNickName(value)
|
return g.SearchByUserName(value)
|
||||||
}
|
}
|
||||||
case "NickName":
|
case "NickName":
|
||||||
if value, ok := v.(string); ok {
|
if value, ok := v.(string); ok {
|
||||||
@ -205,19 +207,21 @@ func (g Groups) Search(cond Cond) (groups Groups, found bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, member := range g {
|
for _, group := range g {
|
||||||
value := reflect.ValueOf(member).Elem()
|
value := reflect.ValueOf(group).Elem()
|
||||||
|
var matchCount int
|
||||||
for k, v := range cond {
|
for k, v := range cond {
|
||||||
if field := value.FieldByName(k); field.IsValid() {
|
if field := value.FieldByName(k); field.IsValid() {
|
||||||
if field.Interface() == v {
|
if field.Interface() != v {
|
||||||
found = true
|
break
|
||||||
if groups == nil {
|
|
||||||
groups = make(Groups, 0)
|
|
||||||
}
|
|
||||||
groups = append(groups, member)
|
|
||||||
}
|
}
|
||||||
|
matchCount++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if matchCount == len(cond) {
|
||||||
|
found = true
|
||||||
|
results = append(results, group)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
16
user.go
16
user.go
@ -343,7 +343,7 @@ func (m Members) Search(cond Cond) (results Members, found bool) {
|
|||||||
switch k {
|
switch k {
|
||||||
case "UserName":
|
case "UserName":
|
||||||
if value, ok := v.(string); ok {
|
if value, ok := v.(string); ok {
|
||||||
return m.SearchByNickName(value)
|
return m.SearchByUserName(value)
|
||||||
}
|
}
|
||||||
case "NickName":
|
case "NickName":
|
||||||
if value, ok := v.(string); ok {
|
if value, ok := v.(string); ok {
|
||||||
@ -359,17 +359,19 @@ func (m Members) Search(cond Cond) (results Members, found bool) {
|
|||||||
|
|
||||||
for _, member := range m {
|
for _, member := range m {
|
||||||
value := reflect.ValueOf(member).Elem()
|
value := reflect.ValueOf(member).Elem()
|
||||||
|
var matchCount int
|
||||||
for k, v := range cond {
|
for k, v := range cond {
|
||||||
if field := value.FieldByName(k); field.IsValid() {
|
if field := value.FieldByName(k); field.IsValid() {
|
||||||
if field.Interface() == v {
|
if field.Interface() != v {
|
||||||
found = true
|
break
|
||||||
if results == nil {
|
|
||||||
results = make(Members, 0)
|
|
||||||
}
|
|
||||||
results = append(results, member)
|
|
||||||
}
|
}
|
||||||
|
matchCount++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if matchCount == len(cond) {
|
||||||
|
found = true
|
||||||
|
results = append(results, member)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user