added create date calculator for user and message.

This commit is contained in:
5elenay 2021-08-22 17:46:54 +03:00
parent b7cc1c0d5f
commit ad734e39cd
2 changed files with 34 additions and 2 deletions

View File

@ -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
View File

@ -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
}