add new admin controller

This commit is contained in:
Smile Rex
2025-10-02 00:04:16 +03:00
parent 9775cfe2d4
commit 8309a64b02
2 changed files with 47 additions and 0 deletions

View 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("Сообщение отправлено.")
}