-
Notifications
You must be signed in to change notification settings - Fork 1
/
messages.go
72 lines (61 loc) · 1.64 KB
/
messages.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package client
import (
"crypto/rand"
"io"
"math/big"
"github.com/subsilent/kappa/common"
)
type Message interface {
Write(w io.Writer, colors common.ColorCodes)
}
type SimpleMessage struct {
Text string
}
func (s SimpleMessage) Write(w io.Writer, colors common.ColorCodes) {
w.Write([]byte(" " + s.Text + "\r\n"))
}
// Quote is a message with an author
type Quote struct {
Color []byte
Author string
Text string
}
func (q Quote) Write(w io.Writer, colors common.ColorCodes) {
w.Write(q.Color)
w.Write([]byte(" " + q.Author))
w.Write(colors.Reset)
w.Write([]byte(": " + q.Text))
w.Write([]byte("\r\n"))
}
// Conversation displays a list of quotes
type Conversation struct {
Quotes []Quote
}
// Write actually writes the message to the terminal
func (c Conversation) Write(w io.Writer, colors common.ColorCodes) {
for _, q := range c.Quotes {
q.Write(w, colors)
}
w.Write([]byte("\r\n"))
}
// LoginMessage writes a message at login
func GetMessage(w io.Writer, colors common.ColorCodes) {
var messages = []Message{
SimpleMessage{"Welcome to Kappa DB, Yo!"},
Quote{colors.LightMagenta, "Jessy Pinkman", "Yeah, Bitch! Magnets!"},
Quote{colors.LightMagenta, "Jessy Pinkman", "Yeah, Science!"},
Quote{colors.LightBlue, "Saul Goodman", "Better call Saul."},
Conversation{
Quotes: []Quote{
Quote{colors.LightGreen, "Walter White", "One particular element comes to mind..."},
Quote{colors.LightMagenta, "Jessy Pinkman", "Ohhhhh... wire.."},
},
},
}
// Choose message
index, err := rand.Int(rand.Reader, big.NewInt(int64(len(messages))))
if err != nil {
index = big.NewInt(0)
}
messages[index.Int64()].Write(w, colors)
}