✨ Wait sending announcements to all users before panic
This commit is contained in:
parent
27611490a5
commit
7c6aa96eff
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue