Fix detection of users on incoming messages

This commit is contained in:
cws 2017-01-05 09:48:57 -05:00
parent 2991331ccb
commit ef0afc2ee0
2 changed files with 23 additions and 14 deletions

View File

@ -6,6 +6,7 @@ package user
// session // session
type User struct { type User struct {
// Current nickname known // Current nickname known
ID string
Name string Name string
Admin bool Admin bool
} }

View File

@ -42,7 +42,7 @@ var idCounter uint64
type slackUserInfoResp struct { type slackUserInfoResp struct {
Ok bool `json:"ok"` Ok bool `json:"ok"`
User struct { User struct {
Id string `json:"id"` ID string `json:"id"`
Name string `json:"name"` Name string `json:"name"`
} `json:"user"` } `json:"user"`
} }
@ -73,6 +73,7 @@ type slackMessage struct {
Channel string `json:"channel"` Channel string `json:"channel"`
Text string `json:"text"` Text string `json:"text"`
User string `json:"user"` User string `json:"user"`
Username string `json:"username"`
Ts string `json:"ts"` Ts string `json:"ts"`
Error struct { Error struct {
Code uint64 `json:"code"` Code uint64 `json:"code"`
@ -130,10 +131,18 @@ func (s *Slack) SendAction(channel, message string) {
} }
func (s *Slack) receiveMessage() (slackMessage, error) { func (s *Slack) receiveMessage() (slackMessage, error) {
var msg []byte
m := slackMessage{} m := slackMessage{}
err := websocket.JSON.Receive(s.ws, &m) //err := websocket.JSON.Receive(s.ws, &m)
err := websocket.Message.Receive(s.ws, &msg)
if err != nil {
log.Println("Error decoding WS message")
return m, err return m, err
} }
log.Printf("Raw response from Slack: %s", msg)
err2 := json.Unmarshal(msg, &m)
return m, err2
}
func (s *Slack) Serve() { func (s *Slack) Serve() {
s.connect() s.connect()
@ -176,8 +185,6 @@ func (s *Slack) buildMessage(m slackMessage) msg.Message {
text = text[3:] text = text[3:]
} }
u := s.getUser(m.User)
// I think it's horseshit that I have to do this // I think it's horseshit that I have to do this
ts := strings.Split(m.Ts, ".") ts := strings.Split(m.Ts, ".")
sec, _ := strconv.ParseInt(ts[0], 10, 64) sec, _ := strconv.ParseInt(ts[0], 10, 64)
@ -186,7 +193,8 @@ func (s *Slack) buildMessage(m slackMessage) msg.Message {
return msg.Message{ return msg.Message{
User: &user.User{ User: &user.User{
Name: u, ID: m.User,
Name: m.Username,
}, },
Body: text, Body: text,
Raw: m.Text, Raw: m.Text,