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/talkers/broadcast.go

42 lines
1.3 KiB
Go
Raw Normal View History

2017-10-22 14:04:14 +04:00
// i2_bot Instinct PokememBro Bot
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
package talkers
import ( // stdlib
// 3rd party
"strings"
"github.com/go-telegram-bot-api/telegram-bot-api"
)
// AdminBroadcastMessage sends message to all private chats with bot
func (t *Talkers) AdminBroadcastMessage(update tgbotapi.Update) string {
broadcastingMessageBody := strings.Replace(update.Message.Text, "/send_all", "", 1)
privateChats, ok := c.Getters.GetAllPrivateChats()
if !ok {
return "fail"
}
for i := range privateChats {
chat := privateChats[i]
broadcastingMessage := "*Привет, " + chat.Name + "!*\n\n"
broadcastingMessage += "*Важное сообщение от администратора " + update.Message.From.FirstName + " " + update.Message.From.LastName + "* (@" + update.Message.From.UserName + ")\n\n"
broadcastingMessage += broadcastingMessageBody
msg := tgbotapi.NewMessage(int64(chat.TelegramID), broadcastingMessage)
msg.ParseMode = "Markdown"
c.Bot.Send(msg)
}
message := "Сообщение всем отправлено. Надеюсь, пользователи бота за него тебя не убьют.\n"
msg := tgbotapi.NewMessage(update.Message.Chat.ID, message)
msg.ParseMode = "Markdown"
c.Bot.Send(msg)
return "ok"
}