1
1
package main
2
2
3
3
import (
4
- "io/ioutil"
5
- "os"
6
- "fmt"
4
+ "bytes"
5
+ "crypto/tls"
6
+ "encoding/base64"
7
+ "encoding/json"
7
8
"errors"
9
+ "fmt"
8
10
"github.com/onescriptkid/disenchant/utils"
11
+ "io/ioutil"
12
+ "log"
13
+ "net/http"
14
+ "os"
9
15
"path/filepath"
10
16
"strings"
11
- "encoding/base64"
12
- "net/http"
13
- "time"
14
- "crypto/tls"
15
- "encoding/json"
16
17
"sync"
17
- "bytes"
18
- "log"
19
- // "io"
18
+ "time"
20
19
)
21
20
22
21
type RiotLoot struct {
23
22
DisenchantLootName string `json:"disenchantLootName"`
24
- ItemStatus string `json:"itemStatus"`
25
- ItemDesc string `json:"itemDesc"`
26
- LootName string `json:"lootName"`
27
- Count int `json:"count"`
28
- Type string `json:"type"`
23
+ ItemStatus string `json:"itemStatus"`
24
+ ItemDesc string `json:"itemDesc"`
25
+ LootName string `json:"lootName"`
26
+ Count int `json:"count"`
27
+ Type string `json:"type"`
29
28
}
30
29
31
30
func main () {
31
+ // Fix colorred terminal output specific to windows cmd prompt
32
+ utils .FixWindowsColors ()
33
+
34
+ // Show Title and set trap to always prompt user before quiting. Prevents app from immediately closing on finish.
32
35
utils .Title ("Disenchanting blue essence ..." )
33
36
defer utils .OnFinish ()
34
37
@@ -37,7 +40,7 @@ func main() {
37
40
if err != nil {
38
41
utils .ErrorFatal (err )
39
42
}
40
-
43
+
41
44
// Build http client to interact with Riot Lol client api
42
45
client , err := BuildHttpClient (port , token )
43
46
if err != nil {
@@ -53,7 +56,7 @@ func main() {
53
56
AreYouSure ()
54
57
55
58
// Disenchant champion shards
56
- err = DisenchantChampionShards (client , port , token , champions )
59
+ err = DisenchantChampionShards (client , port , token , champions )
57
60
if err != nil {
58
61
utils .ErrorFatal (err )
59
62
}
@@ -62,9 +65,9 @@ func main() {
62
65
}
63
66
64
67
// Get Port and Token from LoL Riot lockfile
65
- func getPortAndToken () ( port string , token string , err error ) {
68
+ func getPortAndToken () (port string , token string , err error ) {
66
69
utils .Header ("Searching for lockfile ..." )
67
-
70
+
68
71
// Retrieve standard set of lockfile paths
69
72
paths , pathErr := utils .GetLockFilePaths ()
70
73
if err != nil {
@@ -86,14 +89,14 @@ func getPortAndToken() ( port string, token string, err error ) {
86
89
87
90
// If lockfile found, exit loop. Otherwise, keep searching.
88
91
lockfilePath = abs
89
- _ , err = os .Stat (lockfilePath );
92
+ _ , err = os .Stat (lockfilePath )
90
93
if err == nil {
91
94
msg := fmt .Sprintf (" Found %s. Parsing lockfile ..." , lockfilePath )
92
95
foundLockfile = true
93
96
fmt .Println (msg )
94
97
break
95
98
} else if errors .Is (err , os .ErrNotExist ) {
96
- msg := fmt .Sprintf (" Missing %s. Seaching other locations for lockfile" , lockfilePath )
99
+ msg := fmt .Sprintf (" Missing %s. Seaching other locations for lockfile ... " , lockfilePath )
97
100
utils .Warn (msg )
98
101
} else {
99
102
return
@@ -133,18 +136,18 @@ func getPortAndToken() ( port string, token string, err error ) {
133
136
}
134
137
135
138
// Build http client to interact with Riot Lol client api
136
- func BuildHttpClient (port string , token string )(client http.Client , err error ) {
139
+ func BuildHttpClient (port string , token string ) (client http.Client , err error ) {
137
140
utils .Header ("Building http client ..." )
138
141
139
142
// Instantiate http client
140
- tr := & http.Transport { TLSClientConfig : & tls.Config {InsecureSkipVerify : true } }
143
+ tr := & http.Transport {TLSClientConfig : & tls.Config {InsecureSkipVerify : true }}
141
144
client = http.Client {Timeout : time .Duration (10 ) * time .Second , Transport : tr }
142
145
143
146
return
144
147
}
145
148
146
149
// List all champion shards convertable to blue essence
147
- func ListChampionShards (client http.Client , port string , token string )(champions []RiotLoot , err error ) {
150
+ func ListChampionShards (client http.Client , port string , token string ) (champions []RiotLoot , err error ) {
148
151
utils .Header ("Searching for champions to disenchant ..." )
149
152
host := fmt .Sprintf ("https://127.0.0.1:%s" , port )
150
153
auth := fmt .Sprintf ("Basic %s" , token )
@@ -187,12 +190,15 @@ func ListChampionShards(client http.Client, port string, token string)(champions
187
190
json .NewDecoder (res .Body ).Decode (& riotLoot )
188
191
189
192
// Iterate over all RiotLoot and only select champion shards that are owned for disenchanting
193
+ total := 0
190
194
for _ , loot := range riotLoot {
191
195
if loot .DisenchantLootName == "CURRENCY_champion" && loot .ItemStatus == "OWNED" {
192
- fmt .Printf (" Found %4v %s \n " , loot .Count , loot .ItemDesc , )
196
+ fmt .Printf (" Found %4v %s \n " , loot .Count , loot .ItemDesc )
193
197
champions = append (champions , loot )
198
+ total += loot .Count
194
199
}
195
200
}
201
+ fmt .Printf ("Total %v champions to disenchant ... \n " , total )
196
202
197
203
return
198
204
}
@@ -202,20 +208,20 @@ func AreYouSure() {
202
208
var input string
203
209
204
210
for input != "y" && input != "Y" {
205
- utils .Title ("Are you sure? Press [y] to continue or [n] to quit... \n " )
206
- fmt .Scan (& input )
211
+ utils .Title ("Are you sure? Press [y] to continue or [n] to quit\n " )
212
+ fmt .Scanln (& input )
207
213
208
214
// Quit if n or N
209
- if ( input == "n" || input == "N" ) {
215
+ if input == "n" || input == "N" {
210
216
no := errors .New ("Quitting ..." )
211
217
utils .ErrorFatal (no )
212
218
}
213
219
}
214
220
215
221
}
216
222
217
- // Disenchant all champion shards found on the account
218
- func DisenchantChampionShards (client http.Client , port string , token string , champions []RiotLoot )( err error ) {
223
+ // Disenchant all champion shards found on the account
224
+ func DisenchantChampionShards (client http.Client , port string , token string , champions []RiotLoot ) ( err error ) {
219
225
utils .Header ("Disenchanting champions ..." )
220
226
host := fmt .Sprintf ("https://127.0.0.1:%s" , port )
221
227
auth := fmt .Sprintf ("Basic %s" , token )
@@ -260,23 +266,22 @@ func DisenchantChampionShards(client http.Client, port string, token string, cha
260
266
return
261
267
}
262
268
263
- // Print JSON response from disenchant post request
264
- // Uncomment to print result of disenchant post request json
269
+ // Uncomment to print JSON response for disenchant POST request
265
270
// b, err := io.ReadAll(res.Body)
266
271
// if err != nil {
267
272
// log.Fatalln(err)
268
273
// }
269
274
// fmt.Println(string(b))
270
275
// fmt.Printf(" Url %s\n", url)
271
276
// fmt.Printf(" Auth %s\n", auth)
277
+
272
278
wg .Done ()
273
279
}(client , port , token , champion )
274
280
}
275
-
281
+
276
282
// Wait for every thread to finish
277
283
wg .Wait ()
278
284
279
285
return
280
286
281
287
}
282
-
0 commit comments