Skip to content

Commit

Permalink
feat: Add message URL helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotwms committed Oct 3, 2024
1 parent 247dbd7 commit a1839d1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ var (
return EndpointMessageReactions(cID, mID, eID) + "/" + uID
}

// EndpointMessageURL builds a canonical discord URL in the format https://discord.com/channels/:gID/:cID/:mID
EndpointMessageURL = func(gID, cID, mID string) string {
return EndpointDiscord + "channels/" + gID + "/" + cID + "/" + mID
}

EndpointPoll = func(cID, mID string) string {
return EndpointChannel(cID) + "/polls/" + mID
}
Expand Down
5 changes: 5 additions & 0 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,3 +595,8 @@ type MessageInteractionMetadata struct {
// NOTE: present only on modal submit interactions.
TriggeringInteractionMetadata *MessageInteractionMetadata `json:"triggering_interaction_metadata,omitempty"`
}

// URL returns the canonical Discord message URL
func (m *Message) URL() string {
return EndpointMessageURL(m.GuildID, m.ChannelID, m.ID)
}
12 changes: 12 additions & 0 deletions message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,15 @@ func TestGettingEmojisFromMessage(t *testing.T) {
}

}

func TestMessage_URL(t *testing.T) {
m := &Message{
GuildID: "foo",
ChannelID: "bar",
ID: "baz",
}

if m.URL() != "https://discord.com/channels/foo/bar/baz" {
t.Error("Unexpected url: " + m.URL())
}
}

0 comments on commit a1839d1

Please sign in to comment.