Skip to content

Commit

Permalink
refactor oauth
Browse files Browse the repository at this point in the history
  • Loading branch information
f4tal-err0r committed Dec 19, 2024
1 parent 8458368 commit 5eaa7d9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 154 deletions.
13 changes: 12 additions & 1 deletion cmd/discord.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"log"

"github.com/f4tal-err0r/discord_faas/pkgs/client"
Expand All @@ -9,6 +10,7 @@ import (

func init() {
discordCmd.AddCommand(login)
discordCmd.AddCommand(currentUser)
}

var discordCmd = &cobra.Command{
Expand All @@ -20,8 +22,17 @@ var login = &cobra.Command{
Use: "login",
Short: "Auth to your Discord Guild",
Run: func(cmd *cobra.Command, args []string) {
if _, err := client.StartAuth(); err != nil {
dauth := client.NewUserAuth()
if _, err := dauth.StartAuth(); err != nil {
log.Fatal(err)
}
},
}

var currentUser = &cobra.Command{
Use: "current-user",
Short: "Get the current user",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Current User: %s", client.GetCurrentUser().String())
},
}
4 changes: 2 additions & 2 deletions pkgs/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/bwmarrin/discordgo"
)

func getCurrentUser() *discordgo.User {
token, err := GetToken()
func GetCurrentUser() *discordgo.User {
token, err := NewUserAuth().GetToken()
if err != nil {
log.Fatalf("Error getting token: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkgs/client/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func NewContext(url string, guildid string) *pb.ContextResp {
}

// Send the request with headers
oauth, err := GetToken()
oauth, err := NewUserAuth().GetToken()
if err != nil {
log.Fatal(err)
}
Expand Down
150 changes: 0 additions & 150 deletions pkgs/client/oauth.go

This file was deleted.

0 comments on commit 5eaa7d9

Please sign in to comment.