Updated ChannelMessageSend to reflect new mention method used by Discord, closes #9

This commit is contained in:
Bruce Marriner 2015-12-23 23:50:19 -06:00
parent dfb0b891fd
commit 850901a5dc

View file

@ -16,7 +16,6 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"regexp"
"time" "time"
) )
@ -501,24 +500,11 @@ func (s *Session) ChannelMessageAck(channelID, messageID string) (err error) {
// NOTE, mention and tts parameters may be added in 2.x branch. // NOTE, mention and tts parameters may be added in 2.x branch.
func (s *Session) ChannelMessageSend(channelID string, content string) (st Message, err error) { func (s *Session) ChannelMessageSend(channelID string, content string) (st Message, err error) {
// TOD: nonce string ? // TODO: nonce string ?
data := struct { data := struct {
Content string `json:"content"` Content string `json:"content"`
Mentions []string `json:"mentions"` TTS bool `json:"tts"`
TTS bool `json:"tts"` }{content, false}
}{content, nil, false}
// If true, search for <@ID> tags and add those IDs to mention list.
if s.AutoMention {
re := regexp.MustCompile(`<@(\d+)>`)
match := re.FindAllStringSubmatch(content, -1)
mentions := make([]string, len(match))
for i, m := range match {
mentions[i] = m[1]
}
data.Mentions = mentions
}
// Send the message to the given channel // Send the message to the given channel
response, err := s.Request("POST", CHANNEL_MESSAGES(channelID), data) response, err := s.Request("POST", CHANNEL_MESSAGES(channelID), data)