Browse Source

Clean up and clarify functions a bit

main
Sam 6 years ago
parent
commit
8e3274d6f3
  1. 6
      api/api.go
  2. 21
      api/chatOut.go
  3. 4
      main.go

6
api/api.go

@ -11,9 +11,9 @@ type Keybase struct {
} }
type keybase interface { type keybase interface {
ChatSend(user, message string) (chatOutResult, error) ChatSendText(user string, message ...string) (chatOutResultResult, error)
ChatSendTeam(team, channel, message string) (chatOutResult, error) ChatSendTextTeam(team, channel, message string) (chatOutResultResult, error)
ChatList() (chatOutResult, error) ChatList() ([]chatOutResultConversations, error)
LoggedIn() bool LoggedIn() bool
Username() string Username() string
Version() string Version() string

21
api/chatOut.go

@ -3,6 +3,7 @@ package api
import ( import (
"encoding/json" "encoding/json"
"os/exec" "os/exec"
"strings"
) )
// ---- Struct for sending to API // ---- Struct for sending to API
@ -80,25 +81,33 @@ func chatAPIOut(keybasePath string, c chatOut) (chatOutResult, error) {
} }
// ChatSend() sends a chat message to a user. // ChatSend() sends a chat message to a user.
func (k Keybase) ChatSend(user, message string) (chatOutResult, error) { func (k Keybase) ChatSendText(user string, message ...string) (chatOutResultResult, error) {
m := chatOut{} m := chatOut{}
m.Method = "send" m.Method = "send"
m.Params.Options.Channel.Name = user m.Params.Options.Channel.Name = user
m.Params.Options.Message.Body = message m.Params.Options.Message.Body = strings.Join(message, " ")
return chatAPIOut(k.path, m) r, err := chatAPIOut(k.path, m)
if err != nil {
return chatOutResultResult{}, err
}
return r.Result, nil
} }
// ChatSendTeam() sends a chat message to a team. // ChatSendTeam() sends a chat message to a team.
func (k Keybase) ChatSendTeam(team, channel, message string) (chatOutResult, error) { func (k Keybase) ChatSendTextTeam(team, channel string, message ...string) (chatOutResultResult, error) {
m := chatOut{} m := chatOut{}
m.Method = "send" m.Method = "send"
m.Params.Options.Channel.Name = team m.Params.Options.Channel.Name = team
m.Params.Options.Channel.MembersType = "team" m.Params.Options.Channel.MembersType = "team"
m.Params.Options.Channel.TopicName = channel m.Params.Options.Channel.TopicName = channel
m.Params.Options.Message.Body = message m.Params.Options.Message.Body = strings.Join(message, " ")
return chatAPIOut(k.path, m) r, err := chatAPIOut(k.path, m)
if err != nil {
return chatOutResultResult{}, err
}
return r.Result, nil
} }
// ChatList() returns a list of all conversations. // ChatList() returns a list of all conversations.

4
main.go

@ -26,8 +26,8 @@ func main() {
allChats += fmt.Sprintf("%s\n", chat.Channel.Name) allChats += fmt.Sprintf("%s\n", chat.Channel.Name)
} }
} }
c, _ := k.ChatSend(username, fmt.Sprintf("Version: %s\nConversations:\n```%s```\n", version, allChats)) c, _ := k.ChatSendText(username, fmt.Sprintf("Version: %s\nConversations:\n```%s```\n", version, allChats))
fmt.Println(c.Result.Message) fmt.Println(c.Message, "-", c.ID)
} else { } else {
fmt.Println("Not logged in") fmt.Println("Not logged in")
} }

Loading…
Cancel
Save