go-mastodon/cmd/mstdn/cmd_follow.go

31 lines
587 B
Go
Raw Normal View History

2017-04-19 07:17:18 +02:00
package main
import (
"context"
"errors"
"github.com/mattn/go-mastodon"
2022-11-27 05:24:42 +01:00
"github.com/urfave/cli/v2"
2017-04-19 07:17:18 +02:00
)
func cmdFollow(c *cli.Context) error {
client := c.App.Metadata["client"].(*mastodon.Client)
if !c.Args().Present() {
return errors.New("arguments required")
}
for i := 0; i < c.NArg(); i++ {
account, err := client.AccountsSearch(context.Background(), c.Args().Get(i), 1)
if err != nil {
return err
}
if len(account) == 0 {
continue
}
_, err = client.AccountFollow(context.Background(), account[0].ID)
if err != nil {
return err
}
}
return nil
}