forked from drunkleen/blum-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
250 lines (209 loc) · 6.85 KB
/
main.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
package main
import (
"fmt"
"log"
"math/rand"
"strconv"
"time"
"github.com/drunkleen/blum-bot/requests"
"github.com/drunkleen/blum-bot/utils"
"github.com/fatih/color"
)
var (
startTime time.Time
checkedTasksMap map[string]bool = map[string]bool{}
tokenMap map[string]string = map[string]string{}
checkTaskEnable bool
claimRefEnable bool
initStage bool = true
printText string = ""
bold = color.New(color.Bold).SprintFunc()
red = color.New(color.FgRed).SprintFunc()
cyan = color.New(color.FgCyan).SprintFunc()
green = color.New(color.FgGreen).SprintFunc()
yellow = color.New(color.FgYellow).SprintFunc()
)
func init() {
startTime = time.Now()
}
func main() {
utils.ClearScreen()
utils.PrintLogo()
checkTaskEnable, claimRefEnable = utils.ParseArgs()
fmt.Printf("Task: %v\n", checkTaskEnable)
fmt.Printf("Reff: %v\n", claimRefEnable)
queryList, err := utils.ParseQueries()
if err != nil {
log.Fatalf(red("QueryList Error: %v\n"), err)
}
mainLoop(queryList)
}
func mainLoop(queryList []string) {
utils.ClearScreen()
nowTime := time.Now()
nextTrigger := time.Now()
if nextTrigger.Before(nowTime) {
nextTrigger = nextTrigger.Add(2 * time.Hour)
}
for { // start infinite loop
now := time.Now()
for _, queryID := range queryList { // start query loop
// get Token if not exists
val, exists := tokenMap[queryID]
if !exists || val == "" {
newToken, err := requests.GetNewToken(queryID)
if err != nil {
log.Printf(red("Error: %v\n"), err)
}
tokenMap[queryID] = newToken
}
token := tokenMap[queryID]
// fetching user info
userInfo, err := requests.GetUserInfo(token, queryID)
if err != nil {
if err.Error() == "token is invalid" {
newToken, err := requests.GetNewToken(queryID)
if err != nil {
log.Printf(red("Error: %v\n"), err)
}
tokenMap[queryID] = newToken
} else {
log.Printf(red("Error: %v\n"), err)
}
}
username := userInfo["username"]
printText += fmt.Sprintf("---\n"+"["+bold(cyan("User"))+"] "+"%s\n", bold(green(username)))
if initStage {
fmt.Printf("---\nUser: %s\n", bold(username))
}
// fetching balance info
balanceInfo, err := requests.GetUserBalance(token)
if err != nil {
log.Printf(red("Error: %v\n"), err)
}
printText += fmt.Sprintf("["+bold(cyan("Balance"))+"] "+"%v\n", balanceInfo.AvailableBalance)
if initStage {
fmt.Printf("[Balance] %v\n", bold(cyan(balanceInfo.AvailableBalance)))
}
nextFarmingTime, _ := utils.TimeLeft(balanceInfo.Farming.EndTime)
if balanceInfo.Farming.Balance != "57.6" {
printText += fmt.Sprintf("["+bold(cyan("Farming"))+"] "+"next claim %v remaining", nextFarmingTime)
printText += fmt.Sprintf(" | Earned: %v\n", balanceInfo.Farming.Balance)
} else {
ok, err := requests.ClaimFarm(token)
if err != nil {
log.Printf(red("Error: %v\n"), err)
}
if ok {
printText += fmt.Sprintf("[" + bold(cyan("Farming")) + "] " + "claimed successfully!\n")
} else {
printText += fmt.Sprintf("[" + bold(cyan("Farming")) + "] " + "Failed to claim farm!\n")
}
ok, err = requests.StartFarm(token)
if err != nil {
log.Printf(red("Error: %v\n"), err)
}
if ok {
printText += fmt.Sprintf("[" + bold(cyan("Farming")) + "] " + "started farming successfully!\n")
} else {
printText += fmt.Sprintf("[" + bold(cyan("Farming")) + "] " + "Failed to start farming!\n")
}
}
// Check Daily Rewards
dailyRewardResponse, err := requests.CheckDailyReward(token)
if err != nil {
log.Printf(red("Error: %v\n"), err)
}
switch dailyRewardResponse["message"] {
case "same day":
printText += fmt.Sprintf("[" + bold(cyan("Daily Reward")) + "] " + " already claimed today\n")
case "OK":
printText += fmt.Sprintf("[" + bold(cyan("Daily Reward")) + "] " + " successfully claimed!\n")
default:
printText += fmt.Sprintf("[" + bold(cyan("Daily Reward")) + "] " + " Failed to check daily reward!\n")
}
if checkTaskEnable {
checked, exists := checkedTasksMap[queryID]
if !exists || !checked {
fmt.Println("Checking tasks...")
requests.CheckTasks(token)
checkedTasksMap[queryID] = true
}
}
if claimRefEnable {
friendsBalance, err := requests.CheckBalanceFriend(token)
if friendsBalance.AmountForClaim != "0" || friendsBalance.CanClaim {
if err != nil {
log.Printf(red("[Referrals Balance] Failed to get friend's balance: %v\n"), err)
}
printText += fmt.Sprintf("[" + bold(cyan("Referrals")) + "] ")
printText += fmt.Sprintf(yellow("amount: %v"), friendsBalance.AmountForClaim)
printText += fmt.Sprintf(yellow(" | Claimable: %v"), friendsBalance.CanClaim)
var claimTime int64
if friendsBalance.CanClaimAt != "" {
claimTime, err = strconv.ParseInt(friendsBalance.CanClaimAt, 10, 64)
if err != nil {
log.Printf(red("[Referrals] Failed to parse claim time: %v\n"), err)
}
remainingClaimTime, err := utils.TimeLeft(claimTime)
if err != nil {
log.Printf(red("[Referrals] Failed to calculate remaining claim time: %v\n"), err)
}
printText += fmt.Sprintf(yellow(" | %v remaining\n"), remainingClaimTime)
} else {
printText += "\n"
}
if friendsBalance.CanClaim {
ok, err := requests.ClaimBalanceFriend(token)
if err != nil {
log.Printf(red("[Referrals] Failed to claim friend's balance: %v\n"), err)
}
if ok {
printText += fmt.Sprintf(bold(cyan("[Referrals]")) + " successfully claimed!\n")
}
}
}
}
printText += fmt.Sprintf("[%v] %v tickets\n", bold(cyan("Play Passes")), balanceInfo.PlayPasses)
for balanceInfo.PlayPasses > 0 { // game loop
gameResponse, err := requests.PlayGame(token)
if err != nil {
fmt.Printf("Error: %v\n", err)
} else {
fmt.Printf("Game played successfully: %v\n", gameResponse)
}
if gameId, ok := gameResponse["gameId"].(string); ok {
requests.ClaimGame(token, gameId, queryID, func() int {
return rand.Intn(1999-1301) + 1301
}())
}
balanceInfo.PlayPasses--
} // end game loop
} // end queryList loop
if now.After(nextTrigger) || now.Equal(nextTrigger) {
for i := 0; i < 3; i++ {
for _, token := range tokenMap {
fmt.Println("\nClaiming daily reward")
_, err := requests.GetDailyRewards(token)
if err != nil {
fmt.Printf(red("Error: %v\n"), err)
}
}
}
nextTrigger = nextTrigger.Add(2 * time.Hour)
}
if initStage {
initStage = !initStage
} else {
time.Sleep(time.Duration(rand.Intn(3600-900)+512) * time.Second)
}
h, m, _ := now.Clock()
utils.ClearScreen()
utils.PrintLogo()
fmt.Printf(
"-------- Time: %d:%d --------\n%v\n------------ Up Time: %v ------------",
h, m, printText, yellow(utils.FormatUpTime(time.Since(startTime))),
)
printText = ""
} // end infinite loop
}