(mention *reddit1.Message, comment *models.Comment, post *models.Post)
| 561 | const enterpriseChunkLength = 12 |
| 562 | |
| 563 | func (r *auddBot) HandleQuery(mention *reddit1.Message, comment *models.Comment, post *models.Post) { |
| 564 | var resultUrl, t, parentID, body, subreddit, author, permalink, postId string |
| 565 | var err error |
| 566 | if mention != nil { |
| 567 | t, parentID, body, subreddit, author = |
| 568 | "mention", mention.Name, mention.Body, mention.Subreddit, mention.Author |
| 569 | fmt.Println("\n ! Processing the mention") |
| 570 | } |
| 571 | if comment != nil { |
| 572 | t, parentID, body, subreddit, author, permalink = |
| 573 | "comment", string(comment.GetID()), comment.Body, comment.Subreddit, comment.Author, comment.Permalink |
| 574 | } |
| 575 | if post != nil { |
| 576 | t, parentID, body, subreddit, author, permalink = |
| 577 | "post", string(post.GetID()), post.Selftext, post.Subreddit, post.Author, post.Permalink |
| 578 | } |
| 579 | |
| 580 | body = strings.ToLower(body) |
| 581 | rs := strings.Contains(body, "recognizesong") |
| 582 | summoned := rs || strings.Contains(body, "auddbot") |
| 583 | |
| 584 | if len(body) > r.config.MaxTriggerTextLength && r.config.MaxTriggerTextLength != 0 && !summoned { |
| 585 | fmt.Println("The comment is too long, skipping", body) |
| 586 | return |
| 587 | } |
| 588 | |
| 589 | // Avoid handling of both the comment from r/all and the mention |
| 590 | var previousUrl string |
| 591 | var c chan d |
| 592 | var exists bool |
| 593 | avoidDuplicatesMu.Lock() |
| 594 | if c, exists = avoidDuplicates[parentID]; exists { |
| 595 | delete(avoidDuplicates, parentID) |
| 596 | avoidDoubleDuplicates[parentID] = true |
| 597 | avoidDuplicatesMu.Unlock() |
| 598 | results := <-c |
| 599 | if results.b { |
| 600 | fmt.Println("Ignored a duplicate") |
| 601 | return |
| 602 | } |
| 603 | fmt.Println("Attempting to recognize the song again") |
| 604 | c = make(chan d, 1) |
| 605 | previousUrl = results.u |
| 606 | } else { |
| 607 | if avoidDoubleDuplicates[parentID] { |
| 608 | avoidDuplicatesMu.Unlock() |
| 609 | fmt.Println("Ignored a double duplicate") |
| 610 | return |
| 611 | } |
| 612 | c = make(chan d, 1) |
| 613 | avoidDuplicates[parentID] = c |
| 614 | avoidDuplicatesMu.Unlock() |
| 615 | } |
| 616 | |
| 617 | if post != nil { |
| 618 | resultUrl, err = r.GetLinkFromComment(nil, nil, post) |
| 619 | } else { |
| 620 | resultUrl, postId, err = r.GetVideoLink(mention, comment) |
no test coverage detected