diff --git a/message.go b/message.go index d3c06fe..7510d8c 100644 --- a/message.go +++ b/message.go @@ -1,6 +1,10 @@ package revoltgo -import "time" +import ( + "time" + + "github.com/oklog/ulid/v2" +) // Message struct type Message struct { @@ -76,6 +80,18 @@ type MessageEmbeddedVideo struct { Height int `json:"height"` } +// Calculate creation date and edit the struct. +func (c *Message) CalculateCreationDate() error { + ulid, err := ulid.Parse(c.Id) + + if err != nil { + return err + } + + c.CreatedAt = time.UnixMilli(int64(ulid.Time())) + return nil +} + // Edit message content. func (m *Message) Edit(content string) error { _, err := m.Client.Request("PATCH", "/channels/"+m.ChannelId+"/messages/"+m.Id, []byte("{\"content\": \""+content+"\"}")) diff --git a/user.go b/user.go index cc927e1..3f19560 100644 --- a/user.go +++ b/user.go @@ -1,6 +1,10 @@ package revoltgo -import "time" +import ( + "time" + + "github.com/oklog/ulid/v2" +) // User struct. type User struct { @@ -35,3 +39,15 @@ type UserStatus struct { type BotInformation struct { Owner string `json:"owner"` } + +// Calculate creation date and edit the struct. +func (c *User) CalculateCreationDate() error { + ulid, err := ulid.Parse(c.Id) + + if err != nil { + return err + } + + c.CreatedAt = time.UnixMilli(int64(ulid.Time())) + return nil +}