ChannelMessageSendComplex (#349)

* ChannelMessageSendComplex

* ChannelMessageEditComplex

* I am a murderer.

* Travis didn't like that.

* I can't spell
This commit is contained in:
LEGOlord208 2017-04-08 05:15:31 +02:00 committed by Chris Rhodes
parent 52ad9e2feb
commit fea42d937a
2 changed files with 45 additions and 68 deletions

View file

@ -31,6 +31,20 @@ type Message struct {
Reactions []*MessageReactions `json:"reactions"` Reactions []*MessageReactions `json:"reactions"`
} }
// MessageSend stores all parameters you can send with ChannelMessageSendComplex.
type MessageSend struct {
Content string `json:"content"`
Tts bool `json:"tts"`
Embed *MessageEmbed `json:"embed"`
Nonce string `json:"nonce"`
}
// MessageEdit stores all parameters you can send with ChannelMessageSendComplex.
type MessageEdit struct {
Content string `json:"content"`
Embed *MessageEmbed `json:"embed"`
}
// A MessageAttachment stores data for message attachments. // A MessageAttachment stores data for message attachments.
type MessageAttachment struct { type MessageAttachment struct {
ID string `json:"id"` ID string `json:"id"`

View file

@ -1281,19 +1281,21 @@ func (s *Session) ChannelMessageAck(channelID, messageID, lastToken string) (st
return return
} }
// channelMessageSend sends a message to the given channel. // ChannelMessageSend sends a message to the given channel.
// channelID : The ID of a Channel. // channelID : The ID of a Channel.
// content : The message to send. // content : The message to send.
// tts : Whether to send the message with TTS. func (s *Session) ChannelMessageSend(channelID string, content string) (*Message, error) {
func (s *Session) channelMessageSend(channelID, content string, tts bool) (st *Message, err error) { return s.ChannelMessageSendComplex(channelID, &MessageSend{Content: content})
}
// TODO: nonce string ? // ChannelMessageSendComplex sends a message to the given channel.
data := struct { // channelID : The ID of a Channel.
Content string `json:"content"` // data : The message struct to send.
TTS bool `json:"tts"` func (s *Session) ChannelMessageSendComplex(channelID string, data *MessageSend) (st *Message, err error) {
}{content, tts} if data.Embed != nil && data.Embed.Type == "" {
data.Embed.Type = "rich"
}
// Send the message to the given channel
response, err := s.RequestWithBucketID("POST", EndpointChannelMessages(channelID), data, EndpointChannelMessages(channelID)) response, err := s.RequestWithBucketID("POST", EndpointChannelMessages(channelID), data, EndpointChannelMessages(channelID))
if err != nil { if err != nil {
return return
@ -1303,63 +1305,38 @@ func (s *Session) channelMessageSend(channelID, content string, tts bool) (st *M
return return
} }
// ChannelMessageSend sends a message to the given channel.
// channelID : The ID of a Channel.
// content : The message to send.
func (s *Session) ChannelMessageSend(channelID string, content string) (st *Message, err error) {
return s.channelMessageSend(channelID, content, false)
}
// ChannelMessageSendTTS sends a message to the given channel with Text to Speech. // ChannelMessageSendTTS sends a message to the given channel with Text to Speech.
// channelID : The ID of a Channel. // channelID : The ID of a Channel.
// content : The message to send. // content : The message to send.
func (s *Session) ChannelMessageSendTTS(channelID string, content string) (st *Message, err error) { func (s *Session) ChannelMessageSendTTS(channelID string, content string) (*Message, error) {
return s.ChannelMessageSendComplex(channelID, &MessageSend{Content: content, Tts: true})
return s.channelMessageSend(channelID, content, true)
} }
// ChannelMessageSendEmbed sends a message to the given channel with embedded data. // ChannelMessageSendEmbed sends a message to the given channel with embedded data.
// channelID : The ID of a Channel. // channelID : The ID of a Channel.
// embed : The embed data to send. // embed : The embed data to send.
func (s *Session) ChannelMessageSendEmbed(channelID string, embed *MessageEmbed) (st *Message, err error) { func (s *Session) ChannelMessageSendEmbed(channelID string, embed *MessageEmbed) (*Message, error) {
return s.ChannelMessageSendComplex(channelID, &MessageSend{Embed: embed})
return s.ChannelMessageSendEmbedWithMessage(channelID, "", embed)
}
// ChannelMessageSendEmbedWithMessage sends a message to the given channel with embedded data and a message.
// channelID : The ID of a Channel.
// content : The message to send.
// embed : The embed data to send.
func (s *Session) ChannelMessageSendEmbedWithMessage(channelID string, content string, embed *MessageEmbed) (st *Message, err error) {
if embed != nil && embed.Type == "" {
embed.Type = "rich"
}
data := struct {
Embed *MessageEmbed `json:"embed"`
Content string `json:"content"`
}{embed, content}
// Send the message to the given channel
response, err := s.RequestWithBucketID("POST", EndpointChannelMessages(channelID), data, EndpointChannelMessages(channelID))
if err != nil {
return
}
err = unmarshal(response, &st)
return
} }
// ChannelMessageEdit edits an existing message, replacing it entirely with // ChannelMessageEdit edits an existing message, replacing it entirely with
// the given content. // the given content.
// channeld : The ID of a Channel // channeld : The ID of a Channel
// messageID : the ID of a Message // messageID : The ID of a Message
func (s *Session) ChannelMessageEdit(channelID, messageID, content string) (st *Message, err error) { // content : The contents of the message
func (s *Session) ChannelMessageEdit(channelID, messageID, content string) (*Message, error) {
return s.ChannelMessageEditComplex(channelID, messageID, &MessageEdit{Content: content})
}
data := struct { // ChannelMessageEditComplex edits an existing message, replacing it entirely with
Content string `json:"content"` // the given MessageEdit struct
}{content} // channeld : The ID of a Channel
// messageID : The ID of a Message
// data : The MessageEdit struct to send
func (s *Session) ChannelMessageEditComplex(channelID, messageID string, data *MessageEdit) (st *Message, err error) {
if data.Embed != nil && data.Embed.Type == "" {
data.Embed.Type = "rich"
}
response, err := s.RequestWithBucketID("PATCH", EndpointChannelMessage(channelID, messageID), data, EndpointChannelMessage(channelID, "")) response, err := s.RequestWithBucketID("PATCH", EndpointChannelMessage(channelID, messageID), data, EndpointChannelMessage(channelID, ""))
if err != nil { if err != nil {
@ -1374,22 +1351,8 @@ func (s *Session) ChannelMessageEdit(channelID, messageID, content string) (st *
// channelID : The ID of a Channel // channelID : The ID of a Channel
// messageID : The ID of a Message // messageID : The ID of a Message
// embed : The embed data to send // embed : The embed data to send
func (s *Session) ChannelMessageEditEmbed(channelID, messageID string, embed *MessageEmbed) (st *Message, err error) { func (s *Session) ChannelMessageEditEmbed(channelID, messageID string, embed *MessageEmbed) (*Message, error) {
if embed != nil && embed.Type == "" { return s.ChannelMessageEditComplex(channelID, messageID, &MessageEdit{Embed: embed})
embed.Type = "rich"
}
data := struct {
Embed *MessageEmbed `json:"embed"`
}{embed}
response, err := s.RequestWithBucketID("PATCH", EndpointChannelMessage(channelID, messageID), data, EndpointChannelMessage(channelID, ""))
if err != nil {
return
}
err = unmarshal(response, &st)
return
} }
// ChannelMessageDelete deletes a message from the Channel. // ChannelMessageDelete deletes a message from the Channel.