✨ 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
|
// errCheck helps debug critical errors without warnings from 'gocyclo' linter
|
||||||
func errCheck(err error) {
|
func errCheck(err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
waitForwards.Wait() // Wait what all users get announcement message
|
||||||
panic(err.Error())
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
log "github.com/kirillDanshin/dlog"
|
log "github.com/kirillDanshin/dlog"
|
||||||
tg "github.com/toby3d/telegram"
|
tg "github.com/toby3d/telegram"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var waitForwards = new(sync.WaitGroup)
|
||||||
|
|
||||||
func updateChannelPost(post *tg.Message) {
|
func updateChannelPost(post *tg.Message) {
|
||||||
if post.Chat.ID != channelID {
|
if post.Chat.ID != channelID {
|
||||||
log.Ln(post.Chat.ID, "!=", channelID)
|
log.Ln(post.Chat.ID, "!=", channelID)
|
||||||
|
@ -17,11 +20,13 @@ func updateChannelPost(post *tg.Message) {
|
||||||
errCheck(err)
|
errCheck(err)
|
||||||
|
|
||||||
for i := range users {
|
for i := range users {
|
||||||
|
waitForwards.Add(1)
|
||||||
if _, err = bot.ForwardMessage(
|
if _, err = bot.ForwardMessage(
|
||||||
tg.NewForwardMessage(post.Chat.ID, int64(users[i]), post.ID),
|
tg.NewForwardMessage(post.Chat.ID, int64(users[i]), post.ID),
|
||||||
); err != nil {
|
); err != nil {
|
||||||
log.Ln(err.Error())
|
log.Ln(err.Error())
|
||||||
}
|
}
|
||||||
|
waitForwards.Done()
|
||||||
|
|
||||||
time.Sleep(time.Second / 10) // For avoid spamming
|
time.Sleep(time.Second / 10) // For avoid spamming
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue