github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/chat/tools/slam/slam.go (about)

     1  package main
     2  
     3  import (
     4  	"flag"
     5  	"fmt"
     6  	"os"
     7  	"os/exec"
     8  	"strings"
     9  )
    10  
    11  func getUsernames(allNames string) []string {
    12  	return strings.Split(allNames, ",")
    13  }
    14  
    15  func getConvs(usernames []string) (res []string) {
    16  	if len(usernames) == 0 {
    17  		return []string{""}
    18  	}
    19  	subRes := getConvs(usernames[1:])
    20  	for _, r := range subRes {
    21  		if len(r) > 0 {
    22  			res = append(res, r)
    23  			res = append(res, usernames[0]+","+r)
    24  		} else {
    25  			res = append(res, usernames[0])
    26  		}
    27  	}
    28  	return res
    29  }
    30  
    31  func main() {
    32  	flag.Parse()
    33  	args := flag.Args()
    34  	if len(args) != 2 {
    35  		fmt.Printf("must supply a set of users\n")
    36  		os.Exit(3)
    37  	}
    38  	kbcommand := args[0]
    39  	usernames := getUsernames(args[1])
    40  	fmt.Printf("forming convs from: %v\n", usernames)
    41  	convs := getConvs(usernames)
    42  	for _, c := range convs {
    43  		fmt.Printf("executing: %s chat send %s hi\n", kbcommand, c)
    44  		cmd := exec.Command(kbcommand, "chat", "send", c, "hi")
    45  		if err := cmd.Run(); err != nil {
    46  			fmt.Printf("error: %s\n", err)
    47  		}
    48  	}
    49  }