Archived
1
This repository has been archived on 2022-11-04. You can view files and clone it, but cannot push or open issues or pull requests.
i2_bot/lib/reminder/sender.go

33 lines
1.0 KiB
Go
Raw Normal View History

// i2_bot Instinct PokememBro Bot
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
package reminder
import (
"github.com/go-telegram-bot-api/telegram-bot-api"
"source.wtfteam.pro/i2_bot/i2_bot/lib/dbmapping"
"time"
)
// SendReminders sends reminders for users about coming league tournament
func (r *Reminder) SendReminders() {
currentHour := time.Now().Hour()
nextTournamentID := (currentHour / 2) + 1
playersRaw := []dbmapping.Player{}
err := c.Db.Select(&playersRaw, "SELECT p.* FROM players p, alarms a WHERE a.turnir_number=? AND a.player_id = p.id GROUP BY p.id", nextTournamentID)
if err != nil {
c.Log.Error(err.Error())
}
for i := range playersRaw {
message := "*Турнир Лиг покемемов состоится через пять минут!*\n"
message += "Вперёд, за опытом и деньгами! Выстави атаку и жди результата!"
msg := tgbotapi.NewMessage(int64(playersRaw[i].TelegramID), message)
msg.ParseMode = "Markdown"
c.Bot.Send(msg)
}
}