Archived
1

Pin to all squads at :55 of every even hour

Closes #9
This commit is contained in:
2017-11-24 13:24:36 +04:00
parent a32ed89be8
commit b038d5b10d
8 changed files with 64 additions and 5 deletions

View File

@@ -25,4 +25,6 @@ func New(ac *appcontext.Context) {
// Init is an initialization function for pinner
func (p *Pinner) Init() {
c.Log.Info("Initializing Pinner...")
c.Cron.AddFunc("0 55 */2 * * *", p.PinBattleAlert)
}

View File

@@ -69,3 +69,35 @@ func (p *Pinner) PinMessageToAllChats(update *tgbotapi.Update) string {
return "ok"
}
// PinBattleAlert pins to all squads 'battle alert' at :55 of every even hour
// Even hours are in Moscow timezone
func (p *Pinner) PinBattleAlert() {
c.Log.Debug("> Cron invoked PinBattleAlert()")
message := "*Турнир Лиги покемемов состоится через 5 минут!*\nБоевая готовность, отряд!"
groupChats, _ := c.Squader.GetAllSquadChats()
for i := range groupChats {
if groupChats[i].ChatType == "supergroup" {
msg := tgbotapi.NewMessage(groupChats[i].TelegramID, message)
msg.ParseMode = "Markdown"
pinnableMessage, err := c.Bot.Send(msg)
if err != nil {
c.Log.Error(err.Error())
}
pinChatMessageConfig := tgbotapi.PinChatMessageConfig{
ChatID: pinnableMessage.Chat.ID,
MessageID: pinnableMessage.MessageID,
DisableNotification: true,
}
_, err = c.Bot.PinChatMessage(pinChatMessageConfig)
if err != nil {
c.Log.Error(err.Error())
}
}
}
}

View File

@@ -10,5 +10,7 @@ import (
// PinnerInterface implements Pinner for importing via appcontex
type PinnerInterface interface {
Init()
PinBattleAlert()
PinMessageToAllChats(update *tgbotapi.Update) string
}