forked from pothtonswer/discordmuffin
Updated ChannelMessageSend to reflect new mention method used by Discord, closes #9
This commit is contained in:
parent
dfb0b891fd
commit
850901a5dc
1 changed files with 4 additions and 18 deletions
22
restapi.go
22
restapi.go
|
@ -16,7 +16,6 @@ import (
|
|||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"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.
|
||||
func (s *Session) ChannelMessageSend(channelID string, content string) (st Message, err error) {
|
||||
|
||||
// TOD: nonce string ?
|
||||
// TODO: nonce string ?
|
||||
data := struct {
|
||||
Content string `json:"content"`
|
||||
Mentions []string `json:"mentions"`
|
||||
TTS bool `json:"tts"`
|
||||
}{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
|
||||
}
|
||||
Content string `json:"content"`
|
||||
TTS bool `json:"tts"`
|
||||
}{content, false}
|
||||
|
||||
// Send the message to the given channel
|
||||
response, err := s.Request("POST", CHANNEL_MESSAGES(channelID), data)
|
||||
|
|
Loading…
Reference in a new issue