ChannelMessageSendComplex (#349)
* ChannelMessageSendComplex * ChannelMessageEditComplex * I am a murderer. * Travis didn't like that. * I can't spell
This commit is contained in:
parent
52ad9e2feb
commit
fea42d937a
2 changed files with 45 additions and 68 deletions
14
message.go
14
message.go
|
@ -31,6 +31,20 @@ type Message struct {
|
|||
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.
|
||||
type MessageAttachment struct {
|
||||
ID string `json:"id"`
|
||||
|
|
99
restapi.go
99
restapi.go
|
@ -1281,19 +1281,21 @@ func (s *Session) ChannelMessageAck(channelID, messageID, lastToken string) (st
|
|||
return
|
||||
}
|
||||
|
||||
// channelMessageSend sends a message to the given channel.
|
||||
// ChannelMessageSend sends a message to the given channel.
|
||||
// channelID : The ID of a Channel.
|
||||
// content : The message to send.
|
||||
// tts : Whether to send the message with TTS.
|
||||
func (s *Session) channelMessageSend(channelID, content string, tts bool) (st *Message, err error) {
|
||||
func (s *Session) ChannelMessageSend(channelID string, content string) (*Message, error) {
|
||||
return s.ChannelMessageSendComplex(channelID, &MessageSend{Content: content})
|
||||
}
|
||||
|
||||
// TODO: nonce string ?
|
||||
data := struct {
|
||||
Content string `json:"content"`
|
||||
TTS bool `json:"tts"`
|
||||
}{content, tts}
|
||||
// ChannelMessageSendComplex sends a message to the given channel.
|
||||
// channelID : The ID of a Channel.
|
||||
// data : The message struct to send.
|
||||
func (s *Session) ChannelMessageSendComplex(channelID string, data *MessageSend) (st *Message, err error) {
|
||||
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))
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -1303,63 +1305,38 @@ func (s *Session) channelMessageSend(channelID, content string, tts bool) (st *M
|
|||
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.
|
||||
// channelID : The ID of a Channel.
|
||||
// content : The message to send.
|
||||
func (s *Session) ChannelMessageSendTTS(channelID string, content string) (st *Message, err error) {
|
||||
|
||||
return s.channelMessageSend(channelID, content, true)
|
||||
func (s *Session) ChannelMessageSendTTS(channelID string, content string) (*Message, error) {
|
||||
return s.ChannelMessageSendComplex(channelID, &MessageSend{Content: content, Tts: true})
|
||||
}
|
||||
|
||||
// ChannelMessageSendEmbed sends a message to the given channel with embedded data.
|
||||
// channelID : The ID of a Channel.
|
||||
// embed : The embed data to send.
|
||||
func (s *Session) ChannelMessageSendEmbed(channelID string, embed *MessageEmbed) (st *Message, err error) {
|
||||
|
||||
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
|
||||
func (s *Session) ChannelMessageSendEmbed(channelID string, embed *MessageEmbed) (*Message, error) {
|
||||
return s.ChannelMessageSendComplex(channelID, &MessageSend{Embed: embed})
|
||||
}
|
||||
|
||||
// ChannelMessageEdit edits an existing message, replacing it entirely with
|
||||
// the given content.
|
||||
// channeld : The ID of a Channel
|
||||
// messageID : the ID of a Message
|
||||
func (s *Session) ChannelMessageEdit(channelID, messageID, content string) (st *Message, err error) {
|
||||
// messageID : The ID of a Message
|
||||
// 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 {
|
||||
Content string `json:"content"`
|
||||
}{content}
|
||||
// ChannelMessageEditComplex edits an existing message, replacing it entirely with
|
||||
// the given MessageEdit struct
|
||||
// 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, ""))
|
||||
if err != nil {
|
||||
|
@ -1374,22 +1351,8 @@ func (s *Session) ChannelMessageEdit(channelID, messageID, content string) (st *
|
|||
// channelID : The ID of a Channel
|
||||
// messageID : The ID of a Message
|
||||
// embed : The embed data to send
|
||||
func (s *Session) ChannelMessageEditEmbed(channelID, messageID string, embed *MessageEmbed) (st *Message, err error) {
|
||||
if embed != nil && embed.Type == "" {
|
||||
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
|
||||
func (s *Session) ChannelMessageEditEmbed(channelID, messageID string, embed *MessageEmbed) (*Message, error) {
|
||||
return s.ChannelMessageEditComplex(channelID, messageID, &MessageEdit{Embed: embed})
|
||||
}
|
||||
|
||||
// ChannelMessageDelete deletes a message from the Channel.
|
||||
|
|
Loading…
Reference in a new issue