47 lines
950 B
Go
47 lines
950 B
Go
package controllers
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"strings"
|
|
|
|
tele "gopkg.in/telebot.v4"
|
|
)
|
|
|
|
type AdminMessageController struct {
|
|
DC *DataController
|
|
Bot *tele.Bot
|
|
}
|
|
|
|
func NewAdminMessageController(b *tele.Bot, db *DataController) *AdminMessageController {
|
|
return &AdminMessageController{DC: db, Bot: b}
|
|
}
|
|
|
|
func (b *AdminMessageController) AdminMessage(c tele.Context) error {
|
|
var text string
|
|
chatId := c.Chat().ID
|
|
|
|
user := b.DC.GetUser(c.Sender().ID, chatId)
|
|
if !user.Admin {
|
|
return c.Send("У вас нет прав для использования этой команды")
|
|
}
|
|
|
|
if strings.Contains(c.Text(), " ") {
|
|
text = strings.Split(c.Text(), " ")[1]
|
|
fmt.Println("New admin message", text)
|
|
} else {
|
|
return c.Send("Некоректная команда, /ms <сообщение>")
|
|
}
|
|
|
|
_, err := b.Bot.Send(
|
|
c.Chat(),
|
|
text,
|
|
)
|
|
|
|
if err != nil {
|
|
log.Println(err)
|
|
}
|
|
|
|
return c.Send("Сообщение отправлено.")
|
|
}
|