Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add timestamp #12

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

msstoci
Copy link

@msstoci msstoci commented May 30, 2023

@gtuk
Copy link
Owner

gtuk commented Jun 8, 2023

@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

// 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
Copy link

TheFiordi commented Oct 7, 2023

@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

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

@TheFiordi
Copy link

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

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

@gtuk
Copy link
Owner

gtuk commented Nov 8, 2023

@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