Compare commits
45 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 111d41b901 | |||
| 300e330b8d | |||
| d69b73c5c1 | |||
| b51c00a910 | |||
| 0fd676670f | |||
| 74992fe2c3 | |||
| 74fb4a152b | |||
| 07f5168a6a | |||
| 0631dc60a7 | |||
| 71d1800637 | |||
| c852393504 | |||
| ef7a20a94b | |||
| 21b141b7a1 | |||
| 8cef252023 | |||
| dd6726911e | |||
| 0316bc6db1 | |||
| a22970a284 | |||
| ad3edadc79 | |||
| 5a7a6d7538 | |||
| 4e55ebaf05 | |||
| 6c11327289 | |||
| f6d26e1905 | |||
| 0feb664405 | |||
| ca2a1fdf25 | |||
| c031c36a00 | |||
| 5f211c7a90 | |||
| 3bcca84908 | |||
| 93daa56db1 | |||
| c272c05092 | |||
| 67ffd89a00 | |||
| 97adac7fa4 | |||
| e24450a0af | |||
| 5bcd11703a | |||
| c4f06fa79b | |||
| b50d3bcfa2 | |||
| b55e4b8315 | |||
| 450f2c1558 | |||
| 219ef492f5 | |||
| 26e487659c | |||
| 3faadfd076 | |||
| d791203856 | |||
| 285567309a | |||
| 4e2656445c | |||
| 0cfaa93505 | |||
| 6d85c97e05 |
@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"time"
|
||||
|
||||
"samhofi.us/x/keybase/v2/types/chat1"
|
||||
@ -36,15 +37,7 @@ func getNewMessages(k *Keybase, subs *subscriptionChannels, execOptions []string
|
||||
execString = append(execString, execOptions...)
|
||||
}
|
||||
for {
|
||||
cmd := make([]string, 0)
|
||||
|
||||
if k.HomePath != "" {
|
||||
cmd = append(cmd, "--home", k.HomePath)
|
||||
}
|
||||
|
||||
cmd = append(cmd, execString...)
|
||||
|
||||
execCmd := execCommand(k.ExePath, cmd...)
|
||||
execCmd := exec.Command(k.Path, execString...)
|
||||
stdOut, _ := execCmd.StdoutPipe()
|
||||
execCmd.Start()
|
||||
scanner := bufio.NewScanner(stdOut)
|
||||
@ -751,37 +744,3 @@ func (k *Keybase) ListMembersOfConversation(convID chat1.ConvIDStr) (chat1.ChatM
|
||||
}
|
||||
return k.ListMembers(opts)
|
||||
}
|
||||
|
||||
// ListConvsOnName returns a list of all conversations for a chat1.ChatChannel
|
||||
func (k *Keybase) ListConvsOnName(channel chat1.ChatChannel) (*[]chat1.ConvSummary, error) {
|
||||
type result struct {
|
||||
Conversations []chat1.ConvSummary `json:"conversations"`
|
||||
}
|
||||
|
||||
type res struct {
|
||||
Result result `json:"result"`
|
||||
Error *Error `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
var r res
|
||||
|
||||
arg := newListConvsOnNameArg(channel)
|
||||
|
||||
jsonBytes, _ := json.Marshal(arg)
|
||||
|
||||
cmdOut, err := k.Exec("chat", "api", "-m", string(jsonBytes))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(cmdOut, &r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if r.Error != nil {
|
||||
return nil, fmt.Errorf("%v", r.Error.Message)
|
||||
}
|
||||
|
||||
return &r.Result.Conversations, nil
|
||||
}
|
||||
2
go.mod
2
go.mod
@ -1,3 +1,3 @@
|
||||
module samhofi.us/x/keybase
|
||||
module samhofi.us/x/keybase/v2
|
||||
|
||||
go 1.13
|
||||
|
||||
@ -9,9 +9,6 @@ import (
|
||||
"samhofi.us/x/keybase/v2/types/chat1"
|
||||
)
|
||||
|
||||
// Used for testing
|
||||
var execCommand = exec.Command
|
||||
|
||||
// Possible MemberTypes
|
||||
const (
|
||||
TEAM string = "team"
|
||||
@ -24,33 +21,13 @@ const (
|
||||
CHAT string = "chat"
|
||||
)
|
||||
|
||||
// New returns a new Keybase
|
||||
func New(opts ...KeybaseOpt) *Keybase {
|
||||
k := &Keybase{ExePath: "keybase"}
|
||||
|
||||
for _, opt := range opts {
|
||||
opt.apply(k)
|
||||
}
|
||||
|
||||
s := k.status()
|
||||
k.Version = k.version()
|
||||
k.LoggedIn = s.LoggedIn
|
||||
if k.LoggedIn {
|
||||
k.Username = s.Username
|
||||
k.Device = s.Device.Name
|
||||
}
|
||||
|
||||
return k
|
||||
}
|
||||
|
||||
// NewKeybase returns a new Keybase. Optionally, you can pass a string containing the path to the Keybase executable as the first argument.
|
||||
// This is deprecated and will be removed in a future update. Use New() instead.
|
||||
func NewKeybase(path ...string) *Keybase {
|
||||
k := &Keybase{}
|
||||
if len(path) < 1 {
|
||||
k.ExePath = "keybase"
|
||||
k.Path = "keybase"
|
||||
} else {
|
||||
k.ExePath = path[0]
|
||||
k.Path = path[0]
|
||||
}
|
||||
|
||||
s := k.status()
|
||||
@ -65,15 +42,7 @@ func NewKeybase(path ...string) *Keybase {
|
||||
|
||||
// Exec executes the given Keybase command
|
||||
func (k *Keybase) Exec(command ...string) ([]byte, error) {
|
||||
cmd := make([]string, 0)
|
||||
|
||||
if k.HomePath != "" {
|
||||
cmd = append(cmd, "--home", k.HomePath)
|
||||
}
|
||||
|
||||
cmd = append(cmd, command...)
|
||||
|
||||
out, err := execCommand(k.ExePath, cmd...).Output()
|
||||
out, err := exec.Command(k.Path, command...).Output()
|
||||
if err != nil {
|
||||
return []byte{}, err
|
||||
}
|
||||
@ -20,37 +20,6 @@ type RunOptions struct {
|
||||
FilterChannels []chat1.ChatChannel // Only subscribe to messages from specified channels
|
||||
}
|
||||
|
||||
// KeybaseOpt configures a Keybase
|
||||
type KeybaseOpt interface {
|
||||
apply(kb *Keybase)
|
||||
}
|
||||
|
||||
// SetExePath sets the path to the Keybase executable
|
||||
func SetExePath(path string) KeybaseOpt {
|
||||
return setExePath{path}
|
||||
}
|
||||
|
||||
type setExePath struct {
|
||||
path string
|
||||
}
|
||||
|
||||
func (o setExePath) apply(kb *Keybase) {
|
||||
kb.ExePath = o.path
|
||||
}
|
||||
|
||||
// SetHomePath sets the path to the Keybase home directory
|
||||
func SetHomePath(path string) KeybaseOpt {
|
||||
return setHomePath{path}
|
||||
}
|
||||
|
||||
type setHomePath struct {
|
||||
path string
|
||||
}
|
||||
|
||||
func (o setHomePath) apply(kb *Keybase) {
|
||||
kb.HomePath = o.path
|
||||
}
|
||||
|
||||
type subscriptionType struct {
|
||||
Type string `json:"type"`
|
||||
}
|
||||
@ -114,7 +83,6 @@ type SendMessageOptions struct {
|
||||
ReplyTo *chat1.MessageID `json:"reply_to,omitempty"`
|
||||
ExplodingLifetime *ExplodingLifetime `json:"exploding_lifetime,omitempty"`
|
||||
UnreadOnly bool `json:"unread_only,omitempty"`
|
||||
NonBlock bool `json:"nonblock,omitempty"`
|
||||
}
|
||||
|
||||
type sendMessageParams struct {
|
||||
@ -239,24 +207,6 @@ func newListMembersArg(options ListMembersOptions) listMembersArg {
|
||||
}
|
||||
}
|
||||
|
||||
type listConvsOnNameParams struct {
|
||||
Options chat1.ChatChannel
|
||||
}
|
||||
|
||||
type listConvsOnNameArg struct {
|
||||
Method string
|
||||
Params listConvsOnNameParams
|
||||
}
|
||||
|
||||
func newListConvsOnNameArg(channel chat1.ChatChannel) listConvsOnNameArg {
|
||||
return listConvsOnNameArg{
|
||||
Method: "listconvsonname",
|
||||
Params: listConvsOnNameParams{
|
||||
Options: channel,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// KVOptions holds a set of options to be passed to the KV methods
|
||||
type KVOptions struct {
|
||||
Team *string `json:"team"`
|
||||
@ -1004,8 +954,7 @@ type userBlocks struct {
|
||||
|
||||
// Keybase holds basic information about the local Keybase executable
|
||||
type Keybase struct {
|
||||
HomePath string
|
||||
ExePath string
|
||||
Path string
|
||||
Username string
|
||||
LoggedIn bool
|
||||
Version string
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user