Skip to content
This repository has been archived by the owner on Apr 9, 2020. It is now read-only.

Commit

Permalink
✨ Wait sending announcements to all users before panic
Browse files Browse the repository at this point in the history
  • Loading branch information
toby3d committed Jan 25, 2018
1 parent 2761149 commit 7c6aa96
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions err_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
// errCheck helps debug critical errors without warnings from 'gocyclo' linter
func errCheck(err error) {
if err != nil {
waitForwards.Wait() // Wait what all users get announcement message
panic(err.Error())
}
}
5 changes: 5 additions & 0 deletions update_channel_post.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package main

import (
"sync"
"time"

log "github.com/kirillDanshin/dlog"
tg "github.com/toby3d/telegram"
)

var waitForwards = new(sync.WaitGroup)

func updateChannelPost(post *tg.Message) {
if post.Chat.ID != channelID {
log.Ln(post.Chat.ID, "!=", channelID)
Expand All @@ -17,11 +20,13 @@ func updateChannelPost(post *tg.Message) {
errCheck(err)

for i := range users {
waitForwards.Add(1)
if _, err = bot.ForwardMessage(
tg.NewForwardMessage(post.Chat.ID, int64(users[i]), post.ID),
); err != nil {
log.Ln(err.Error())
}
waitForwards.Done()

time.Sleep(time.Second / 10) // For avoid spamming
}
Expand Down

0 comments on commit 7c6aa96

Please sign in to comment.