-
Notifications
You must be signed in to change notification settings - Fork 3
/
cmdgroupgive.go
52 lines (48 loc) · 1.57 KB
/
cmdgroupgive.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"fmt"
"github.com/nlm/briq-cli/briq"
"github.com/nlm/briq-cli/utils"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
func init() {
GroupGiveCmd.Flags().String("to-group", "", "group name")
GroupGiveCmd.Flags().String("message", "🎁 #Community", "message to send")
GroupGiveCmd.Flags().Uint("amount", 1, "how many briqs to give")
GroupGiveCmd.MarkFlagRequired("group")
Register(&GroupGiveCmd)
}
var GroupGiveCmd = cobra.Command{
Use: "group-give",
Aliases: []string{"gg"},
Short: "Give one or more briqs to a group",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
argToGroup, err := cmd.Flags().GetString("to-group")
cobra.CheckErr(err)
argMessage, err := cmd.Flags().GetString("message")
cobra.CheckErr(err)
argAmount, err := cmd.Flags().GetUint("amount")
cobra.CheckErr(err)
groupUserNames := viper.GetStringSlice(fmt.Sprintf("groups.%s", argToGroup))
client, err := briq.NewClient(viper.GetString(viperKeyBriqSecretKey))
cobra.CheckErr(err)
req := &briq.ListUsersRequest{}
res, err := client.ListUsers(cmd.Context(), req)
cobra.CheckErr(err)
for _, user := range utils.FilterSlice(res.Users, groupUserNames, BriqUserKey) {
for i := uint(0); i < CapBriqAmount(argAmount); i++ {
fmt.Printf("Sending gift to %s (%v)\n", user.Username, user.Id)
req := &briq.CreateTransactionRequest{
App: briq.AppGive,
To: user.Id,
Comment: argMessage,
}
res, err := client.CreateTransaction(cmd.Context(), req)
cobra.CheckErr(err)
cobra.CheckErr(Render(res))
}
}
},
}