diff --git a/getNewPosts.go b/getNewPosts.go index 64dc143..955fa55 100644 --- a/getNewPosts.go +++ b/getNewPosts.go @@ -81,16 +81,20 @@ func GetPostID(s string) (int, error) { return strconv.Atoi(match[1]) } -func parseNewPosts(BoardPosts string, indexMax int, board string) []*embed.Embed { +func parseNewPosts(BoardPosts string, board string) []*embed.Embed { var post []Post + newMaxId := maxId[board] a := strings.Split(BoardPosts, "----------------------------------------") for _, c := range a { nb, _ := GetPostID(c) - if nb > indexMax { + if nb > maxId[board] { post = append(post, GetPostInfos(c, nb)) - maxId[board] = nb + if nb > newMaxId { + newMaxId = nb + } } } + maxId[board] = newMaxId return EmbedNewPosts(post, board) } @@ -114,25 +118,26 @@ func getNewPosts(board string) ([]*embed.Embed, error) { return nil, err } - re := regexp.MustCompile("\\bpostid=([0-9]+)") - var newIdString = re.FindAllStringSubmatch(BoardPosts, -1) - var newId []int - - for _, i := range newIdString { - j, err := strconv.Atoi(i[1]) - if err != nil { - panic(err) - } - newId = append(newId, j) - } if maxId[board] != 0 { - if maxId[board] < newId[len(newId)-1] { - return parseNewPosts(BoardPosts, maxId[board], board), nil - } + return parseNewPosts(BoardPosts, board), nil } else { + re := regexp.MustCompile("\\bpostid=([0-9]+)") + var newIdString = re.FindAllStringSubmatch(BoardPosts, -1) + var newId []int + + var basicMaxId int + for _, i := range newIdString { + j, err := strconv.Atoi(i[1]) + if err != nil { + panic(err) + } + if j > basicMaxId { + basicMaxId = j + } + } if len(newId) > 0 { fmt.Println("first setup for this board:", board) - maxId[board] = newId[len(newId)-1] + maxId[board] = basicMaxId } else { fmt.Println("Empty board:", board) }