Skip to content

Commit c956c0e

Browse files
authored
Merge pull request #14 from SkyCryptWebsite/dev
bump prod
2 parents 476fd8c + 0567674 commit c956c0e

7 files changed

Lines changed: 132 additions & 15 deletions

File tree

NotEnoughUpdates-REPO

src/NotEnoughUpdates/main.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,18 @@ func UpdateNEURepository() error {
6464
// fmt.Println("[NOT-ENOUGH-UPDATES] Already up to date")
6565
return nil
6666
}
67-
return fmt.Errorf("failed to pull: %w", err)
67+
68+
fmt.Printf("[NOT-ENOUGH-UPDATES] Pull failed (%v), removing and re-cloning repository...\n", err)
69+
if removeErr := os.RemoveAll("NotEnoughUpdates-REPO"); removeErr != nil {
70+
return fmt.Errorf("failed to remove corrupted repository: %w", removeErr)
71+
}
72+
73+
if initErr := InitializeNEURepository(); initErr != nil {
74+
return fmt.Errorf("failed to re-clone repository: %w", initErr)
75+
}
76+
77+
fmt.Println("[NOT-ENOUGH-UPDATES] Repository re-cloned successfully")
78+
return nil
6879
}
6980

7081
ref, err := repo.Head()

src/api/hypixel.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,19 @@ func GetPlayer(uuid string) (*skycrypttypes.Player, error) {
4444
}
4545
defer resp.Body.Close()
4646

47+
if resp.StatusCode != http.StatusOK {
48+
return &response, fmt.Errorf("API returned status code: %d", resp.StatusCode)
49+
}
50+
4751
body, err := io.ReadAll(resp.Body)
4852
if err != nil {
4953
return &response, fmt.Errorf("error reading response: %v", err)
5054
}
5155

56+
if len(body) == 0 {
57+
return &response, fmt.Errorf("received empty response from API")
58+
}
59+
5260
var json = jsoniter.ConfigCompatibleWithStandardLibrary
5361
err = json.Unmarshal(body, &rawReponse)
5462
if err != nil {
@@ -85,11 +93,19 @@ func GetProfiles(uuid string) (*models.HypixelProfilesResponse, error) {
8593
}
8694
defer resp.Body.Close()
8795

96+
if resp.StatusCode != http.StatusOK {
97+
return &response, fmt.Errorf("API returned status code: %d", resp.StatusCode)
98+
}
99+
88100
body, err := io.ReadAll(resp.Body)
89101
if err != nil {
90102
return &response, fmt.Errorf("error reading response: %v", err)
91103
}
92104

105+
if len(body) == 0 {
106+
return &response, fmt.Errorf("received empty response from API")
107+
}
108+
93109
var json = jsoniter.ConfigCompatibleWithStandardLibrary
94110
err = json.Unmarshal(body, &response)
95111
if err != nil {
@@ -154,11 +170,19 @@ func GetMuseum(profileId string) (map[string]*skycrypttypes.Museum, error) {
154170
}
155171
defer resp.Body.Close()
156172

173+
if resp.StatusCode != http.StatusOK {
174+
return nil, fmt.Errorf("API returned status code: %d", resp.StatusCode)
175+
}
176+
157177
body, err := io.ReadAll(resp.Body)
158178
if err != nil {
159179
return nil, fmt.Errorf("error reading response: %v", err)
160180
}
161181

182+
if len(body) == 0 {
183+
return nil, fmt.Errorf("received empty response from API")
184+
}
185+
162186
var json = jsoniter.ConfigCompatibleWithStandardLibrary
163187
err = json.Unmarshal(body, &rawReponse)
164188
if err != nil {
@@ -187,11 +211,19 @@ func GetGarden(profileId string) (*skycrypttypes.Garden, error) {
187211
}
188212
defer resp.Body.Close()
189213

214+
if resp.StatusCode != http.StatusOK {
215+
return nil, fmt.Errorf("API returned status code: %d", resp.StatusCode)
216+
}
217+
190218
body, err := io.ReadAll(resp.Body)
191219
if err != nil {
192220
return nil, fmt.Errorf("error reading response: %v", err)
193221
}
194222

223+
if len(body) == 0 {
224+
return nil, fmt.Errorf("received empty response from API")
225+
}
226+
195227
var json = jsoniter.ConfigCompatibleWithStandardLibrary
196228
err = json.Unmarshal(body, &rawReponse)
197229
if err != nil {

src/api/hypixel_constants.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,19 @@ func getSkyBlockItems() ([]models.HypixelItem, error) {
3131
}
3232
defer resp.Body.Close()
3333

34+
if resp.StatusCode != http.StatusOK {
35+
return nil, fmt.Errorf("API returned status code: %d", resp.StatusCode)
36+
}
37+
3438
body, err := io.ReadAll(resp.Body)
3539
if err != nil {
3640
return nil, fmt.Errorf("error reading response: %v", err)
3741
}
3842

43+
if len(body) == 0 {
44+
return nil, fmt.Errorf("received empty response from API")
45+
}
46+
3947
var json = jsoniter.ConfigCompatibleWithStandardLibrary
4048
var data models.HypixelItemsResponse
4149
err = json.Unmarshal(body, &data)
@@ -65,11 +73,19 @@ func GetSkyBlockCollections() (map[string]models.HypixelCollection, error) {
6573
}
6674
defer resp.Body.Close()
6775

76+
if resp.StatusCode != http.StatusOK {
77+
return nil, fmt.Errorf("API returned status code: %d", resp.StatusCode)
78+
}
79+
6880
body, err := io.ReadAll(resp.Body)
6981
if err != nil {
7082
return nil, fmt.Errorf("error reading response: %v", err)
7183
}
7284

85+
if len(body) == 0 {
86+
return nil, fmt.Errorf("received empty response from API")
87+
}
88+
7389
var json = jsoniter.ConfigCompatibleWithStandardLibrary
7490
var data models.HypixelCollectionsResponse
7591
err = json.Unmarshal(body, &data)

src/api/mowojang.go

Lines changed: 69 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ import (
1313
jsoniter "github.com/json-iterator/go"
1414
)
1515

16-
func GetUUID(username string) (string, error) {
16+
func GetUUID(username string, throwAnError ...bool) (string, error) {
17+
shouldThrowError := true
18+
if len(throwAnError) > 0 {
19+
shouldThrowError = throwAnError[0]
20+
}
21+
1722
var post models.MowojangReponse
1823

1924
cache, err := redis.Get(fmt.Sprintf("uuid:%s", strings.ToLower(username)))
@@ -23,23 +28,43 @@ func GetUUID(username string) (string, error) {
2328

2429
resp, err := http.Get(fmt.Sprintf("https://mowojang.matdoes.dev/%s", username))
2530
if err != nil {
26-
return post.UUID, fmt.Errorf("error making request: %v", err)
31+
if shouldThrowError {
32+
return post.UUID, fmt.Errorf("error making request: %v", err)
33+
}
34+
return "", nil
2735
}
2836
defer resp.Body.Close()
2937

3038
body, err := io.ReadAll(resp.Body)
3139
if err != nil {
32-
return post.UUID, fmt.Errorf("error reading response: %v", err)
40+
if shouldThrowError {
41+
return post.UUID, fmt.Errorf("error reading response: %v", err)
42+
}
43+
return "", nil
3344
}
3445

3546
if resp.StatusCode == http.StatusNotFound || string(body) == "player not found" {
47+
if shouldThrowError {
48+
return post.UUID, fmt.Errorf("invalid username or UUID provided")
49+
}
50+
3651
return "Player not Found", nil
3752
}
3853

54+
if len(body) == 0 {
55+
if shouldThrowError {
56+
return post.UUID, fmt.Errorf("received empty response from API")
57+
}
58+
return "", nil
59+
}
60+
3961
var json = jsoniter.ConfigCompatibleWithStandardLibrary
4062
err = json.Unmarshal(body, &post)
4163
if err != nil {
42-
return post.UUID, fmt.Errorf("error parsing JSON: %v", err)
64+
if shouldThrowError {
65+
return post.UUID, fmt.Errorf("error parsing JSON: %v", err)
66+
}
67+
return "", nil
4368
}
4469

4570
redis.Set(fmt.Sprintf("uuid:%s", strings.ToLower(post.Name)), post.UUID, 24*60*60) // Cache for 24 hours
@@ -48,7 +73,12 @@ func GetUUID(username string) (string, error) {
4873
return post.UUID, nil
4974
}
5075

51-
func GetUsername(uuid string) (string, error) {
76+
func GetUsername(uuid string, throwAnError ...bool) (string, error) {
77+
shouldThrowError := true
78+
if len(throwAnError) > 0 {
79+
shouldThrowError = throwAnError[0]
80+
}
81+
5282
var post models.MowojangReponse
5383

5484
cache, err := redis.Get(fmt.Sprintf("username:%s", uuid))
@@ -58,23 +88,39 @@ func GetUsername(uuid string) (string, error) {
5888

5989
resp, err := http.Get(fmt.Sprintf("https://mowojang.matdoes.dev/%s", uuid))
6090
if err != nil {
61-
return post.Name, fmt.Errorf("error making request: %v", err)
91+
if shouldThrowError {
92+
return post.Name, fmt.Errorf("error making request: %v", err)
93+
}
94+
return "", nil
6295
}
6396
defer resp.Body.Close()
6497

6598
body, err := io.ReadAll(resp.Body)
6699
if err != nil {
67-
return post.Name, fmt.Errorf("error reading response: %v", err)
100+
if shouldThrowError {
101+
return post.Name, fmt.Errorf("error reading response: %v", err)
102+
}
103+
return "", nil
68104
}
69105

70106
if resp.StatusCode == http.StatusNotFound || string(body) == "player not found" {
71107
return "Player not Found", nil
72108
}
73109

110+
if len(body) == 0 {
111+
if shouldThrowError {
112+
return post.Name, fmt.Errorf("received empty response from API")
113+
}
114+
return "", nil
115+
}
116+
74117
var json = jsoniter.ConfigCompatibleWithStandardLibrary
75118
err = json.Unmarshal(body, &post)
76119
if err != nil {
77-
return post.Name, fmt.Errorf("error parsing JSON: %v", err)
120+
if shouldThrowError {
121+
return post.Name, fmt.Errorf("error parsing JSON: %v", err)
122+
}
123+
return "", nil
78124
}
79125

80126
redis.Set(fmt.Sprintf("uuid:%s", strings.ToLower(post.Name)), uuid, 24*60*60) // Cache for 24 hours
@@ -83,12 +129,20 @@ func GetUsername(uuid string) (string, error) {
83129
return post.Name, nil
84130
}
85131

86-
func ResolvePlayer(uuid string) (*models.MowojangReponse, error) {
132+
func ResolvePlayer(uuid string, throwAnError ...bool) (*models.MowojangReponse, error) {
133+
shouldThrowError := true
134+
if len(throwAnError) > 0 {
135+
shouldThrowError = throwAnError[0]
136+
}
137+
87138
var post models.MowojangReponse
88139
if !utility.IsUUID(uuid) {
89-
tempUUID, err := GetUUID(uuid)
140+
tempUUID, err := GetUUID(uuid, shouldThrowError)
90141
if err != nil {
91-
return &post, fmt.Errorf("error resolving UUID for username '%s': %v", uuid, err)
142+
if shouldThrowError {
143+
return &post, fmt.Errorf("error resolving UUID for username '%s': %v", uuid, err)
144+
}
145+
return &post, nil
92146
}
93147
uuid = tempUUID
94148
}
@@ -120,6 +174,10 @@ func ResolvePlayer(uuid string) (*models.MowojangReponse, error) {
120174
}, nil
121175
}
122176

177+
if len(body) == 0 {
178+
return &post, fmt.Errorf("received empty response from API")
179+
}
180+
123181
var json = jsoniter.ConfigCompatibleWithStandardLibrary
124182
err = json.Unmarshal(body, &post)
125183
if err != nil {

src/constants/accessories.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ var AccessoryUpgrades = [][]string{
9999
{"BLOOD_DONOR_TALISMAN", "BLOOD_DONOR_RING", "BLOOD_DONOR_ARTIFACT"},
100100
{"LUSH_TALISMAN", "LUSH_RING", "LUSH_ARTIFACT"},
101101
{"ANITA_TALISMAN", "ANITA_RING", "ANITA_ARTIFACT"},
102-
{"PESTHUNTER_BADGE", "PESTHUNTER_RING", "PESTHUNTER_ARTIFACT"},
102+
{"PESTHUNTER_BADGE", "PESTHUNTER_RING", "PESTHUNTER_ARTIFACT", "PESTHUNTER_RELIC"},
103103
{"NIBBLE_CHOCOLATE_STICK", "SMOOTH_CHOCOLATE_BAR", "RICH_CHOCOLATE_CHUNK", "GANACHE_CHOCOLATE_SLAB", "PRESTIGE_CHOCOLATE_REALM"},
104104
{"EMERALD_RING", "EMERALD_ARTIFACT"},
105105
{"COIN_TALISMAN", "RING_OF_COINS", "ARTIFACT_OF_COINS", "RELIC_OF_COINS"},

src/stats/rank.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func GetRank(player *skycrypttypes.Player) *models.RankOutput {
2525
rankName = player.Rank
2626
} else if player.MonthlyPackageRank != "" && player.MonthlyPackageRank != "NONE" {
2727
rankName = player.MonthlyPackageRank
28-
} else if player.NewPackageRank != "" {
28+
} else if player.NewPackageRank != "" && player.NewPackageRank != "NONE" {
2929
rankName = player.NewPackageRank
3030
} else if player.PackageRank != "" {
3131
rankName = player.PackageRank

0 commit comments

Comments
 (0)