-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquote.go
36 lines (32 loc) · 817 Bytes
/
quote.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
import (
"fmt"
"strings"
"time"
)
type quote struct {
Id int
Date time.Time
Rating int
Text []string
}
func (q quote) ircFormat() (result []string) {
id := fmt.Sprintf("\x0304#%d\x03", q.Id)
// https://pkg.go.dev/time#pkg-constants
date := fmt.Sprintf("\x0310%s\x03", q.Date.Format("2006-01-02 15:04"))
rating := fmt.Sprintf("\x0304%d\x03", q.Rating)
header := fmt.Sprintf("%s :: %s :: Rating: %s", id, date, rating)
result = append(result, header)
result = append(result, colorize(q.Text, "\x0303")...)
return
}
func colorize(in []string, color string) (out []string) {
for _, line := range in {
line = strings.TrimSpace(line)
if len(line) == 0 || line == "Комикс по мотивам цитаты" {
continue
}
out = append(out, color+line)
}
return out
}