-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
195 lines (156 loc) · 5.7 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
package main
import (
"crewInator/socialclub"
"errors"
"fmt"
"log"
"os"
"runtime"
"strings"
"sync"
"time"
"github.com/atotto/clipboard"
"github.com/briandowns/spinner"
"github.com/fatih/color"
"github.com/manifoldco/promptui"
"github.com/valyala/fasthttp"
)
func doPromotion(wg *sync.WaitGroup, url string, token string) {
defer wg.Done()
if url == "" {
return
}
req := fasthttp.AcquireRequest()
resp := fasthttp.AcquireResponse()
defer fasthttp.ReleaseRequest(req)
defer fasthttp.ReleaseResponse(resp)
req.SetRequestURI(url)
req.Header.SetMethod("POST")
req.Header.Set("Authorization", token)
req.Header.Set("X-Requested-With", "XMLHttpRequest")
if err := fasthttp.Do(req, resp); err != nil {
log.Printf("Error sending request to %s: %v", url, err)
return
}
statusCode := resp.StatusCode()
body := resp.Body()
if statusCode != 200 {
log.Printf("Promotion %s failed: Status Code: %d, Response: %s", url, statusCode, body)
return
}
}
func getPromotionUrl(crewID int, rid int) string {
return fmt.Sprintf("https://scapi.rockstargames.com/crew/promote?crewId=%d&rockstarIds=%d&newRankOrder=0", crewID, rid)
}
func handleCrewPromotion(crewName string, bearerToken string) error {
crewName = strings.ReplaceAll(crewName, " ", "_")
bearerToken = "Bearer " + bearerToken
basicCrewInfo, err := socialclub.GetBasicCrewInfo(crewName)
if err != nil || !basicCrewInfo.Status {
return errors.New("failed to convert crew name to crewID")
}
crewHierarchy, err := socialclub.GetCrewHierarchy(basicCrewInfo.CrewID)
if err != nil || !crewHierarchy.Status {
return errors.New("failed to fetch crew hierarchy")
}
crewRanks := crewHierarchy.CrewRanks
if len(crewRanks) < 2 {
return errors.New("failed to find commissioner rank")
}
comissionerMembers := crewRanks[1].RankMembers
// Doing this dirty shit so goroutines don't have to do any additional progressing and send at nearly the exact same time
promotion1 := ""
promotion2 := ""
promotion3 := ""
promotion4 := ""
promotion5 := ""
lengthRids := len(comissionerMembers)
if lengthRids > 0 {
promotion1 = getPromotionUrl(basicCrewInfo.CrewID, comissionerMembers[0].RockstarID)
}
if lengthRids > 1 {
promotion2 = getPromotionUrl(basicCrewInfo.CrewID, comissionerMembers[1].RockstarID)
}
if lengthRids > 2 {
promotion3 = getPromotionUrl(basicCrewInfo.CrewID, comissionerMembers[2].RockstarID)
}
if lengthRids > 3 {
promotion4 = getPromotionUrl(basicCrewInfo.CrewID, comissionerMembers[3].RockstarID)
}
if lengthRids > 4 {
promotion5 = getPromotionUrl(basicCrewInfo.CrewID, comissionerMembers[4].RockstarID)
}
var wg sync.WaitGroup
for i := 0; i < 4; i++ {
wg.Add(5)
go doPromotion(&wg, promotion1, bearerToken)
go doPromotion(&wg, promotion2, bearerToken)
go doPromotion(&wg, promotion3, bearerToken)
go doPromotion(&wg, promotion4, bearerToken)
go doPromotion(&wg, promotion5, bearerToken)
}
wg.Wait()
return nil
}
func main() {
jsCode := `function gT(){let t=decodeURIComponent(document.cookie).split(";"),e="BearerToken=";for(let o of t)if((o=o.trim()).startsWith(e)){let i=o.substring(e.length,o.length);navigator.clipboard.writeText(i).then(()=>{alert("Copied To Clipboard")}).catch(t=>{console.log("Copy this:",i),alert("Copy this: "+i)});return}alert("You don't seem to be logged in")}gT();`
if runtime.GOOS == "windows" { // windows don't support colors, for the most part :[
color.NoColor = true
}
red := color.New(color.FgRed).SprintFunc()
green := color.New(color.FgGreen).SprintFunc()
blue := color.New(color.FgBlue).SprintFunc()
bold := color.New(color.Bold).SprintFunc()
fmt.Println(bold("Welcome to CrewInator! This tool helps you promote leaders in your Social Club crew."))
fmt.Println()
fmt.Println("How to use CrewInator:")
fmt.Printf("%s. Log in to your Social Club account with leader privileges.\n", green("1"))
fmt.Printf("%s. Promote up to 5 people to 'commissioner' rank.\n", green("2"))
fmt.Printf("%s. Go to your crew's page and get the crew name from the URL.\n", green("3"))
fmt.Printf("%s. Open the browser console (right-click -> Inspect -> Console) and paste this JS code:\n", green("4"))
fmt.Println()
fmt.Println(blue(jsCode))
fmt.Println()
if clipboardContent, _ := clipboard.ReadAll(); strings.TrimSpace(clipboardContent) == "" {
clipboard.WriteAll(jsCode)
fmt.Println(green("(The JavaScript code has been copied to your clipboard.)"))
} else {
fmt.Println(blue("(JavaScript code not copied because your clipboard contains other data.)"))
}
fmt.Println()
fmt.Printf("%s. Copy the output Bearer Token, and enter it into the prompt here.\n", green("5"))
fmt.Println()
prompt := promptui.Prompt{
Label: "Enter the crew name",
}
crewName, err := prompt.Run()
if err != nil {
log.Fatalf(red("Prompt failed %v\n"), err)
}
tokenPrompt := promptui.Prompt{
Label: "Enter the bearer token",
Mask: '*',
}
bearerToken, err := tokenPrompt.Run()
if err != nil {
log.Fatalf(red("Prompt failed %v\n"), err)
}
if !strings.HasPrefix(bearerToken, "eyJ") { // 'eyJ' is base64 for '{"'
fmt.Println(red("Your input does not seem to be a BearerToken. Make sure you copied the JavaScript's output correctly. BearerTokens start with 'eyJ'."))
time.Sleep(10 * time.Second)
os.Exit(1)
}
fmt.Println()
s := spinner.New(spinner.CharSets[14], 100*time.Millisecond)
s.Start()
err = handleCrewPromotion(crewName, bearerToken)
s.Stop()
if err != nil {
fmt.Println(red(fmt.Sprintf("Failed to do promotions: %s", err.Error())))
time.Sleep(10 * time.Second)
os.Exit(1)
}
fmt.Println(green("Promotion requests sent. Depending on timing, multiple leaders may be promoted."))
fmt.Println("If you encounter issues, try the hosted service at https://crew.dudx.info/")
time.Sleep(10 * time.Second)
}