add new bonus system
This commit is contained in:
27
main.go
27
main.go
@@ -10,6 +10,11 @@ import (
|
|||||||
tele "gopkg.in/telebot.v4"
|
tele "gopkg.in/telebot.v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// //////////////////////
|
||||||
|
var isTest bool = false
|
||||||
|
|
||||||
|
////////////////////////
|
||||||
|
|
||||||
func config() models.Config {
|
func config() models.Config {
|
||||||
return models.Config{
|
return models.Config{
|
||||||
Token: os.Getenv("BOT_TOKEN"),
|
Token: os.Getenv("BOT_TOKEN"),
|
||||||
@@ -20,8 +25,25 @@ func config() models.Config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testConfig() models.Config {
|
||||||
|
return models.Config{
|
||||||
|
Token: "7757765456:AAFpFXhbi9XCfgRt7P3OT3F_jrBBplubWZA",
|
||||||
|
HostName: "217.12.40.237",
|
||||||
|
DbName: "stage",
|
||||||
|
UserName: "root",
|
||||||
|
Password: "12641264",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
cfg := config()
|
var cfg models.Config
|
||||||
|
|
||||||
|
if isTest {
|
||||||
|
cfg = testConfig()
|
||||||
|
} else {
|
||||||
|
cfg = config()
|
||||||
|
}
|
||||||
|
|
||||||
pref := tele.Settings{
|
pref := tele.Settings{
|
||||||
Token: cfg.Token,
|
Token: cfg.Token,
|
||||||
Poller: &tele.LongPoller{Timeout: 10 * time.Second},
|
Poller: &tele.LongPoller{Timeout: 10 * time.Second},
|
||||||
@@ -37,6 +59,7 @@ func main() {
|
|||||||
|
|
||||||
dickController := controllers.NewDick(dc)
|
dickController := controllers.NewDick(dc)
|
||||||
duelController := controllers.NewDuel(b, dc)
|
duelController := controllers.NewDuel(b, dc)
|
||||||
|
bonusController := controllers.NewBonusController(b, dc)
|
||||||
|
|
||||||
b.Handle("/dick", dickController.Dick)
|
b.Handle("/dick", dickController.Dick)
|
||||||
b.Handle("/top_dick", dickController.TopDick)
|
b.Handle("/top_dick", dickController.TopDick)
|
||||||
@@ -45,5 +68,7 @@ func main() {
|
|||||||
b.Handle("/accept", duelController.AcceptMatch)
|
b.Handle("/accept", duelController.AcceptMatch)
|
||||||
b.Handle("/clear", duelController.ClearMatch)
|
b.Handle("/clear", duelController.ClearMatch)
|
||||||
|
|
||||||
|
b.Handle("/b", bonusController.Bonus)
|
||||||
|
|
||||||
b.Start()
|
b.Start()
|
||||||
}
|
}
|
||||||
|
|||||||
74
src/controllers/bonusController.go
Normal file
74
src/controllers/bonusController.go
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
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 SendChatToID(bot *tele.Bot, msg string, id int64) {
|
||||||
|
chat := &tele.Chat{ID: id}
|
||||||
|
_, err := bot.Send(chat, msg)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *BonusController) Bonus(c tele.Context) error {
|
||||||
|
var text string
|
||||||
|
var chatID int64 = -1002345923642
|
||||||
|
|
||||||
|
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 bonus", text)
|
||||||
|
} else {
|
||||||
|
return c.Send("Некоректная команда, используйте /bonus1 <сумма>")
|
||||||
|
}
|
||||||
|
|
||||||
|
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)))
|
||||||
|
btn.Inline(row)
|
||||||
|
|
||||||
|
msg, err := b.Bot.Send(
|
||||||
|
&tele.Chat{ID: chatID},
|
||||||
|
fmt.Sprintf("Успей забрать бонус.\nСумма: %d", giftSumm),
|
||||||
|
btn,
|
||||||
|
)
|
||||||
|
|
||||||
|
b.Bot.Handle(&row[0], func(c tele.Context) error {
|
||||||
|
user := b.DC.GetUser(c.Sender().ID)
|
||||||
|
newSize := user.DickSize + giftSumm
|
||||||
|
b.DC.UpdateDick(c.Sender().ID, newSize)
|
||||||
|
b.Bot.Edit(msg, fmt.Sprintf("%s получает бонус: %d", c.Sender().FirstName, giftSumm))
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
fmt.Println(giftSumm)
|
||||||
|
|
||||||
|
return c.Send(fmt.Sprintf("Бонус запущен: %d", giftSumm))
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user