Skip to content

Commit b5418c6

Browse files
authored
Merge pull request #18 from SkyCryptWebsite/dev
feat: add source ot accessories and other qol
2 parents 98e9fbe + 5d5865f commit b5418c6

4 files changed

Lines changed: 32 additions & 34 deletions

File tree

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ HYPIXEL_API_KEY=""
22
DISCORD_WEBHOOK=""
33
DEV="true"
44
ENABLE_ARMOR_HEX="false"
5+
MONGO_URI="mongodb://localhost:27017"
6+
MONGO_DB_NAME="SkyCrypt"

src/db/mongo.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,6 @@ func CloseMongo() error {
166166
}
167167

168168
func populateEmojis() {
169-
timeNow := time.Now()
170-
171169
collection := GetMongoCollection("emojis")
172170
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
173171
defer cancel()
@@ -190,10 +188,6 @@ func populateEmojis() {
190188
}
191189
EMOJIS[result.UUID] = result.Emoji
192190
}
193-
194-
if os.Getenv("FIBER_PREFORK_CHILD") == "" {
195-
fmt.Printf("[MONGO] Emojis populated in %v\n", time.Since(timeNow))
196-
}
197191
}
198192

199193
func init() {

src/routes/accessories.go

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"time"
1111

1212
skycrypttypes "github.com/DuckySoLucky/SkyCrypt-Types"
13-
skyhelpernetworthgo "github.com/SkyCryptWebsite/SkyHelper-Networth-Go"
1413
"github.com/gofiber/fiber/v2"
1514
)
1615

@@ -43,33 +42,11 @@ func AccessoriesHandler(c *fiber.Ctx) error {
4342
userProfile.Inventory = &skycrypttypes.Inventory{}
4443
}
4544

46-
specifiedInventories := skyhelpernetworthgo.SpecifiedInventory{
47-
"talisman_bag": userProfile.Inventory.BagContents.TalismanBag,
48-
}
49-
50-
decodedItems, err := skyhelpernetworthgo.CalculateFromSpecifiedInventories(specifiedInventories, skyhelpernetworthgo.NetworthOptions{
51-
IncludeItemData: true,
52-
KeepInvalidItems: true,
53-
}.ToInternal())
54-
if err != nil {
55-
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
56-
"error": fmt.Sprintf("Failed to calculate items: %v", err),
57-
})
58-
}
59-
60-
accessories := []*skycrypttypes.Item{}
61-
if decodedItems.Types["talisman_bag"] != nil {
62-
for _, item := range decodedItems.Types["talisman_bag"].Items {
63-
if item.ItemData != nil {
64-
item.ItemData.Price = item.Price
65-
}
66-
67-
accessories = append(accessories, item.ItemData)
68-
}
69-
}
70-
7145
items := map[string][]*skycrypttypes.Item{
72-
"talisman_bag": accessories,
46+
"talisman_bag": stats.GetInventory(&userProfile, "talisman_bag"),
47+
"inventory": stats.GetInventory(&userProfile, "inventory"),
48+
"enderchest": stats.GetInventory(&userProfile, "enderchest"),
49+
"backpack": stats.GetInventory(&userProfile, "backpack"),
7350
}
7451

7552
disabledPacks := []string{""}

src/stats/accessories.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package stats
22

33
import (
4+
"fmt"
45
notenoughupdates "skycrypt/src/NotEnoughUpdates"
56
"skycrypt/src/constants"
67
"skycrypt/src/models"
@@ -65,7 +66,7 @@ func GetAccessories(useProfile *skycrypttypes.Member, items map[string][]*skycry
6566
continue
6667
}
6768

68-
item.Lore = append(item.Lore, "", "§7Inactive: §cNot in accessory bag")
69+
item.Lore = append(item.Lore, "", fmt.Sprintf("§7Inactive: §cFound in %s", utility.TitleCase(inventoryId)))
6970
newAccessory := models.InsertAccessory{
7071
ProcessedItem: item,
7172
Id: id,
@@ -103,8 +104,17 @@ func GetAccessories(useProfile *skycrypttypes.Member, items map[string][]*skycry
103104

104105
if utility.RarityNameToInt(duplicateRarity) < utility.RarityNameToInt(rarity) {
105106
duplicates[i].IsInactive = true
107+
108+
if !strings.Contains(strings.Join(duplicates[i].ProcessedItem.Lore, "\n"), "§7Inactive:") {
109+
duplicates[i].ProcessedItem.Lore = append(duplicates[i].ProcessedItem.Lore, "", fmt.Sprintf("§7Inactive: §cLower rarity duplicate of %s", accessory.DisplayName))
110+
}
106111
} else if duplicate.Rarity == rarity {
107112
duplicates[i].IsInactive = true
113+
114+
if !strings.Contains(strings.Join(duplicates[i].ProcessedItem.Lore, "\n"), "§7Inactive:") {
115+
duplicates[i].ProcessedItem.Lore = append(duplicates[i].ProcessedItem.Lore, "", fmt.Sprintf("§7Inactive: §cDuplicate of %s", accessory.DisplayName))
116+
}
117+
108118
}
109119
}
110120

@@ -132,6 +142,17 @@ func GetAccessories(useProfile *skycrypttypes.Member, items map[string][]*skycry
132142
for i, acc := range accessories {
133143
if acc.Id == id && acc.Rarity == rarity {
134144
accessories[i].IsInactive = false
145+
146+
// Remove the inactive lore line
147+
for j := len(accessories[i].ProcessedItem.Lore) - 1; j >= 0; j-- {
148+
if strings.HasPrefix(accessories[i].ProcessedItem.Lore[j], "§7Inactive:") {
149+
accessories[i].ProcessedItem.Lore = append(accessories[i].ProcessedItem.Lore[:j], accessories[i].ProcessedItem.Lore[j+1:]...)
150+
if j > 0 {
151+
accessories[i].ProcessedItem.Lore = append(accessories[i].ProcessedItem.Lore[:j-1], accessories[i].ProcessedItem.Lore[j-1+1:]...)
152+
}
153+
break
154+
}
155+
}
135156
break
136157
}
137158
}
@@ -148,6 +169,9 @@ func GetAccessories(useProfile *skycrypttypes.Member, items map[string][]*skycry
148169
for j, acc := range accessories {
149170
if acc.Id == upgrade {
150171
accessories[j].IsInactive = true
172+
if !strings.Contains(strings.Join(accessories[j].ProcessedItem.Lore, "\n"), "§7Inactive:") {
173+
accessories[j].ProcessedItem.Lore = append(accessories[j].ProcessedItem.Lore, "", fmt.Sprintf("§7Inactive: §cUpgraded to %s", accessory.DisplayName))
174+
}
151175
}
152176
}
153177
}
@@ -182,6 +206,7 @@ func GetAccessories(useProfile *skycrypttypes.Member, items map[string][]*skycry
182206
}
183207

184208
sort.Sort(itemSorter(accessories))
209+
185210
output := models.AccessoriesOutput{
186211
Accessories: accessories,
187212
AccessoryIds: accessoryIds,

0 commit comments

Comments
 (0)