diff --git a/adapter/adapter.go b/adapter/adapter.go index 62108ec..dc048d4 100644 --- a/adapter/adapter.go +++ b/adapter/adapter.go @@ -9,6 +9,6 @@ type Adapter interface { Name() string Subscribe(string) []error Fetch(string, []string) error - Do(string) error + Do(string, []string) error DefaultSubscriptionFilter() string } diff --git a/adapter/mastodon.go b/adapter/mastodon.go index a5f0cef..99cf317 100644 --- a/adapter/mastodon.go +++ b/adapter/mastodon.go @@ -104,7 +104,7 @@ func (self *MastoAdapter) Fetch(etype string, ids []string) error { return nil } -func (self *MastoAdapter) Do(action string) error { +func (self *MastoAdapter) Do(action string, data []string) error { return nil } diff --git a/adapter/misskey.go b/adapter/misskey.go index 24f886d..2728b25 100644 --- a/adapter/misskey.go +++ b/adapter/misskey.go @@ -294,6 +294,8 @@ func (self *MisskeyAdapter) toAuthor(usr mkm.User, bustCache bool) *Author { func (self *MisskeyAdapter) Fetch(etype string, ids []string) error { for _, id := range ids { switch etype { + case "byAuthor": + // fetch notes by this author case "message": data, err := self.mk.Notes().Show(id) if err != nil { @@ -360,13 +362,13 @@ func (self *MisskeyAdapter) Fetch(etype string, ids []string) error { self.send(a) } } - } } return nil } -func (self *MisskeyAdapter) Do(action string) error { +func (self *MisskeyAdapter) Do(action string, data []string) error { + return nil } diff --git a/adapter/nostr.go b/adapter/nostr.go index ef836dc..7f07712 100644 --- a/adapter/nostr.go +++ b/adapter/nostr.go @@ -90,7 +90,7 @@ func (self *NostrAdapter) Fetch(etype string, ids []string) error { return nil } -func (self *NostrAdapter) Do(action string) error { +func (self *NostrAdapter) Do(action string, data []string) error { return nil } diff --git a/cli/cli.go b/cli/cli.go index d406c9e..e864f28 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -2,6 +2,7 @@ package cli import ( "encoding/json" + "errors" "io/ioutil" "log" @@ -12,7 +13,11 @@ import ( func Process(args ...string) error { // allocate storage for the settings array var settings []models.Settings - var s models.Settings + var s *models.Settings + + if len(args) < 3 { + return errors.New("CLI requires at least 3 args: ADAPTER ACTION DATA...") + } // get adapter from first arg adapterName := args[0] @@ -30,10 +35,15 @@ func Process(args ...string) error { } for _, x := range settings { if x.Nickname == adapterName { - s = x + s = &x break } } + + if s == nil { + return errors.New("given adapter " + adapterName + " is not in the config file") + } + // instantiate adapter with config var a adapter.Adapter switch s.Protocol { @@ -46,10 +56,14 @@ func Process(args ...string) error { default: break } - a.Init(s, nil) + a.Init(*s, nil) // process remaining args and execute switch args[0] { + case "fetch": + a.Fetch(args[1], args[2:]) + case "do": + a.Do(args[1], args[2:]) default: log.Print(args) }