Directly use *discordgo.Session from global state
This commit is contained in:
parent
2dde45cc95
commit
e43a631950
2 changed files with 6 additions and 9 deletions
11
discord.go
11
discord.go
|
|
@ -96,15 +96,12 @@ type loginResponse struct {
|
|||
Token string `json:"token"`
|
||||
}
|
||||
|
||||
func login(
|
||||
s *discordgo.Session,
|
||||
email, password string,
|
||||
) (*loginResponse, error) {
|
||||
func login(email, password string) (*loginResponse, error) {
|
||||
data := struct {
|
||||
Email string `json:"email"`
|
||||
Password string `json:"password"`
|
||||
}{email, password}
|
||||
resp, err := s.RequestWithBucketID(
|
||||
resp, err := session.RequestWithBucketID(
|
||||
"POST",
|
||||
discordgo.EndpointLogin,
|
||||
data,
|
||||
|
|
@ -123,13 +120,13 @@ func login(
|
|||
return &lr, nil
|
||||
}
|
||||
|
||||
func totp(s *discordgo.Session, code, ticket string) (*loginResponse, error) {
|
||||
func totp(code, ticket string) (*loginResponse, error) {
|
||||
data := struct {
|
||||
Code string `json:"code"`
|
||||
Ticket string `json:"ticket"`
|
||||
}{code, ticket}
|
||||
e := discordgo.EndpointAuth + "mfa/totp"
|
||||
resp, err := s.RequestWithBucketID("POST", e, data, e)
|
||||
resp, err := session.RequestWithBucketID("POST", e, data, e)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
4
main.go
4
main.go
|
|
@ -93,7 +93,7 @@ func onLoginFormLoginButtonSelected() {
|
|||
|
||||
session = newSession()
|
||||
// Login using the email and password
|
||||
lr, err := login(session, email, password)
|
||||
lr, err := login(email, password)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
@ -118,7 +118,7 @@ func onLoginFormLoginButtonSelected() {
|
|||
return
|
||||
}
|
||||
|
||||
lr, err = totp(session, code, lr.Ticket)
|
||||
lr, err = totp(code, lr.Ticket)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue