-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvos.go
46 lines (41 loc) · 1.65 KB
/
convos.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
package guilded
import (
"github.com/Clinet/clinet_cmds"
"github.com/Clinet/clinet_convos"
"github.com/Clinet/clinet_services"
)
func convoHandler(message *services.Message, session *ClientGuilded) (cmdResps []*cmds.CmdResp, err error) {
if message == nil {
return nil, cmds.ErrCmdEmptyMsg
}
content := message.Content
if content == "" {
return nil, nil
}
cmdResps = make([]*cmds.CmdResp, 0)
conversation := convos.NewConversation()
if oldConversation, err := Guilded.Storage.ServerGet(message.ServerID, "conversations_" + message.UserID); err == nil {
switch oldConversation.(type) {
case convos.Conversation:
conversation = oldConversation.(convos.Conversation)
default:
Log.Trace("Skipping broken conversation record")
}
}
conversationState := conversation.QueryText(content)
if len(conversationState.Errors) > 0 {
for _, csErr := range conversationState.Errors {
Log.Error(csErr)
}
}
if conversationState.Response != nil {
//TODO: Dynamically build either an embed response or a simple conversation response
Guilded.Storage.ServerSet(message.ServerID, "conversations_" + message.UserID, conversation)
cmdResps = append(cmdResps, cmds.NewCmdRespMsg(conversationState.Response.TextSimple))
} else {
//TODO: Make a nice error message for failed queries in a conversation
Guilded.Storage.ServerDel(message.ServerID, "conversations_" + message.UserID)
cmdResps = append(cmdResps, cmds.NewCmdRespMsg("Erm... well this is awkward. I don't have an answer for that."))
}
return cmdResps, nil
}