Преглед изворни кода

feat(config): move Timestamps & TimestampsFormat to its own table

ayn2op пре 1 година
родитељ
комит
284853dc4a
2 измењених фајлова са 12 додато и 7 уклоњено
  1. 2 2
      cmd/messages_text.go
  2. 10 5
      internal/config/config.go

+ 2 - 2
cmd/messages_text.go

@@ -128,8 +128,8 @@ func (mt *MessagesText) createMessage(m discord.Message) {
 }
 
 func (mt *MessagesText) createHeader(w io.Writer, m discord.Message, isReply bool) {
-	if mt.cfg.Timestamps {
-		time := m.Timestamp.Time().In(time.Local).Format(mt.cfg.TimestampsFormat)
+	if mt.cfg.Timestamps.Enabled {
+		time := m.Timestamp.Time().In(time.Local).Format(mt.cfg.Timestamps.Format)
 		fmt.Fprintf(w, "[::d]%s[::-] ", time)
 	}
 

+ 10 - 5
internal/config/config.go

@@ -14,6 +14,11 @@ import (
 const fileName = "config.toml"
 
 type (
+	Timestamps struct {
+		Enabled bool   `toml:"enabled"`
+		Format  string `toml:"format"`
+	}
+
 	Identify struct {
 		Status         discord.Status `toml:"status"`
 		Browser        string         `toml:"browser"`
@@ -40,9 +45,7 @@ type (
 		ShowAttachmentLinks bool  `toml:"show_attachment_links"`
 		MessagesLimit       uint8 `toml:"messages_limit"`
 
-		Timestamps       bool   `toml:"timestamps"`
-		TimestampsFormat string `toml:"timestamps_format"`
-
+		Timestamps    Timestamps    `toml:"timestamps"`
 		Identify      Identify      `toml:"identify"`
 		Notifications Notifications `toml:"notifications"`
 
@@ -60,8 +63,10 @@ func defaultConfig() *Config {
 		ShowAttachmentLinks: true,
 		MessagesLimit:       50,
 
-		Timestamps:       false,
-		TimestampsFormat: time.Kitchen,
+		Timestamps: Timestamps{
+			Enabled: false,
+			Format:  time.Kitchen,
+		},
 
 		Identify: Identify{
 			Status:         discord.OnlineStatus,