diff --git a/src/boost/boost.go b/src/boost/boost.go index 036841d1..62d45a37 100644 --- a/src/boost/boost.go +++ b/src/boost/boost.go @@ -1646,6 +1646,9 @@ func RemoveFarmerByMention(client dc.Client, guildID string, channelID string, o msg, err := client.EditMessage(loc.ChannelID, loc.ListMsgID, dc.Message{Components: components}) if err == nil { loc.ListMsgID = msg.ID + } else { + log.Printf("RemoveFarmerFromContract: failed to edit boost list message %s in channel %s for contract %s: %v", + loc.ListMsgID, loc.ChannelID, contract.ContractHash, err) } // Need to disable the speedrun start button if the contract is no longer full if previousBoosters != len(contract.Boosters) && previousBoosters == contract.CoopSize { diff --git a/src/boost/boost_speedrun.go b/src/boost/boost_speedrun.go index af75aac9..96fd0b20 100644 --- a/src/boost/boost_speedrun.go +++ b/src/boost/boost_speedrun.go @@ -223,6 +223,9 @@ func setSpeedrunOptions(client dc.Client, channelID string, sinkBoosting string, msg, err := client.EditMessage(loc.ChannelID, loc.ListMsgID, dc.Message{Components: components}) if err == nil { loc.ListMsgID = msg.ID + } else { + log.Printf("startSpeedrun: failed to edit boost list message %s in channel %s for contract %s: %v", + loc.ListMsgID, loc.ChannelID, contract.ContractHash, err) } updateSignupReactionMessage(client, contract, loc) } diff --git a/src/boost/contract.go b/src/boost/contract.go index 319efb56..086b2f40 100644 --- a/src/boost/contract.go +++ b/src/boost/contract.go @@ -343,7 +343,7 @@ func HandleContractCommand(client dc.Client, e *dc.CommandEvent) { ChannelID = thread.ID _ = client.JoinThread(thread.ID) } else { - log.Print(err) + log.Printf("contract: failed to start thread in channel %s: %v", ChannelID, err) } } @@ -356,7 +356,7 @@ func HandleContractCommand(client dc.Client, e *dc.CommandEvent) { Content: err.Error(), Ephemeral: true, }); ferr != nil { - log.Print(ferr) + log.Printf("contract: failed to send create error followup to channel %s: %v", e.ChannelID(), ferr) } return } @@ -1014,7 +1014,7 @@ func HandleContractSettingsReactions(client dc.Client, e *dc.ComponentEvent) { if err == nil { loc.ListMsgID = msg.ID } else { - log.Print(err) + log.Printf("contract: failed to edit boost list message %s in channel %s for contract %s: %v", loc.ListMsgID, loc.ChannelID, contract.ContractHash, err) } if redrawSignup { @@ -1047,7 +1047,7 @@ func HandleContractSettingsCommand(client dc.Client, e *dc.CommandEvent) { components = append(components, comp...) err = e.Followup(dc.Message{Components: components}) if err != nil { - log.Println("Error sending contract settings:", err) + log.Printf("contract: error sending contract settings followup in channel %s: %v", e.ChannelID(), err) } return @@ -1207,7 +1207,7 @@ func HandleThresholdModalSubmit(client dc.Client, e *dc.ModalEvent) { if err == nil { loc.ListMsgID = msg.ID } else { - log.Print(err) + log.Printf("contract: failed to edit boost list message %s in channel %s for contract %s: %v", loc.ListMsgID, loc.ChannelID, contract.ContractHash, err) } updateSignupReactionMessage(client, contract, loc) diff --git a/src/boost/message_redraw.go b/src/boost/message_redraw.go index 52f82051..e035305d 100644 --- a/src/boost/message_redraw.go +++ b/src/boost/message_redraw.go @@ -184,6 +184,9 @@ func refreshBoostListMessage(client dc.Client, contract *Contract, updateSignupM if err == nil { // This is an edit, it should be the same loc.ListMsgID = msg.ID + } else { + log.Printf("refreshBoostListMessage: failed to edit boost list message %s in channel %s for contract %s: %v", + loc.ListMsgID, loc.ChannelID, contract.ContractHash, err) } if updateSignupMessage { updateSignupReactionMessage(client, contract, loc) @@ -209,7 +212,8 @@ func sendNextNotification(client dc.Client, contract *Contract, pingUsers bool) } _, err := client.EditMessage(loc.ChannelID, loc.ListMsgID, dc.Message{Components: components}) if err != nil { - log.Println("Unable to send this message." + err.Error()) + log.Printf("sendNextNotification: unable to edit boost list message %s in channel %s for contract %s: %v", + loc.ListMsgID, loc.ChannelID, contract.ContractHash, err) } updateSignupReactionMessage(client, contract, loc) @@ -244,7 +248,8 @@ func sendNextNotification(client dc.Client, contract *Contract, pingUsers bool) drawn = true } if err != nil { - log.Println("Unable to resend message." + err.Error()) + log.Printf("sendNextNotification: unable to send message in channel %s for contract %s: %v", + loc.ChannelID, contract.ContractHash, err) } var str = "" if msg == nil { @@ -345,7 +350,8 @@ func updateSignupReactionMessage(client dc.Client, contract *Contract, loc *Loca components = append(components, comp...) _, err := client.EditMessage(loc.ChannelID, msgID, dc.Message{Components: components}) if err != nil { - log.Printf("unable to send this message: %v", err) + log.Printf("updateSignupReactionMessage: unable to edit message %s in channel %s for contract %s: %v", + msgID, loc.ChannelID, contract.ContractHash, err) } //} } diff --git a/src/dc/errors.go b/src/dc/errors.go index 0b4298b3..2e513e09 100644 --- a/src/dc/errors.go +++ b/src/dc/errors.go @@ -106,3 +106,17 @@ func IsThreadArchived(err error) bool { apiErr, ok := AsAPIError(err) return ok && apiErr.Code == ErrCodeThreadArchived } + +// IsMissingAccess reports whether err is Discord refusing a call because the +// bot cannot view/access the target channel or guild (Discord code 50001). +func IsMissingAccess(err error) bool { + apiErr, ok := AsAPIError(err) + return ok && apiErr.Code == ErrCodeMissingAccess +} + +// IsMissingPermissions reports whether err is Discord refusing a call because +// the bot lacks specific permissions to perform the action (Discord code 50013). +func IsMissingPermissions(err error) bool { + apiErr, ok := AsAPIError(err) + return ok && apiErr.Code == ErrCodeMissingPermissions +} diff --git a/src/dc/errors_test.go b/src/dc/errors_test.go index 605ee03e..4b70dcb2 100644 --- a/src/dc/errors_test.go +++ b/src/dc/errors_test.go @@ -96,3 +96,27 @@ func TestIsThreadArchived(t *testing.T) { t.Fatal("a plain error is not thread archived") } } + +func TestIsMissingAccess(t *testing.T) { + if !IsMissingAccess(restError(403, ErrCodeMissingAccess, "Missing Access")) { + t.Fatal("expected missing access") + } + if IsMissingAccess(restError(403, ErrCodeMissingPermissions, "Missing Permissions")) { + t.Fatal("missing permissions is not missing access") + } + if IsMissingAccess(errors.New("nope")) { + t.Fatal("a plain error is not missing access") + } +} + +func TestIsMissingPermissions(t *testing.T) { + if !IsMissingPermissions(restError(403, ErrCodeMissingPermissions, "Missing Permissions")) { + t.Fatal("expected missing permissions") + } + if IsMissingPermissions(restError(403, ErrCodeMissingAccess, "Missing Access")) { + t.Fatal("missing access is not missing permissions") + } + if IsMissingPermissions(errors.New("nope")) { + t.Fatal("a plain error is not missing permissions") + } +}