-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.go
77 lines (65 loc) · 2.16 KB
/
list.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
package list
import (
"fmt"
"math/rand"
"sort"
"strings"
rc "github.com/grokify/go-ringcentral-client/office/v1/client"
"github.com/grokify/mogo/html/htmlutil"
"github.com/grokify/mogo/net/http/httputilmore"
log "github.com/sirupsen/logrus"
"github.com/grokify/groupbot"
)
func NewIntent() groupbot.Intent {
return groupbot.Intent{
Type: groupbot.MatchStringLowerCase,
Strings: []string{"list"},
HandleIntent: handleIntent,
}
}
func handleIntent(bot *groupbot.Groupbot, glipPostEventInfo *groupbot.GlipPostEventInfo) (*httputilmore.ResponseInfo, error) {
glipPost := buildPost(bot)
return bot.SendGlipPost(glipPostEventInfo, glipPost)
}
func buildPost(bot *groupbot.Groupbot) rc.GlipCreatePost {
displayKeysLc := []string{}
keysMap := map[string]string{}
for i, item := range bot.SheetsMap.ItemMap {
log.Warn(fmt.Sprintf("LIST_ITEM_I [%v][%v][%v]", i, item.Key, item.Display))
displayKeyLc := strings.TrimSpace(fmt.Sprintf("%v %v", strings.ToLower(item.ItemDisplayOrKey()), rand.Int63()))
displayKeysLc = append(displayKeysLc, displayKeyLc)
vals := []string{}
for _, col := range bot.SheetsMap.DataColumnsKeys() {
if itemVal, ok := item.Data[col]; ok {
itemVal = strings.TrimSpace(itemVal)
if len(itemVal) > 0 {
vals = append(vals, itemVal)
} else {
vals = append(vals, "?")
}
} else {
vals = append(vals, "?")
}
}
itemString := item.ItemDisplayOrKey() + " - " + strings.Join(vals, ", ")
keysMap[displayKeyLc] = itemString
}
log.Info(fmt.Sprintf("DISP_KEYS_1: %v", strings.Join(displayKeysLc, ", ")))
sort.Strings(displayKeysLc)
log.Info(fmt.Sprintf("DISP_KEYS_2: %v", strings.Join(displayKeysLc, ", ")))
outputs := []string{}
for _, displayKeyLc := range displayKeysLc {
if output, ok := keysMap[displayKeyLc]; ok {
outputs = append(outputs, output)
}
}
outputsString := "* " + strings.Join(outputs, "\n* ")
return rc.GlipCreatePost{
Text: fmt.Sprintf(
"Here's the current data. Use %s to see overall stats.",
bot.AppConfig.Quote("stats")),
Attachments: []rc.GlipMessageAttachmentInfoRequest{{
Type: "Card",
Color: htmlutil.RingCentralOrangeHex,
Text: outputsString}}}
}