this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

basic bsky prefs export/import

+93
+1
cmd/goat/bsky.go
··· 23 23 ArgsUsage: `<text>`, 24 24 Action: runBskyPost, 25 25 }, 26 + cmdBskyPrefs, 26 27 }, 27 28 } 28 29
+92
cmd/goat/bsky_prefs.go
··· 1 + package main 2 + 3 + import ( 4 + "context" 5 + "encoding/json" 6 + "fmt" 7 + "os" 8 + 9 + appbsky "github.com/bluesky-social/indigo/api/bsky" 10 + 11 + "github.com/urfave/cli/v2" 12 + ) 13 + 14 + var cmdBskyPrefs = &cli.Command{ 15 + Name: "prefs", 16 + Usage: "sub-commands for preferences", 17 + Flags: []cli.Flag{}, 18 + Subcommands: []*cli.Command{ 19 + &cli.Command{ 20 + Name: "export", 21 + Usage: "dump preferences out as JSON", 22 + Action: runBskyPrefsExport, 23 + }, 24 + &cli.Command{ 25 + Name: "import", 26 + Usage: "upload preferences from JSON file", 27 + ArgsUsage: `<file>`, 28 + Action: runBskyPrefsImport, 29 + }, 30 + }, 31 + } 32 + 33 + func runBskyPrefsExport(cctx *cli.Context) error { 34 + ctx := context.Background() 35 + 36 + xrpcc, err := loadAuthClient(ctx) 37 + if err == ErrNoAuthSession { 38 + return fmt.Errorf("auth required, but not logged in") 39 + } else if err != nil { 40 + return err 41 + } 42 + 43 + // TODO: does this crash with unsupported preference types? 44 + resp, err := appbsky.ActorGetPreferences(ctx, xrpcc) 45 + if err != nil { 46 + return fmt.Errorf("failed fetching old preferences: %w", err) 47 + } 48 + 49 + b, err := json.MarshalIndent(resp.Preferences, "", " ") 50 + if err != nil { 51 + return err 52 + } 53 + fmt.Println(string(b)) 54 + 55 + return nil 56 + } 57 + 58 + func runBskyPrefsImport(cctx *cli.Context) error { 59 + ctx := context.Background() 60 + prefsPath := cctx.Args().First() 61 + if prefsPath == "" { 62 + return fmt.Errorf("need to provide file path as an argument") 63 + } 64 + 65 + xrpcc, err := loadAuthClient(ctx) 66 + if err == ErrNoAuthSession { 67 + return fmt.Errorf("auth required, but not logged in") 68 + } else if err != nil { 69 + return err 70 + } 71 + 72 + prefsBytes, err := os.ReadFile(prefsPath) 73 + if err != nil { 74 + return err 75 + } 76 + 77 + var prefsArray []appbsky.ActorDefs_Preferences_Elem 78 + err = json.Unmarshal(prefsBytes, &prefsArray) 79 + if err != nil { 80 + return err 81 + } 82 + 83 + // TODO: does this clobber unsupported preference types? 84 + err = appbsky.ActorPutPreferences(ctx, xrpcc, &appbsky.ActorPutPreferences_Input{ 85 + Preferences: prefsArray, 86 + }) 87 + if err != nil { 88 + return fmt.Errorf("failed fetching old preferences: %w", err) 89 + } 90 + 91 + return nil 92 + }