/send_all feature for administrators
This commit is contained in:
41
lib/talkers/broadcast.go
Normal file
41
lib/talkers/broadcast.go
Normal file
@@ -0,0 +1,41 @@
|
||||
// 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"
|
||||
}
|
@@ -8,17 +8,22 @@ import (
|
||||
"github.com/go-telegram-bot-api/telegram-bot-api"
|
||||
// local
|
||||
"../config"
|
||||
"../dbmapping"
|
||||
)
|
||||
|
||||
// HelpMessage gives user all available commands
|
||||
func (t *Talkers) HelpMessage(update tgbotapi.Update) {
|
||||
func (t *Talkers) HelpMessage(update tgbotapi.Update, playerRaw *dbmapping.Player) {
|
||||
message := "*Бот Инстинкта Enchanched.*\n\n"
|
||||
message += "Текущая версия: *" + config.VERSION + "*\n\n"
|
||||
message += "Список команд:\n\n"
|
||||
message += "Список команд\n\n"
|
||||
message += "+ /me – посмотреть свой сохраненный профиль в боте\n"
|
||||
message += "+ /best – посмотреть лучших покемонов для поимки\n"
|
||||
message += "+ /pokedeks – получить список известных боту покемемов\n"
|
||||
if c.Getters.PlayerBetterThan(playerRaw, "admin") {
|
||||
message += "+ /send\\_all _текст_ — отправить сообщение всем пользователям бота\n"
|
||||
}
|
||||
message += "+ /help – выводит данное сообщение\n"
|
||||
|
||||
message += "\n\n"
|
||||
message += "Связаться с автором: @fat0troll\n"
|
||||
|
||||
|
@@ -15,7 +15,7 @@ type TalkersInterface interface {
|
||||
Init()
|
||||
HelloMessageUnauthorized(update tgbotapi.Update)
|
||||
HelloMessageAuthorized(update tgbotapi.Update, playerRaw dbmapping.Player)
|
||||
HelpMessage(update tgbotapi.Update)
|
||||
HelpMessage(update tgbotapi.Update, playerRaw *dbmapping.Player)
|
||||
PokememesList(update tgbotapi.Update, page int)
|
||||
PokememeInfo(update tgbotapi.Update, playerRaw dbmapping.Player) string
|
||||
BestPokememesList(update tgbotapi.Update, playerRaw dbmapping.Player) string
|
||||
@@ -30,6 +30,8 @@ type TalkersInterface interface {
|
||||
AnyMessageUnauthorized(update tgbotapi.Update)
|
||||
GetterError(update tgbotapi.Update)
|
||||
|
||||
AdminBroadcastMessage(update tgbotapi.Update) string
|
||||
|
||||
DurakMessage(update tgbotapi.Update)
|
||||
MatMessage(update tgbotapi.Update)
|
||||
}
|
||||
|
Reference in New Issue
Block a user