-
Notifications
You must be signed in to change notification settings - Fork 15
/
debug.go
78 lines (71 loc) · 2.03 KB
/
debug.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
73
74
75
76
77
78
package rivescript
// Debugging methods
import (
"fmt"
)
// say prints a debugging message
func (rs *RiveScript) say(message string, a ...interface{}) {
if rs.Debug {
fmt.Printf(message+"\n", a...)
}
}
// warn prints a warning message for non-fatal errors
func (rs *RiveScript) warn(message string, a ...interface{}) {
if !rs.Quiet {
fmt.Printf("[WARN] "+message+"\n", a...)
}
}
// warnSyntax is like warn but takes a filename and line number.
func (rs *RiveScript) warnSyntax(message string, filename string, lineno int, a ...interface{}) {
message += fmt.Sprintf(" at %s line %d", filename, lineno)
rs.warn(message, a...)
}
/*
DumpTopics is a debug method which pretty-prints the topic tree structure from
the bot's memory.
*/
func (rs *RiveScript) DumpTopics() {
for topic, data := range rs.topics {
fmt.Printf("Topic: %s\n", topic)
for _, trigger := range data.triggers {
fmt.Printf(" + %s\n", trigger.trigger)
if trigger.previous != "" {
fmt.Printf(" %% %s\n", trigger.previous)
}
for _, cond := range trigger.condition {
fmt.Printf(" * %s\n", cond)
}
for _, reply := range trigger.reply {
fmt.Printf(" - %s\n", reply)
}
if trigger.redirect != "" {
fmt.Printf(" @ %s\n", trigger.redirect)
}
}
}
}
/*
DumpSorted is a debug method which pretty-prints the sort tree of topics from
the bot's memory.
*/
func (rs *RiveScript) DumpSorted() {
rs._dumpSorted(rs.sorted.topics, "Topics")
rs._dumpSorted(rs.sorted.thats, "Thats")
rs._dumpSortedList(rs.sorted.sub, "Substitutions")
rs._dumpSortedList(rs.sorted.person, "Person Substitutions")
}
func (rs *RiveScript) _dumpSorted(tree map[string][]sortedTriggerEntry, label string) {
fmt.Printf("Sort Buffer: %s\n", label)
for topic, data := range tree {
fmt.Printf(" Topic: %s\n", topic)
for _, trigger := range data {
fmt.Printf(" + %s\n", trigger.trigger)
}
}
}
func (rs *RiveScript) _dumpSortedList(list []string, label string) {
fmt.Printf("Sort buffer: %s\n", label)
for _, item := range list {
fmt.Printf(" %s\n", item)
}
}