(p *models.Comment)
| 987 | } |
| 988 | |
| 989 | func (r *auddBot) Comment(p *models.Comment) { |
| 990 | //fmt.Print("c") // why? to test the amount of new comments on Reddit! |
| 991 | atomic.AddInt64(&commentsCounter, 1) |
| 992 | //return nil |
| 993 | compare := getBodyToCompare(p.Body) |
| 994 | trigger := substringInSlice(compare, r.config.Triggers) |
| 995 | if strings.Contains(compare, "bad bot") || strings.Contains(compare, "damn bot") || |
| 996 | strings.Contains(compare, "stupid bot") { |
| 997 | myRepliesMu.Lock() |
| 998 | comment, exists := myReplies[string(p.ParentID)] |
| 999 | myRepliesMu.Unlock() |
| 1000 | if exists && !comment.summoned { |
| 1001 | target := mira.RedditOauth + "/api/del" |
| 1002 | _, err := r.r2.MiraRequest("POST", target, map[string]string{ |
| 1003 | "id": comment.commentID, |
| 1004 | "api_type": "json", |
| 1005 | }) |
| 1006 | capture(err) |
| 1007 | if comment.additionalCommentID != "" { |
| 1008 | _, err = r.r2.MiraRequest("POST", target, map[string]string{ |
| 1009 | "id": comment.additionalCommentID, |
| 1010 | "api_type": "json", |
| 1011 | }) |
| 1012 | } |
| 1013 | capture(err) |
| 1014 | fmt.Println("got a bad bot comment", "https://reddit.com"+p.Permalink) |
| 1015 | return |
| 1016 | } |
| 1017 | } |
| 1018 | if !trigger { |
| 1019 | d := minDistance(compare, "what", "song", "music", "track") |
| 1020 | if len(compare) < 100 && d != 0 && d < 10 { |
| 1021 | fmt.Println("Skipping comment:", compare, "https://reddit.com"+p.Permalink) |
| 1022 | } |
| 1023 | return |
| 1024 | } |
| 1025 | myRepliesMu.Lock() |
| 1026 | _, exists := myReplies[string(p.ParentID)] |
| 1027 | myRepliesMu.Unlock() |
| 1028 | if exists { |
| 1029 | fmt.Println("Ignoring a comment that's a reply to ours:", "https://reddit.com"+p.Permalink) |
| 1030 | return |
| 1031 | } |
| 1032 | if stringInSlice([]string{"auddbot", "RecognizeSong"}, p.Author) { |
| 1033 | fmt.Println("Ignoring a comment from itself", p.Body) |
| 1034 | return |
| 1035 | } |
| 1036 | if stringInSlice(r.config.IgnoreSubreddits, p.Subreddit) { |
| 1037 | fmt.Println("Ignoring a comment from", p.Subreddit, "https://reddit.com"+p.Permalink) |
| 1038 | return |
| 1039 | } |
| 1040 | if stringInSlice(r.config.SubredditsBannedOn, p.Subreddit) && |
| 1041 | !strings.Contains(compare, "u/recognizesong") && strings.Contains(compare, "u/auddbot") { |
| 1042 | avoidDuplicatesMu.Lock() |
| 1043 | if _, exists := avoidDuplicates[string(p.ParentID)]; exists { |
| 1044 | avoidDuplicatesMu.Unlock() |
| 1045 | return |
| 1046 | } |
no test coverage detected