From 867f87f2bc7ca6994ecda3d5d457b9296d3861c0 Mon Sep 17 00:00:00 2001 From: ayntgl <90600421+ayntgl@users.noreply.github.com> Date: Mon, 17 Jan 2022 13:23:14 +0400 Subject: [PATCH] feat: implement message timestamps (#113) --- config/mod.go | 2 ++ ui/builder.go | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/config/mod.go b/config/mod.go index 9ac3cab..f0f3ff9 100644 --- a/config/mod.go +++ b/config/mod.go @@ -10,6 +10,7 @@ type GeneralConfig struct { FetchMessagesLimit int `json:"fetchMessagesLimit"` Mouse bool `json:"mouse"` Notifications bool `json:"notifications"` + Timestamps bool `json:"timestamps"` } type KeybindingsConfig struct { @@ -37,6 +38,7 @@ func New() *Config { FetchMessagesLimit: 50, Mouse: true, Notifications: true, + Timestamps: false, }, Keybindings: KeybindingsConfig{ FocusGuildsList: []string{"Alt+Rune[g]"}, diff --git a/ui/builder.go b/ui/builder.go index d223267..0ea9986 100644 --- a/ui/builder.go +++ b/ui/builder.go @@ -3,6 +3,7 @@ package ui import ( "fmt" "strings" + "time" "github.com/ayntgl/discordgo" "github.com/ayntgl/discordo/util" @@ -21,18 +22,35 @@ func buildMessage(app *App, m *discordgo.Message) []byte { b.WriteString("\"]") // Build the message associated with crosspost, channel follow add, pin, or a reply. buildReferencedMessage(&b, m.ReferencedMessage, app.Session.State.User.ID) + + if app.Config.General.Timestamps { + t, err := m.Timestamp.Parse() + if err != nil { + return nil + } + + b.WriteString("[::d]") + b.WriteString(t.Format(time.Stamp)) + b.WriteString("[::-]") + b.WriteByte(' ') + } + // Build the author of this message. buildAuthor(&b, m.Author, app.Session.State.User.ID) + // Build the contents of the message. buildContent(&b, m, app.Session.State.User.ID) if m.EditedTimestamp != "" { b.WriteString(" [::d](edited)[::-]") } + // Build the embeds associated with the message. buildEmbeds(&b, m.Embeds) + // Build the message attachments (attached files to the message). buildAttachments(&b, m.Attachments) + // Tags with no region ID ([""]) do not start new regions. They can // therefore be used to mark the end of a region. b.WriteString("[\"\"]")