Skip to content

Commit

Permalink
auto start farm added
Browse files Browse the repository at this point in the history
  • Loading branch information
drunkleen committed Jun 27, 2024
1 parent 69dccd0 commit 71168ae
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 20 deletions.
17 changes: 12 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,10 @@ func mainLoop(queryList []string) {
fmt.Printf("[Balance] %v\n", bold(cyan(balanceInfo.AvailableBalance)))
}

nextFarmingTime, err := utils.ConvertStrTimestamp(fmt.Sprintf("%d", balanceInfo.Farming.EndTime))
if err != nil {
log.Printf(red(red("Error: %v\n")), err)
}
nextFarmingTime, _ := utils.TimeLeft(balanceInfo.Farming.EndTime)

if balanceInfo.Farming.EndTime != 0 && time.Unix(balanceInfo.Farming.EndTime, 0).After(time.Now()) {
printText += fmt.Sprintf("["+bold(cyan("Farming"))+"] "+"next claim %v", nextFarmingTime)
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)
Expand All @@ -105,6 +102,16 @@ func mainLoop(queryList []string) {
} 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
Expand Down
28 changes: 28 additions & 0 deletions requests/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,3 +605,31 @@ func ClaimFarm(token string) (bool, error) {

return true, nil
}

func StartFarm(token string) (bool, error) {
url := "https://game-domain.blum.codes/api/v1/farming/start"
headers := getHeaders
headers["Authorization"] = "Bearer " + token

req, err := http.NewRequest("POST", url, nil)
if err != nil {
return false, fmt.Errorf("failed to create request: %w", err)
}

for key, value := range headers {
req.Header.Set(key, value)
}

client := &http.Client{Timeout: 10 * time.Second}
resp, err := client.Do(req)
if err != nil {
return false, fmt.Errorf("failed to start farm: %w", err)
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return false, fmt.Errorf("unexpected status code: %d", resp.StatusCode)
}

return true, nil
}
15 changes: 0 additions & 15 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,6 @@ type UserBalance struct {
} `json:"farming"`
}

//type Farming struct {
// StartTime int64 `json:"startTime"`
// EndTime int64 `json:"endTime"`
// EarningsRate float64 `json:"earningsRate"`
// Balance float64 `json:"balance"`
//}
//
//// UserBalance represents the response from the '/v1/user/balance' endpoint.
//type UserBalance struct {
// AvailableBalance string `json:"availableBalance"`
// PlayPasses uint64 `json:"playPasses"`
// Timestamp int64 `json:"timestamp"`
// Farming
//}

// FriendsBalance represents the response from the '/v1/friends/balance' endpoint.
type FriendsBalance struct {
LimitInvitation string `json:"limitInvitation"`
Expand Down
22 changes: 22 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,25 @@ func ConvertStrTimestamp(timestampStr string) (string, error) {

return humanReadableTime, nil
}

func TimeLeft(futureTimestamp int64) (string, error) {

seconds := futureTimestamp / 1000
nanoseconds := (futureTimestamp % 1000) * 1e6

t := time.Unix(seconds, nanoseconds)

currentTime := time.Now()

duration := t.Sub(currentTime)

if duration < 0 {
return "00:00:00", nil
}

hours := int(duration.Hours())
minutes := int(duration.Minutes()) % 60
seconds = int64(duration.Seconds()) % 60

return fmt.Sprintf("%02d:%02d:%02d", hours, minutes, seconds), nil
}

0 comments on commit 71168ae

Please sign in to comment.