You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
2.3KB

  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "math/rand"
  6. "net/http"
  7. "net/url"
  8. "strconv"
  9. "strings"
  10. "time"
  11. )
  12. func enterGiveaways(cookie *http.Cookie, enterWishlist bool) {
  13. if enterWishlist {
  14. fmt.Println("wishlist")
  15. } else {
  16. fmt.Println("all")
  17. }
  18. page := 1
  19. for {
  20. var index string
  21. if enterWishlist {
  22. index = getResultsPage(pagingURL+strconv.Itoa(page)+wishlistURL, cookie)
  23. } else {
  24. index = getResultsPage(pagingURL+strconv.Itoa(page), cookie)
  25. }
  26. if index == "" {
  27. fmt.Println("Cookie is wrong or something")
  28. return
  29. } else if strings.Contains(index, bannedString) {
  30. fmt.Println("Banned, skipping...")
  31. return
  32. }
  33. xsrfToken := xsrfRegex.FindStringSubmatch(index)[1]
  34. points := pointsRegex.FindStringSubmatch(index)[1]
  35. pointsInt, err := strconv.ParseInt(points, 10, 16)
  36. if err != nil {
  37. log.Fatalln(err)
  38. }
  39. giveaways2D := mainRegex.FindAllStringSubmatch(index, 120)
  40. giveaways := convert2DsliceTo1D(giveaways2D)
  41. giveaways = removeDuplicatesUnordered(giveaways)
  42. if len(giveaways) <= 1 && enterWishlist {
  43. fmt.Println("No more games on wishlist")
  44. return
  45. }
  46. for _, givewayID := range giveaways {
  47. pointsInt, err = strconv.ParseInt(points, 10, 16)
  48. if err != nil {
  49. log.Fatalln(err)
  50. }
  51. if pointsInt <= 0 {
  52. fmt.Println("No points left, exiting")
  53. return
  54. }
  55. postData := url.Values{}
  56. postData.Add("xsrf_token", xsrfToken)
  57. postData.Add("do", "entry_insert")
  58. postData.Add("code", givewayID)
  59. postResponse := sendRequest(mainURL+"/ajax.php", cookie, &postData)
  60. fmt.Println(postResponse)
  61. points = pointsResponseRegex.FindStringSubmatch(postResponse)[1]
  62. rand.Seed(time.Now().UnixNano())
  63. duration := rand.Intn(20) + 30
  64. time.Sleep(time.Duration(duration) * time.Second)
  65. }
  66. if err != nil {
  67. log.Fatalln(err)
  68. }
  69. page++
  70. }
  71. }
  72. func main() {
  73. createCookieFile()
  74. cookieValue := loadCookieFile()
  75. cookie := http.Cookie{Name: cookieName, Value: cookieValue}
  76. if len(cookieValue) < 2 {
  77. log.Fatalln("Wrong cookie mate, too short")
  78. }
  79. quitChan := make(chan bool)
  80. go func() {
  81. <-time.After(timeToRunFor)
  82. close(quitChan)
  83. }()
  84. t := time.NewTicker(timeToSleepFor)
  85. // enter first manually
  86. go doStuff(&cookie)
  87. func() {
  88. for {
  89. select {
  90. case <-t.C:
  91. go doStuff(&cookie)
  92. case <-quitChan:
  93. t.Stop()
  94. return
  95. }
  96. }
  97. }()
  98. log.Println(timeToRunFor.String() + " passed. Exiting.")
  99. }