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.

121 lines
2.6KB

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