-
Notifications
You must be signed in to change notification settings - Fork 3
/
callback.go
96 lines (83 loc) · 1.97 KB
/
callback.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import (
"fmt"
"log"
"strconv"
"gopkg.in/telegram-bot-api.v4"
)
func buy(call *tgbotapi.CallbackQuery, number string) {
num, err := strconv.Atoi(number)
if err != nil {
err.Error()
}
username := call.From.UserName
var us User
db.First(&us, "name = ?", username)
fmt.Println(us.Money)
var reply tgbotapi.MessageConfig
if us.Money >= videos[num].Cost {
us.Money -= videos[num].Cost
fmt.Println(us.Money)
if num == 0 {
us.Mayner1++
} else if num == 1 {
us.Mayner2++
} else if num == 2 {
us.Mayner3++
} else if num == 3 {
us.Mayner4++
}
db.Save(&us)
reply = tgbotapi.NewMessage(int64(call.From.ID), fmt.Sprintf("Куплено /video"))
} else {
reply = tgbotapi.NewMessage(int64(call.From.ID), "Недостаточно денег")
}
_, err = bot.Send(reply)
if err != nil {
err.Error()
}
}
func changeValue(call *tgbotapi.CallbackQuery, number string) {
id, err := strconv.Atoi(number)
if err != nil {
log.Println(err)
}
var val CryptoValue
db.First(&val, id)
fmt.Println(val)
var us User
db.First(&us, "name = ?", call.From.UserName)
us.CryptoValue = val
db.Save(&us)
reply := tgbotapi.NewMessage(
int64(call.From.ID),
fmt.Sprintf("Майним %s", val.Name),
)
_, err = bot.Send(reply)
if err != nil {
log.Fatal(err)
}
}
func sellAll(call *tgbotapi.CallbackQuery) {
var message string
message = "Успешно продано!\nBTC - %d\nР - %d"
username := call.From.UserName
var us User
db.First(&us, "name = ?", username)
var reply tgbotapi.MessageConfig
if us.Score >= 500 {
us.Money += int(us.Score / 500)
us.Score -= (us.Score / 500) * 500
db.Model(&us).Update(User{
Score: us.Score,
Money: us.Money,
})
reply = tgbotapi.NewMessage(int64(call.From.ID), fmt.Sprintf(message, us.Score, us.Money))
} else {
reply = tgbotapi.NewMessage(int64(call.From.ID), "Слишком мало b чтобы продать!!!")
}
_, err := bot.Send(reply)
if err != nil {
err.Error()
}
}