Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/boost/boost.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions src/boost/boost_speedrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
10 changes: 5 additions & 5 deletions src/boost/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand All @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
12 changes: 9 additions & 3 deletions src/boost/message_redraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
//}
}
14 changes: 14 additions & 0 deletions src/dc/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
24 changes: 24 additions & 0 deletions src/dc/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Loading