-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add fetch users * Fix
- Loading branch information
Showing
3 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"log" | ||
"os" | ||
"strings" | ||
|
||
"github.com/MixinNetwork/bot-api-go-client/v3" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
var getUsersCmdCli = &cli.Command{ | ||
Name: "users", | ||
Action: getUsersCmd, | ||
Flags: []cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: "keystore,k", | ||
Usage: "keystore download from https://developers.mixin.one/dashboard", | ||
}, | ||
&cli.StringFlag{ | ||
Name: "users", | ||
Usage: "user ids", | ||
}, | ||
}, | ||
} | ||
|
||
func getUsersCmd(ctx *cli.Context) error { | ||
keystore := ctx.String("keystore") | ||
idStr := ctx.String("users") | ||
|
||
log.Println(keystore, idStr) | ||
dat, err := os.ReadFile(keystore) | ||
if err != nil { | ||
panic(err) | ||
} | ||
log.Println(string(dat)) | ||
var su bot.SafeUser | ||
err = json.Unmarshal([]byte(dat), &su) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
ids := strings.Split(idStr, ",") | ||
users, err := bot.GetUsers(context.Background(), ids, &su) | ||
if err != nil { | ||
panic(err) | ||
} | ||
for _, user := range users { | ||
log.Printf("%#v", user) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters