-
Notifications
You must be signed in to change notification settings - Fork 2
/
command.go
49 lines (44 loc) · 1.19 KB
/
command.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
package outputs
import (
"fmt"
"sort"
"strings"
"github.com/fatih/color"
"github.com/hexbotio/hex/models"
"github.com/hexbotio/hex/parse"
)
type Command struct {
}
func (x Command) Write(message models.Message, config models.Config) {
for _, output := range message.Outputs {
if message.Debug && parse.EitherMember(config.Admins, message.Attributes["hex.user"], message.Attributes["hex.channel"]) {
output.Response = output.Response + "\n\n[ Debug: " + output.Command + " ]"
}
if message.Attributes["hex.rule.format"] == "true" {
if output.Success {
color.Set(color.FgGreen)
} else {
color.Set(color.FgRed)
}
fmt.Println(output.Response, "\n")
color.Unset()
} else {
fmt.Println(output.Response, "\n")
}
}
if message.Debug {
keys := make([]string, 0, len(message.Attributes))
for key, _ := range message.Attributes {
keys = append(keys, key)
}
sort.Strings(keys)
fmt.Printf("MESSAGE DEBUG (%d sec to complete)\n", message.EndTime-message.StartTime)
for _, key := range keys {
if strings.HasPrefix(key, "hex.var.") {
fmt.Printf(" %s: '%s'\n", key, "********")
} else {
fmt.Printf(" %s: '%s'\n", key, message.Attributes[key])
}
}
}
}