Skip to content

feat: add timestamp - #12

Open
msstoci wants to merge 1 commit into
gtuk:mainfrom
msstoci:feat/add-timestamp
Open

feat: add timestamp#12
msstoci wants to merge 1 commit into
gtuk:mainfrom
msstoci:feat/add-timestamp

Conversation

@msstoci

@msstoci msstoci commented May 30, 2023

Copy link
Copy Markdown

@gtuk

gtuk commented Jun 8, 2023

Copy link
Copy Markdown
Owner

@msstoci Thanks for you contribution, it's really appreciated. I have question though, based on https://birdie0.github.io/discord-webhooks-guide/discord_webhook.html the timestamp should be ISO8601. I am not sure the timestamp coming from golang is in this format, could you provide me with more info/details here

@attributeerror

Copy link
Copy Markdown
// MarshalJSON implements the json.Marshaler interface.
// The time is a quoted string in the RFC 3339 format with sub-second precision.
// If the timestamp cannot be represented as valid RFC 3339
// (e.g., the year is out of range), then an error is reported.
func (t Time) MarshalJSON() ([]byte, error) {
	b := make([]byte, 0, len(RFC3339Nano)+len(`""`))
	b = append(b, '"')
	b, err := t.appendStrictRFC3339(b)
	b = append(b, '"')
	if err != nil {
		return nil, errors.New("Time.MarshalJSON: " + err.Error())
	}
	return b, nil
}

Pulled from Go v1.20.7 source code, looks like time.Time is serialised into a string that matches the RFC3339 (which is very similar to ISO 8601 - main difference is decimal fractions of the smallest time values & case sensitivity, but this seems to be fine when sending this value to Discord.

cc @gtuk

@TheFiordi

TheFiordi commented Oct 7, 2023

Copy link
Copy Markdown

@msstoci Hi. the timestamp field should be added to the Embed struct and not to Message

type Message struct {
	Username        *string          `json:"username,omitempty"`
	AvatarUrl       *string          `json:"avatar_url,omitempty"`
	Content         *string          `json:"content,omitempty"`
	Embeds          *[]Embed         `json:"embeds,omitempty"`
	AllowedMentions *AllowedMentions `json:"allowed_mentions,omitempty"`
}

type Embed struct {
	Title       *string    `json:"title,omitempty"`
	Url         *string    `json:"url,omitempty"`
	Description *string    `json:"description,omitempty"`
	Color       *string    `json:"color,omitempty"`
	Author      *Author    `json:"author,omitempty"`
	Fields      *[]Field   `json:"fields,omitempty"`
	Thumbnail   *Thumbnail `json:"thumbnail,omitempty"`
	Image       *Image     `json:"image,omitempty"`
	Footer      *Footer    `json:"footer,omitempty"`
	Timestamp   *time.Time `json:"timestamp,omitempty"` <------- Here
}

@attributeerror

Copy link
Copy Markdown

@TheFiordi Appreciate the review, and you're totally right, but the PR was raised by @msstoci :)

@TheFiordi

Copy link
Copy Markdown

@TheFiordi Appreciate the review, and you're totally right, but the PR was raised by @msstoci :)

You're right, I'm so sorry!!

@gtuk

gtuk commented Nov 8, 2023

Copy link
Copy Markdown
Owner

@msstoci do you want to update your PR, with the suggestion from @TheFiordi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants