this repo has no description
0
fork

Configure Feed

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

bulk invites commands, and some moderation query tooling (#147)

authored by

Whyrusleeping and committed by
GitHub
d8d3324b b18c0e75

+95 -29
+76 -1
cmd/gosky/admin.go
··· 20 20 Subcommands: []*cli.Command{ 21 21 buildInviteTreeCmd, 22 22 checkUserCmd, 23 + reportsCmd, 23 24 }, 24 25 } 25 26 ··· 96 97 var lk sync.Mutex 97 98 var wg sync.WaitGroup 98 99 var used int 100 + var revoked int 99 101 for _, inv := range rep.Invites { 100 102 used += len(inv.Uses) 101 103 104 + if inv.Disabled { 105 + revoked++ 106 + } 102 107 for _, u := range inv.Uses { 103 108 wg.Add(1) 104 109 go func(did string) { ··· 118 123 119 124 wg.Wait() 120 125 121 - fmt.Printf("Invites, used %d of %d\n", used, len(rep.Invites)) 126 + fmt.Printf("Invites, used %d of %d (%d disabled)\n", used, len(rep.Invites), revoked) 122 127 for _, inv := range invited { 123 128 124 129 var invited, total int ··· 297 302 298 303 return json.NewEncoder(outfi).Encode(users) 299 304 */ 305 + 300 306 return nil 301 307 }, 302 308 } ··· 317 323 Invited []string 318 324 TotalInvites int 319 325 } 326 + 327 + var reportsCmd = &cli.Command{ 328 + Name: "reports", 329 + Subcommands: []*cli.Command{ 330 + listReportsCmd, 331 + }, 332 + } 333 + 334 + var listReportsCmd = &cli.Command{ 335 + Name: "list", 336 + Flags: []cli.Flag{ 337 + &cli.StringFlag{ 338 + Name: "admin-password", 339 + EnvVars: []string{"ATP_AUTH_ADMIN_PASSWORD"}, 340 + Required: true, 341 + }, 342 + &cli.StringFlag{ 343 + Name: "plc", 344 + Usage: "method, hostname, and port of PLC registry", 345 + Value: "https://plc.directory", 346 + EnvVars: []string{"ATP_PLC_HOST"}, 347 + }, 348 + &cli.BoolFlag{ 349 + Name: "raw", 350 + }, 351 + }, 352 + Action: func(cctx *cli.Context) error { 353 + xrpcc, err := cliutil.GetXrpcClient(cctx, false) 354 + if err != nil { 355 + return err 356 + } 357 + 358 + ctx := context.Background() 359 + 360 + adminKey := cctx.String("admin-password") 361 + xrpcc.AdminToken = &adminKey 362 + 363 + resp, err := comatproto.AdminGetModerationReports(ctx, xrpcc, "", 100, true, "") 364 + if err != nil { 365 + return err 366 + } 367 + 368 + tojson := func(i any) string { 369 + b, err := json.MarshalIndent(i, "", " ") 370 + if err != nil { 371 + panic(err) 372 + } 373 + 374 + return string(b) 375 + } 376 + 377 + for _, rep := range resp.Reports { 378 + b, err := json.MarshalIndent(rep, "", " ") 379 + if err != nil { 380 + return err 381 + } 382 + fmt.Println(string(b)) 383 + for _, act := range rep.ResolvedByActionIds { 384 + action, err := comatproto.AdminGetModerationAction(ctx, xrpcc, act) 385 + if err != nil { 386 + return err 387 + } 388 + 389 + fmt.Println(tojson(action)) 390 + } 391 + } 392 + return nil 393 + }, 394 + }
+19 -28
cmd/gosky/main.go
··· 10 10 "os" 11 11 "os/signal" 12 12 "strings" 13 - "sync" 14 13 "syscall" 15 14 "time" 16 15 ··· 723 722 var followsListCmd = &cli.Command{ 724 723 Name: "list", 725 724 Action: func(cctx *cli.Context) error { 726 - xrpcc, err := cliutil.GetXrpcClient(cctx, true) 725 + xrpcc, err := cliutil.GetXrpcClient(cctx, false) 727 726 if err != nil { 728 727 return err 729 728 } ··· 1030 1029 Value: 1, 1031 1030 }, 1032 1031 &cli.StringFlag{ 1033 - Name: "bulk-dids", 1032 + Name: "bulk", 1034 1033 }, 1035 1034 }, 1036 1035 Action: func(cctx *cli.Context) error { ··· 1044 1043 count := cctx.Int("useCount") 1045 1044 num := cctx.Int("num") 1046 1045 1047 - if bulkfi := cctx.String("bulk-dids"); bulkfi != "" { 1046 + if bulkfi := cctx.String("bulk"); bulkfi != "" { 1048 1047 xrpcc.AdminToken = &adminKey 1049 1048 dids, err := readDids(bulkfi) 1050 1049 if err != nil { 1051 1050 return err 1052 1051 } 1053 1052 1054 - feeder := make(chan string) 1055 - var wg sync.WaitGroup 1056 - for i := 0; i < 20; i++ { 1057 - wg.Add(1) 1058 - go func() { 1059 - defer wg.Done() 1060 - for d := range feeder { 1061 - did := d 1062 - resp, err := comatproto.ServerCreateInviteCodes(context.TODO(), xrpcc, &comatproto.ServerCreateInviteCodes_Input{ 1063 - UseCount: int64(count), 1064 - ForAccounts: []string{did}, 1065 - CodeCount: int64(num), 1066 - }) 1067 - if err != nil { 1068 - log.Error(err) 1069 - } 1070 - _ = resp 1053 + for i, d := range dids { 1054 + if !strings.HasPrefix(d, "did:plc:") { 1055 + out, err := comatproto.IdentityResolveHandle(context.TODO(), xrpcc, d) 1056 + if err != nil { 1057 + return fmt.Errorf("failed to resolve %q: %w", d, err) 1071 1058 } 1072 - }() 1073 - } 1074 1059 1075 - for _, d := range dids { 1076 - feeder <- d 1060 + dids[i] = out.Did 1061 + } 1077 1062 } 1078 1063 1079 - close(feeder) 1064 + _, err = comatproto.ServerCreateInviteCodes(context.TODO(), xrpcc, &comatproto.ServerCreateInviteCodes_Input{ 1065 + UseCount: int64(count), 1066 + ForAccounts: dids, 1067 + CodeCount: int64(num), 1068 + }) 1069 + if err != nil { 1070 + return err 1071 + } 1080 1072 1081 - wg.Wait() 1082 1073 return nil 1083 1074 } 1084 1075 ··· 1123 1114 scan := bufio.NewScanner(fi) 1124 1115 var out []string 1125 1116 for scan.Scan() { 1126 - out = append(out, scan.Text()) 1117 + out = append(out, strings.Split(scan.Text(), " ")[0]) 1127 1118 } 1128 1119 1129 1120 return out, nil