add new admin controller
This commit is contained in:
2
main.go
2
main.go
@@ -57,6 +57,7 @@ func main() {
|
||||
dickController := controllers.NewDick(dc)
|
||||
duelController := controllers.NewDuel(b, dc)
|
||||
bonusController := controllers.NewBonusController(b, dc)
|
||||
adminMessageController := controllers.NewAdminMessageController(b, dc)
|
||||
acceptButton := tele.Btn{Unique: controllers.AcceptDuelButtonUnique}
|
||||
|
||||
b.Handle(&acceptButton, duelController.AcceptMatch)
|
||||
@@ -68,6 +69,7 @@ func main() {
|
||||
b.Handle("/clear", duelController.ClearMatch)
|
||||
|
||||
b.Handle("/b", bonusController.Bonus)
|
||||
b.Handle("/ms", adminMessageController.AdminMessage)
|
||||
|
||||
b.Start()
|
||||
}
|
||||
|
||||
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