this repo has no description
0
fork

Configure Feed

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

update beemo to cli/v3

+36 -37
+17 -16
cmd/beemo/main.go
··· 4 4 package main 5 5 6 6 import ( 7 + "context" 7 8 "io" 8 9 "log/slog" 9 10 "os" ··· 13 14 _ "go.uber.org/automaxprocs" 14 15 15 16 "github.com/earthboundkid/versioninfo/v2" 16 - "github.com/urfave/cli/v2" 17 + "github.com/urfave/cli/v3" 17 18 ) 18 19 19 20 func main() { ··· 25 26 26 27 func run(args []string) error { 27 28 28 - app := cli.App{ 29 + app := cli.Command{ 29 30 Name: "beemo", 30 31 Usage: "bluesky moderation reporting bot", 31 32 Version: versioninfo.Short(), ··· 35 36 &cli.StringFlag{ 36 37 Name: "log-level", 37 38 Usage: "log verbosity level (eg: warn, info, debug)", 38 - EnvVars: []string{"BEEMO_LOG_LEVEL", "GO_LOG_LEVEL", "LOG_LEVEL"}, 39 + Sources: cli.EnvVars("BEEMO_LOG_LEVEL", "GO_LOG_LEVEL", "LOG_LEVEL"), 39 40 }, 40 41 &cli.StringFlag{ 41 42 Name: "slack-webhook-url", 42 43 // eg: https://hooks.slack.com/services/X1234 43 44 Usage: "full URL of slack webhook", 44 45 Required: true, 45 - EnvVars: []string{"SLACK_WEBHOOK_URL"}, 46 + Sources: cli.EnvVars("SLACK_WEBHOOK_URL"), 46 47 }, 47 48 } 48 49 app.Commands = []*cli.Command{ ··· 55 56 Name: "pds-host", 56 57 Usage: "method, hostname, and port of PDS instance", 57 58 Value: "http://localhost:4849", 58 - EnvVars: []string{"ATP_PDS_HOST"}, 59 + Sources: cli.EnvVars("ATP_PDS_HOST"), 59 60 }, 60 61 &cli.StringFlag{ 61 62 Name: "admin-host", 62 63 Usage: "method, hostname, and port of admin interface (eg, Ozone), for direct links", 63 64 Value: "http://localhost:3000", 64 - EnvVars: []string{"ATP_ADMIN_HOST"}, 65 + Sources: cli.EnvVars("ATP_ADMIN_HOST"), 65 66 }, 66 67 &cli.IntFlag{ 67 68 Name: "poll-period", 68 69 Usage: "API poll period in seconds", 69 70 Value: 30, 70 - EnvVars: []string{"POLL_PERIOD"}, 71 + Sources: cli.EnvVars("POLL_PERIOD"), 71 72 }, 72 73 &cli.StringFlag{ 73 74 Name: "handle", 74 75 Usage: "for PDS login", 75 76 Required: true, 76 - EnvVars: []string{"ATP_AUTH_HANDLE"}, 77 + Sources: cli.EnvVars("ATP_AUTH_HANDLE"), 77 78 }, 78 79 &cli.StringFlag{ 79 80 Name: "password", 80 81 Usage: "for PDS login", 81 82 Required: true, 82 - EnvVars: []string{"ATP_AUTH_PASSWORD"}, 83 + Sources: cli.EnvVars("ATP_AUTH_PASSWORD"), 83 84 }, 84 85 &cli.StringFlag{ 85 86 Name: "admin-password", 86 87 Usage: "admin authentication password for PDS", 87 88 Required: true, 88 - EnvVars: []string{"ATP_AUTH_ADMIN_PASSWORD"}, 89 + Sources: cli.EnvVars("ATP_AUTH_ADMIN_PASSWORD"), 89 90 }, 90 91 }, 91 92 }, ··· 98 99 Name: "relay-host", 99 100 Usage: "method, hostname, and port of Relay instance (websocket)", 100 101 Value: "wss://bsky.network", 101 - EnvVars: []string{"ATP_RELAY_HOST"}, 102 + Sources: cli.EnvVars("ATP_RELAY_HOST"), 102 103 }, 103 104 &cli.StringFlag{ 104 105 Name: "mention-dids", 105 106 Usage: "DIDs to look for in mentions (comma-separated)", 106 107 Required: true, 107 - EnvVars: []string{"BEEMO_MENTION_DIDS"}, 108 + Sources: cli.EnvVars("BEEMO_MENTION_DIDS"), 108 109 }, 109 110 &cli.IntFlag{ 110 111 Name: "minimum-words", 111 112 Usage: "minimum length of post text (word count; zero for no minimum)", 112 113 Value: 0, 113 - EnvVars: []string{"BEEMO_MINIMUM_WORDS"}, 114 + Sources: cli.EnvVars("BEEMO_MINIMUM_WORDS"), 114 115 }, 115 116 }, 116 117 }, 117 118 } 118 - return app.Run(args) 119 + return app.Run(context.Background(), args) 119 120 } 120 121 121 - func configLogger(cctx *cli.Context, writer io.Writer) *slog.Logger { 122 + func configLogger(cmd *cli.Command, writer io.Writer) *slog.Logger { 122 123 var level slog.Level 123 - switch strings.ToLower(cctx.String("log-level")) { 124 + switch strings.ToLower(cmd.String("log-level")) { 124 125 case "error": 125 126 level = slog.LevelError 126 127 case "warn":
+7 -8
cmd/beemo/notify_mentions.go
··· 11 11 "github.com/bluesky-social/indigo/atproto/identity" 12 12 "github.com/bluesky-social/indigo/atproto/syntax" 13 13 14 - "github.com/urfave/cli/v2" 14 + "github.com/urfave/cli/v3" 15 15 ) 16 16 17 17 type MentionChecker struct { ··· 61 61 return nil 62 62 } 63 63 64 - func notifyMentions(cctx *cli.Context) error { 65 - ctx := context.Background() 66 - logger := configLogger(cctx, os.Stdout) 67 - relayHost := cctx.String("relay-host") 68 - minimumWords := cctx.Int("minimum-words") 64 + func notifyMentions(ctx context.Context, cmd *cli.Command) error { 65 + logger := configLogger(cmd, os.Stdout) 66 + relayHost := cmd.String("relay-host") 67 + minimumWords := cmd.Int("minimum-words") 69 68 70 69 mentionDIDs := []syntax.DID{} 71 - for _, raw := range strings.Split(cctx.String("mention-dids"), ",") { 70 + for _, raw := range strings.Split(cmd.String("mention-dids"), ",") { 72 71 did, err := syntax.ParseDID(raw) 73 72 if err != nil { 74 73 return err ··· 77 76 } 78 77 79 78 checker := MentionChecker{ 80 - slackWebhookURL: cctx.String("slack-webhook-url"), 79 + slackWebhookURL: cmd.String("slack-webhook-url"), 81 80 mentionDIDs: mentionDIDs, 82 81 logger: logger, 83 82 directory: identity.DefaultDirectory(),
+12 -13
cmd/beemo/notify_reports.go
··· 12 12 "github.com/bluesky-social/indigo/util" 13 13 "github.com/bluesky-social/indigo/xrpc" 14 14 15 - "github.com/urfave/cli/v2" 15 + "github.com/urfave/cli/v3" 16 16 ) 17 17 18 - func pollNewReports(cctx *cli.Context) error { 19 - ctx := context.Background() 20 - logger := configLogger(cctx, os.Stdout) 21 - slackWebhookURL := cctx.String("slack-webhook-url") 18 + func pollNewReports(ctx context.Context, cmd *cli.Command) error { 19 + logger := configLogger(cmd, os.Stdout) 20 + slackWebhookURL := cmd.String("slack-webhook-url") 22 21 23 22 // record last-seen report timestamp 24 23 since := time.Now() 25 24 // NOTE: uncomment this for testing 26 25 //since = time.Now().Add(time.Duration(-12) * time.Hour) 27 - period := time.Duration(cctx.Int("poll-period")) * time.Second 26 + period := time.Duration(cmd.Int("poll-period")) * time.Second 28 27 29 28 // create a new session 30 29 xrpcc := &xrpc.Client{ 31 30 Client: util.RobustHTTPClient(), 32 - Host: cctx.String("pds-host"), 33 - Auth: &xrpc.AuthInfo{Handle: cctx.String("handle")}, 31 + Host: cmd.String("pds-host"), 32 + Auth: &xrpc.AuthInfo{Handle: cmd.String("handle")}, 34 33 } 35 34 36 35 auth, err := comatproto.ServerCreateSession(ctx, xrpcc, &comatproto.ServerCreateSession_Input{ 37 36 Identifier: xrpcc.Auth.Handle, 38 - Password: cctx.String("password"), 37 + Password: cmd.String("password"), 39 38 }) 40 39 if err != nil { 41 40 return err ··· 45 44 xrpcc.Auth.Did = auth.Did 46 45 xrpcc.Auth.Handle = auth.Handle 47 46 48 - adminToken := cctx.String("admin-password") 47 + adminToken := cmd.String("admin-password") 49 48 if len(adminToken) > 0 { 50 49 xrpcc.AdminToken = &adminToken 51 50 } ··· 70 69 // query just new reports (regardless of resolution state) 71 70 var limit int64 = 50 72 71 me, err := toolsozone.ModerationQueryEvents( 73 - cctx.Context, 72 + ctx, 74 73 xrpcc, 75 74 nil, // addedLabels []string 76 75 nil, // addedTags []string ··· 113 112 // ok, we found a "new" report, need to notify 114 113 msg := fmt.Sprintf("⚠️ New report at `%s` ⚠️\n", evt.CreatedAt) 115 114 msg += fmt.Sprintf("report id: `%d`\t", evt.Id) 116 - msg += fmt.Sprintf("instance: `%s`\n", cctx.String("pds-host")) 115 + msg += fmt.Sprintf("instance: `%s`\n", cmd.String("pds-host")) 117 116 msg += fmt.Sprintf("reasonType: `%s`\t", shortType) 118 - msg += fmt.Sprintf("Admin: %s/reports/%d\n", cctx.String("admin-host"), evt.Id) 117 + msg += fmt.Sprintf("Admin: %s/reports/%d\n", cmd.String("admin-host"), evt.Id) 119 118 //msg += fmt.Sprintf("reportedByDid: `%s`\n", report.ReportedByDid) 120 119 logger.Info("found new report, notifying slack", "report", report) 121 120 err := sendSlackMsg(ctx, msg, slackWebhookURL)