From 1f4ca3cb271bafc3a05a5a6907d1d7ba1ce24b4f Mon Sep 17 00:00:00 2001 From: Jun Nishimura Date: Sun, 6 Aug 2023 13:00:24 +0900 Subject: [PATCH] update main.go (#32) --- main.go | 56 ++------------------------------------------------------ 1 file changed, 2 insertions(+), 54 deletions(-) diff --git a/main.go b/main.go index 6032946..df16432 100644 --- a/main.go +++ b/main.go @@ -4,65 +4,13 @@ Copyright © 2023 NAME HERE package main import ( - "context" - "fmt" "log" "github.com/JunNishimura/Chatify/cmd" - "github.com/JunNishimura/spotify/v2" - spotifyauth "github.com/JunNishimura/spotify/v2/auth" "github.com/spf13/cobra" ) -const ( - redirectURI = "http://localhost:8888/callback" -) - -var ( - auth *spotifyauth.Authenticator - clientChannel = make(chan *spotify.Client, 1) -) - func main() { - auth = spotifyauth.New( - spotifyauth.WithClientID(clientViper.GetString(SpotifyIDKeyName)), - spotifyauth.WithClientSecret(clientViper.GetString(SpotifySecretKeyName)), - spotifyauth.WithRedirectURL(redirectURI), - spotifyauth.WithScopes(spotifyauth.ScopeUserReadPrivate), - ) - - // check if token viper is set - if !isClientInfoSet() { - authorize() - } else { - ctx := context.Background() - token := getToken() - - newToken, err := auth.RefreshToken(ctx, token) - if err != nil { - log.Fatalf("fail to get a new access token: %v", err) - } - - // update an access token if it has expired - if token.AccessToken != newToken.AccessToken { - if err := saveToken(newToken); err != nil { - log.Fatalf("fail to save token: %v", err) - } - } - - spotifyClient := spotify.New(auth.Client(ctx, newToken)) - - clientChannel <- spotifyClient - } - - client := <-clientChannel - - user, err := client.CurrentUser(context.Background()) - if err != nil { - log.Fatalf("fail to get current user: %v\n", err) - } - fmt.Printf("logged in as: %s\n", user.DisplayName) - rootCmd := &cobra.Command{ Use: "chatify", Short: "chatify is a CLI tool that suggests music recommendations for you", @@ -70,11 +18,11 @@ func main() { Run: func(cmd *cobra.Command, args []string) {}, } - heyCommand := cmd.NewHeyCommand(context.Background(), client, clientViper.GetString(OpenAIApiKeyName)) + // heyCommand := cmd.NewHeyCommand(context.Background(), client, clientViper.GetString(OpenAIApiKeyName)) greetingCommand := cmd.NewGreetingCommand() rootCmd.AddCommand( - heyCommand, + // heyCommand, greetingCommand, )