diff --git a/README.md b/README.md index d7cf9bc..7f9b65e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ A [yarn.social](https://yarn.social) client from the future ## Current status -* [ ] Follow/Unfollow +* [X] Follow/Unfollow * [X] Login * [X] Posting * [ ] Timeline diff --git a/cmd/follow.go b/cmd/follow.go new file mode 100644 index 0000000..63ab338 --- /dev/null +++ b/cmd/follow.go @@ -0,0 +1,45 @@ +package main + +import ( + log "github.com/sirupsen/logrus" + "github.com/spf13/cobra" + "git.laidback.moe/shinyoukai/mikuru" + "go.yarn.social/client" +) + +var followCmd = &cobra.Command{ + Use: "follow ", + Short: "Track a twtxt.txt feed, located in a Yarn pod or otherwise", + Run: func(_ *cobra.Command, args []string) { + cli, err := client.NewClient( + client.WithURI(mikuru.Config.Host), + client.WithToken(mikuru.Config.Token), + ) + if err != nil { + log.Fatal(err) + } + if len(args) != 2 { + log.Fatal("Not enough arguments") + } + nick := args[0] + url := args[1] + + observe(cli, nick, url) + if err != nil { + log.Fatalf("Could not follow %s at %s\n", nick, url) + } + }, +} + +func init() { + mikuru.ConfInit() + rootCmd.AddCommand(followCmd) +} + +func observe(cli *client.Client, nick, url string) error { + err := cli.Follow(nick, url) + if err != nil { + return err + } + return nil +} diff --git a/cmd/unfollow.go b/cmd/unfollow.go new file mode 100644 index 0000000..33954ed --- /dev/null +++ b/cmd/unfollow.go @@ -0,0 +1,44 @@ +package main + +import ( + log "github.com/sirupsen/logrus" + "github.com/spf13/cobra" + "git.laidback.moe/shinyoukai/mikuru" + "go.yarn.social/client" +) + +var unfollowCmd = &cobra.Command{ + Use: "unfollow ", + Short: "Cease to track a feed", + Run: func(_ *cobra.Command, args []string) { + cli, err := client.NewClient( + client.WithURI(mikuru.Config.Host), + client.WithToken(mikuru.Config.Token), + ) + if err != nil { + log.Fatal(err) + } + if len(args) != 1 { + log.Fatal("Not enough arguments") + } + nick := args[0] + + leave_alone(cli, nick) + if err != nil { + log.Fatalf("Could not unfollow %s\n", nick) + } + }, +} + +func init() { + mikuru.ConfInit() + rootCmd.AddCommand(unfollowCmd) +} + +func leave_alone(cli *client.Client, nick string) error { + err := cli.Unfollow(nick) + if err != nil { + return err + } + return nil +}