Skip to content

Commit

Permalink
SendContent (bwmarrin#352)
Browse files Browse the repository at this point in the history
* SendContent

* Fixed error...?

* Commented

* Yep let's do that

* Oops

* Oki

* Whatever you say, Travis... :<

* Omit them empty structs
  • Loading branch information
LEGOlord208 authored and iopred committed Apr 10, 2017
1 parent f0c6abb commit 0c94256
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
22 changes: 16 additions & 6 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,28 @@ type Message struct {
Reactions []*MessageReactions `json:"reactions"`
}

// MessageParams is used in MessageSend and MessageEdit to share common parameters.
type MessageParams struct {
Content *string `json:"content,omitempty"`
Embed *MessageEmbed `json:"embed,omitempty"`
}

// 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"`
MessageParams
Tts bool `json:"tts"`
}

// MessageEdit stores all parameters you can send with ChannelMessageSendComplex.
type MessageEdit struct {
Content string `json:"content"`
Embed *MessageEmbed `json:"embed"`
MessageParams
}

// SetContent is the same as setting the variable Content,
// except it doesn't take a pointer.
// Only a conveniance function.
func (m *MessageParams) SetContent(str string) {
m.Content = &str
}

// A MessageAttachment stores data for message attachments.
Expand Down
10 changes: 5 additions & 5 deletions restapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -1285,7 +1285,7 @@ func (s *Session) ChannelMessageAck(channelID, messageID, lastToken string) (st
// channelID : The ID of a Channel.
// content : The message to send.
func (s *Session) ChannelMessageSend(channelID string, content string) (*Message, error) {
return s.ChannelMessageSendComplex(channelID, &MessageSend{Content: content})
return s.ChannelMessageSendComplex(channelID, &MessageSend{MessageParams: MessageParams{Content: &content}})
}

// ChannelMessageSendComplex sends a message to the given channel.
Expand All @@ -1309,14 +1309,14 @@ func (s *Session) ChannelMessageSendComplex(channelID string, data *MessageSend)
// channelID : The ID of a Channel.
// content : The message to send.
func (s *Session) ChannelMessageSendTTS(channelID string, content string) (*Message, error) {
return s.ChannelMessageSendComplex(channelID, &MessageSend{Content: content, Tts: true})
return s.ChannelMessageSendComplex(channelID, &MessageSend{MessageParams: MessageParams{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) (*Message, error) {
return s.ChannelMessageSendComplex(channelID, &MessageSend{Embed: embed})
return s.ChannelMessageSendComplex(channelID, &MessageSend{MessageParams: MessageParams{Embed: embed}})
}

// ChannelMessageEdit edits an existing message, replacing it entirely with
Expand All @@ -1325,7 +1325,7 @@ func (s *Session) ChannelMessageSendEmbed(channelID string, embed *MessageEmbed)
// 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})
return s.ChannelMessageEditComplex(channelID, messageID, &MessageEdit{MessageParams: MessageParams{Content: &content}})
}

// ChannelMessageEditComplex edits an existing message, replacing it entirely with
Expand All @@ -1352,7 +1352,7 @@ func (s *Session) ChannelMessageEditComplex(channelID, messageID string, data *M
// messageID : The ID of a Message
// embed : The embed data to send
func (s *Session) ChannelMessageEditEmbed(channelID, messageID string, embed *MessageEmbed) (*Message, error) {
return s.ChannelMessageEditComplex(channelID, messageID, &MessageEdit{Embed: embed})
return s.ChannelMessageEditComplex(channelID, messageID, &MessageEdit{MessageParams: MessageParams{Embed: embed}})
}

// ChannelMessageDelete deletes a message from the Channel.
Expand Down

0 comments on commit 0c94256

Please sign in to comment.