2017-11-21 06:06:32 +04:00
// i2_bot – Instinct PokememBro Bot
2018-03-31 16:45:09 +04:00
// Copyright (c) 2017-2018 Vladimir "fat0troll" Hodakov
2017-11-21 06:06:32 +04:00
package broadcaster
import (
2018-03-31 16:45:09 +04:00
"strconv"
2017-11-21 06:06:32 +04:00
"github.com/go-telegram-bot-api/telegram-bot-api"
2018-05-19 12:14:25 +04:00
"github.com/fat0troll/i2_bot/lib/dbmapping"
2017-11-21 06:06:32 +04:00
)
// AdminBroadcastMessageCompose saves message for future broadcast
func ( b * Broadcaster ) AdminBroadcastMessageCompose ( update * tgbotapi . Update , playerRaw * dbmapping . Player ) string {
2017-11-25 03:00:34 +04:00
broadcastingMessageBody := update . Message . CommandArguments ( )
2018-03-31 16:45:09 +04:00
messageMode := "none"
2017-11-25 03:00:34 +04:00
switch update . Message . Command ( ) {
case "send_all" :
2018-03-31 16:45:09 +04:00
messageMode = "all"
2017-11-25 03:00:34 +04:00
case "send_league" :
2018-03-31 16:45:09 +04:00
messageMode = "league"
}
messageRaw , ok := b . createBroadcastMessage ( playerRaw , broadcastingMessageBody , messageMode )
if ! ok {
return "fail"
2017-11-21 06:06:32 +04:00
}
message := "Сообщение сохранено в базу.\n"
message += "Выглядеть оно будет так:"
2018-03-31 16:45:09 +04:00
c . Sender . SendMarkdownAnswer ( update , message )
2017-11-21 06:06:32 +04:00
broadcastingMessage := "*Привет, %username%!*\n\n"
broadcastingMessage += "*Важное сообщение от администратора " + update . Message . From . FirstName + " " + update . Message . From . LastName + "* (@" + update . Message . From . UserName + ")\n\n"
broadcastingMessage += messageRaw . Text
2018-03-31 16:45:09 +04:00
c . Sender . SendMarkdownAnswer ( update , broadcastingMessage )
2017-11-21 06:06:32 +04:00
2017-11-25 03:00:34 +04:00
switch update . Message . Command ( ) {
case "send_all" :
message = "Чтобы отправить сообщение всем, отправь команду /send\\_confirm " + strconv . Itoa ( messageRaw . ID )
case "send_league" :
message = "Чтобы отправить сообщение всем игрокам лиги Инстинкт, отправь команду /send\\_confirm " + strconv . Itoa ( messageRaw . ID )
}
2017-11-21 06:06:32 +04:00
2018-03-31 16:45:09 +04:00
c . Sender . SendMarkdownAnswer ( update , message )
2017-11-21 06:06:32 +04:00
return "ok"
}