Skip to content

Commit c84a67c

Browse files
authored
Merge pull request #2303 from mkmccarty/mm-branch-1
✨ fix: include eeid & improve misc settings dump
2 parents 6880f87 + 7c7b696 commit c84a67c

File tree

8 files changed

+35
-18
lines changed

8 files changed

+35
-18
lines changed

main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ func init() {
145145
// Load status messages
146146
ei.LoadStatusMessages(statusMessagesFileName)
147147

148+
// Wire the coop status fix check to avoid import cycle in ei package
149+
ei.CoopStatusFixEnabled = func() bool {
150+
return guildstate.GetGuildSettingString("DEFAULT", "coop_status_fix") == "1"
151+
}
152+
148153
// Read application parameters
149154
flag.Parse()
150155

src/boost/contract_report.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ func ContractReport(
452452

453453
// Get coop status; validate response
454454
// Using GetCoopStatusForCompletedContracts to ensure we cache completed contract data locally
455-
coopStatus, nowTime, _, err := ei.GetCoopStatusForCompletedContracts(contractID, coopID)
455+
coopStatus, nowTime, _, err := ei.GetCoopStatusForCompletedContracts(contractID, coopID, "")
456456
if err != nil {
457457
return fmt.Errorf("%w: %v", ErrCoopStatusFetch, err)
458458
}

src/boost/replay.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ func printArchivedContracts(userID string, archive []*ei.LocalContract, percent
281281
var components []discordgo.MessageComponent
282282
tvalFooterMessage := false
283283
eiUserName := farmerstate.GetMiscSettingString(userID, "ei_ign")
284+
eiID := farmerstate.GetMiscSettingString(userID, "encrypted_ei_id")
284285
divider := true
285286
spacing := discordgo.SeparatorSpacingSizeSmall
286287
builder := strings.Builder{}
@@ -425,7 +426,7 @@ func printArchivedContracts(userID string, archive []*ei.LocalContract, percent
425426

426427
log.Printf("Evaluating contract %s coop %s for user %s\n", contractID, coopID, eiUserName)
427428
if coopID != "[solo]" {
428-
coopStatus, _, _, err := ei.GetCoopStatusForCompletedContracts(contractID, a.GetCoopIdentifier())
429+
coopStatus, _, _, err := ei.GetCoopStatusForCompletedContracts(contractID, a.GetCoopIdentifier(), eiID)
429430
if err == nil {
430431
builder.Reset()
431432
for _, c := range coopStatus.GetContributors() {

src/boost/stones.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ func DownloadCoopStatusStones(contractID string, coopID string, details bool, so
251251
var builderURL strings.Builder
252252
var field []*discordgo.MessageEmbedField
253253

254-
coopStatus, _, dataTimestampStr, err := ei.GetCoopStatus(contractID, coopID)
254+
coopStatus, _, dataTimestampStr, err := ei.GetCoopStatus(contractID, coopID, "")
255255
if err != nil {
256256
return err.Error(), "", field
257257
}

src/boost/teamwork.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ func DownloadCoopStatusTeamwork(contractID string, coopID string, setContractEst
275275
return fmt.Sprintf("Filenames:\n%s", strings.Join(fileNames, "\n")), nil, ContractScore{}
276276
}
277277

278-
coopStatus, nowTime, dataTimestampStr, err := ei.GetCoopStatus(contractID, coopID)
278+
coopStatus, nowTime, dataTimestampStr, err := ei.GetCoopStatus(contractID, coopID, "")
279279
if err != nil {
280280
return err.Error(), nil, ContractScore{}
281281
}

src/ei/coop_status.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,25 @@ type eiData struct {
3030
var (
3131
// Contracts is a map of contracts and is saved to disk
3232
eiDatas map[string]*eiData
33+
34+
// CoopStatusFixEnabled is a callback set from outside the ei package (to avoid import
35+
// cycles) that returns true when the alternate coop_status endpoint and eeid override
36+
// should be used. It is wired up in main.
37+
CoopStatusFixEnabled func() bool
3338
)
3439

3540
func init() {
3641
eiDatas = make(map[string]*eiData)
3742
}
3843

3944
// GetCoopStatus retrieves the coop status for a given contract and coop
40-
func GetCoopStatus(contractID string, coopID string) (*ContractCoopStatusResponse, time.Time, string, error) {
45+
func GetCoopStatus(contractID string, coopID string, eeidOverride string) (*ContractCoopStatusResponse, time.Time, string, error) {
4146
eggIncID := config.EIUserIDBasic
4247
reqURL := "https://www.auxbrain.com/ei/coop_status_bot"
48+
if eeidOverride != "" && CoopStatusFixEnabled != nil && CoopStatusFixEnabled() {
49+
eggIncID = DecryptEID(eeidOverride)
50+
reqURL = "https://www.auxbrain.com/ei/coop_status"
51+
}
4352
enc := base64.StdEncoding
4453
timestamp := time.Now()
4554

@@ -205,9 +214,13 @@ func ClearCoopStatusCachedData() {
205214

206215
// GetCoopStatusForCompletedContracts retrieves the coop status for a given contract and coop, but is intended for completed contracts
207216
// This saves the data in compressed form without a timestamp in the filename
208-
func GetCoopStatusForCompletedContracts(contractID string, coopID string) (*ContractCoopStatusResponse, time.Time, string, error) {
217+
func GetCoopStatusForCompletedContracts(contractID string, coopID string, eeidOverride string) (*ContractCoopStatusResponse, time.Time, string, error) {
209218
eggIncID := config.EIUserIDBasic
210219
reqURL := "https://www.auxbrain.com/ei/coop_status_bot"
220+
if eeidOverride != "" && CoopStatusFixEnabled != nil && CoopStatusFixEnabled() {
221+
eggIncID = DecryptEID(eeidOverride)
222+
reqURL = "https://www.auxbrain.com/ei/coop_status"
223+
}
211224
enc := base64.StdEncoding
212225
timestamp := time.Now()
213226

src/guildstate/slashcmd.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -312,21 +312,19 @@ func GetGuildSettingsForGuild(s *discordgo.Session, i *discordgo.InteractionCrea
312312
for _, key := range keys {
313313
value := guild.MiscSettingsString[key]
314314
items := splitCSV(value)
315+
fmt.Fprintf(&builder, "- %s = %s\n", key, value)
315316
if len(items) > 1 {
316-
fmt.Fprintf(&builder, "- %s (%d items)\n", key, len(items))
317+
fmt.Fprintf(&builder, " - parsed items (%d):\n", len(items))
317318
for _, item := range items {
318-
details := getSnowflakeDetails(s, guildID, item)
319-
if len(details) == 1 {
320-
fmt.Fprintf(&builder, " - %s\n", details[0])
321-
} else {
322-
fmt.Fprintf(&builder, " - %s\n", item)
319+
fmt.Fprintf(&builder, " - %s\n", item)
320+
for _, detail := range getSnowflakeDetails(s, guildID, item) {
321+
fmt.Fprintf(&builder, " - resolved: %s\n", detail)
323322
}
324323
}
325-
} else {
326-
fmt.Fprintf(&builder, "- %s = %s\n", key, value)
327-
for _, detail := range getSnowflakeDetails(s, guildID, value) {
328-
fmt.Fprintf(&builder, " - resolved: %s\n", detail)
329-
}
324+
continue
325+
}
326+
for _, detail := range getSnowflakeDetails(s, guildID, value) {
327+
fmt.Fprintf(&builder, " - resolved: %s\n", detail)
330328
}
331329
}
332330
}

src/track/track_update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func DownloadCoopStatusTracker(contractID string, coopID string) (time.Time, flo
6868
return time.Time{}, 0, fmt.Errorf("invalid contract ID")
6969
}
7070

71-
coopStatus, _, _, err := ei.GetCoopStatus(contractID, coopID)
71+
coopStatus, _, _, err := ei.GetCoopStatus(contractID, coopID, "")
7272
if err != nil {
7373
return time.Time{}, 0, err
7474
}

0 commit comments

Comments
 (0)