add new admin controller
This commit is contained in:
45
src/controllers/adminMessageController.go
Normal file
45
src/controllers/adminMessageController.go
Normal file
@@ -0,0 +1,45 @@
|
||||
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) *BonusController {
|
||||
return &BonusController{DC: db, Bot: b}
|
||||
}
|
||||
|
||||
func (b *BonusController) AdminMessage(c tele.Context) error {
|
||||
var text string
|
||||
|
||||
user := b.DC.GetUser(c.Sender().ID)
|
||||
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(
|
||||
&tele.Chat{ID: -1002345923642},
|
||||
text,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
return c.Send("Сообщение отправлено.")
|
||||
}
|
||||
Reference in New Issue
Block a user