Add Params to ChatAPI instance so we can fill it with data

This commit is contained in:
Sam
2019-07-25 11:23:09 -04:00
parent a5a50f79cd
commit 1b089d2833
2 changed files with 21 additions and 7 deletions

View File

@ -103,7 +103,9 @@ func heartbeat(c chan<- ChatAPI, freq time.Duration) {
// be fetched at a time. However, if count is passed, then that is the number of
// messages that will be fetched.
func (c Chat) Read(count ...int) (*ChatAPI, error) {
m := ChatAPI{}
m := ChatAPI{
Params: &params{},
}
m.Method = "read"
m.Params.Options.Channel = c.Channel
if len(count) == 0 {
@ -125,7 +127,9 @@ func (c Chat) Read(count ...int) (*ChatAPI, error) {
// fetched with Read. However, if count is passed, then that is the number of
// messages that will be fetched.
func (c *ChatAPI) Next(count ...int) (*ChatAPI, error) {
m := ChatAPI{}
m := ChatAPI{
Params: &params{},
}
m.Method = "read"
m.Params.Options.Channel = c.Result.Messages[0].Msg.Channel
if len(count) == 0 {
@ -150,7 +154,9 @@ func (c *ChatAPI) Next(count ...int) (*ChatAPI, error) {
// originally fetched with Read. However, if count is passed, then that is the
// number of messages that will be fetched.
func (c *ChatAPI) Previous(count ...int) (*ChatAPI, error) {
m := ChatAPI{}
m := ChatAPI{
Params: &params{},
}
m.Method = "read"
m.Params.Options.Channel = c.Result.Messages[0].Msg.Channel
if len(count) == 0 {

View File

@ -26,7 +26,9 @@ func chatAPIOut(keybasePath string, c ChatAPI) (ChatAPI, error) {
// Send sends a chat message
func (c Chat) Send(message ...string) (ChatAPI, error) {
m := ChatAPI{}
m := ChatAPI{
Params: &params{},
}
m.Method = "send"
m.Params.Options.Channel = c.Channel
m.Params.Options.Message.Body = strings.Join(message, " ")
@ -40,7 +42,9 @@ func (c Chat) Send(message ...string) (ChatAPI, error) {
// Edit edits a previously sent chat message
func (c Chat) Edit(messageId int, message ...string) (ChatAPI, error) {
m := ChatAPI{}
m := ChatAPI{
Params: &params{},
}
m.Method = "edit"
m.Params.Options.Channel = c.Channel
m.Params.Options.Message.Body = strings.Join(message, " ")
@ -55,7 +59,9 @@ func (c Chat) Edit(messageId int, message ...string) (ChatAPI, error) {
// React sends a reaction to a message.
func (c Chat) React(messageId int, reaction string) (ChatAPI, error) {
m := ChatAPI{}
m := ChatAPI{
Params: &params{},
}
m.Method = "reaction"
m.Params.Options.Channel = c.Channel
m.Params.Options.Message.Body = reaction
@ -70,7 +76,9 @@ func (c Chat) React(messageId int, reaction string) (ChatAPI, error) {
// Delete deletes a chat message
func (c Chat) Delete(messageId int) (ChatAPI, error) {
m := ChatAPI{}
m := ChatAPI{
Params: &params{},
}
m.Method = "delete"
m.Params.Options.Channel = c.Channel
m.Params.Options.MessageID = messageId