From 569005f3ebcafd616f1f2ca83d5ab4a27b01dbae Mon Sep 17 00:00:00 2001 From: Arturomtz8 Date: Mon, 11 Sep 2023 22:50:31 -0600 Subject: [PATCH] force limit of 5 repos --- telegram.go | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/telegram.go b/telegram.go index 3e06b51..9e7be4c 100644 --- a/telegram.go +++ b/telegram.go @@ -138,26 +138,30 @@ func formatReposContentAndSend(repos *github.TrendingSearchResult, chatId int) ( {{.HtmlURL}} ` - for _, repo := range repos.Items { - var report = template.Must(template.New("trendinglist").Parse(templ)) - buf := &bytes.Buffer{} - if err := report.Execute(buf, repo); err != nil { - sendTextToTelegramChat(chatId, err.Error()) - return "", err + for index, repo := range repos.Items { + if index <= defaulRepoLen { + var report = template.Must(template.New("trendinglist").Parse(templ)) + buf := &bytes.Buffer{} + if err := report.Execute(buf, repo); err != nil { + sendTextToTelegramChat(chatId, err.Error()) + return "", err + } + s := buf.String() + + reposContent = append(reposContent, s) } - s := buf.String() - reposContent = append(reposContent, s) } if len(reposContent) == 0 { return "", errors.New("There are not trending repos yet for today, try again later") - } else if len(reposContent) <= defaulRepoLen { - repoLen = len(reposContent) - } else { - repoLen = defaulRepoLen } + // else if len(reposContent) <= defaulRepoLen { + // repoLen = len(reposContent) + // } else { + // repoLen = defaulRepoLen + // } fmt.Println("template created and proceeding to send repos to chat") fmt.Println("Total repos that will be sent", repoLen)