added create date calculator for user and message.
This commit is contained in:
parent
b7cc1c0d5f
commit
ad734e39cd
18
message.go
18
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+"\"}"))
|
||||
|
18
user.go
18
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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user