Skip to content

Commit

Permalink
Merge pull request #3 from PoCInnovation/fix/parseNewPosts
Browse files Browse the repository at this point in the history
fix: remove global var from function args list
  • Loading branch information
Doozers authored Jun 5, 2022
2 parents 6cf39bc + d7b7ca1 commit b6a38fa
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions getNewPosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
}
Expand Down

0 comments on commit b6a38fa

Please sign in to comment.