Also check URL field of posts

This commit is contained in:
Elara 2023-01-23 14:13:39 -08:00
parent ae06e38b04
commit 6f8860ba80
1 changed files with 5 additions and 5 deletions

10
main.go
View File

@ -2,6 +2,7 @@ package main
import (
"context"
"fmt"
"os"
"os/signal"
"strings"
@ -139,12 +140,11 @@ func commentWorker(ctx context.Context, c *lemmy.WSClient, replyCh chan<- replyJ
}
for i, reply := range cfg.Replies {
if !pr.PostView.Post.Body.IsValid() {
continue
}
body := pr.PostView.Post.URL.ValueOr("") + "\n\n" + pr.PostView.Post.Body.ValueOr("")
fmt.Println(body)
re := compiledRegexes[reply.Regex]
if !re.MatchString(pr.PostView.Post.Body.MustValue()) {
if !re.MatchString(body) {
continue
}
@ -155,7 +155,7 @@ func commentWorker(ctx context.Context, c *lemmy.WSClient, replyCh chan<- replyJ
job := replyJob{PostID: pr.PostView.Post.ID}
matches := re.FindAllStringSubmatch(pr.PostView.Post.Body.MustValue(), -1)
matches := re.FindAllStringSubmatch(body, -1)
job.Content, err = executeTmpl(compiledTmpls[reply.Regex], matches)
if err != nil {
log.Warn("Error while executing template").Err(err).Send()