78 lines
1.8 KiB
Go
78 lines
1.8 KiB
Go
package controllers
|
||
|
||
import (
|
||
"fmt"
|
||
"log"
|
||
"strconv"
|
||
"strings"
|
||
|
||
tele "gopkg.in/telebot.v4"
|
||
)
|
||
|
||
type BonusController struct {
|
||
DC *DataController
|
||
Bot *tele.Bot
|
||
}
|
||
|
||
func NewBonusController(b *tele.Bot, db *DataController) *BonusController {
|
||
return &BonusController{DC: db, Bot: b}
|
||
}
|
||
|
||
func (b *BonusController) Bonus(c tele.Context) error {
|
||
var text string
|
||
var msg *tele.Message
|
||
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 bonus", text)
|
||
} else {
|
||
return c.Send("Некоректная команда, используйте /b <сумма>")
|
||
}
|
||
|
||
giftSumm, err := strconv.Atoi(text)
|
||
if err != nil {
|
||
return c.Send("Некоректная сумма")
|
||
}
|
||
|
||
btn := &tele.ReplyMarkup{}
|
||
row := btn.Row(btn.Data("Забрать", "add_bonus", fmt.Sprintf("%d", giftSumm)+":"+fmt.Sprintf("%d", c.Sender().ID)+":"+fmt.Sprintf("%d", chatId)))
|
||
btn.Inline(row)
|
||
|
||
msg, err = b.Bot.Send(
|
||
c.Chat(),
|
||
fmt.Sprintf("Успей забрать бонус.\nСумма: %d", giftSumm),
|
||
btn,
|
||
)
|
||
|
||
if err != nil {
|
||
log.Println(err)
|
||
}
|
||
|
||
b.Bot.Handle(&row[0], func(c tele.Context) error {
|
||
data := strings.Split(c.Data(), ":")
|
||
giftSumm, _ := strconv.Atoi(data[0])
|
||
chatId, _ := strconv.ParseInt(data[2], 10, 64)
|
||
|
||
user := b.DC.GetUser(c.Sender().ID, chatId)
|
||
newSize := user.DickSize + giftSumm
|
||
|
||
b.DC.UpdateDick(c.Sender().ID, chatId, newSize)
|
||
_, err := b.Bot.Edit(msg, fmt.Sprintf("%s получает бонус: %d", c.Sender().FirstName, giftSumm))
|
||
if err != nil {
|
||
log.Println(err)
|
||
}
|
||
|
||
return c.Send("Поздравляем")
|
||
})
|
||
|
||
fmt.Println(giftSumm)
|
||
|
||
return c.Send(fmt.Sprintf("Бонус запущен: %d", giftSumm))
|
||
}
|