mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-11-08 16:20:02 +00:00
Knut Ahlers
f5f8feb730
also switch to yaml.v3 to improve config rendering Signed-off-by: Knut Ahlers <knut@ahlers.me>
43 lines
1 KiB
Go
43 lines
1 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/gofrs/uuid/v3"
|
|
"github.com/pkg/errors"
|
|
log "github.com/sirupsen/logrus"
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
func init() {
|
|
cli.Add(cliRegistryEntry{
|
|
Name: "api-token",
|
|
Description: "Generate an api-token to be entered into the config",
|
|
Params: []string{"<token-name>", "<scope>", "[...scope]"},
|
|
Run: func(args []string) error {
|
|
if len(args) < 3 { //nolint:gomnd // Just a count of parameters
|
|
return errors.New("Usage: twitch-bot api-token <token name> <scope> [...scope]")
|
|
}
|
|
|
|
t := configAuthToken{
|
|
Name: args[1],
|
|
Modules: args[2:],
|
|
}
|
|
|
|
if err := fillAuthToken(&t); err != nil {
|
|
return errors.Wrap(err, "generating token")
|
|
}
|
|
|
|
log.WithField("token", t.Token).Info("Token generated, add this to your config:")
|
|
if err := yaml.NewEncoder(os.Stdout).Encode(map[string]map[string]configAuthToken{
|
|
"auth_tokens": {
|
|
uuid.Must(uuid.NewV4()).String(): t,
|
|
},
|
|
}); err != nil {
|
|
return errors.Wrap(err, "printing token info")
|
|
}
|
|
|
|
return nil
|
|
},
|
|
})
|
|
}
|