46 lines
899 B
Go
46 lines
899 B
Go
package main
|
|
|
|
import (
|
|
log "github.com/sirupsen/logrus"
|
|
"github.com/spf13/cobra"
|
|
"git.laidback.moe/shinyoukai/mikuru/mirai"
|
|
"go.yarn.social/client"
|
|
)
|
|
|
|
var followCmd = &cobra.Command{
|
|
Use: "follow <NICK> <URL>",
|
|
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(mirai.Config.Host),
|
|
client.WithToken(mirai.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() {
|
|
mirai.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
|
|
}
|