From 6f85ff609353cf383bc03705107935b423ea14b6 Mon Sep 17 00:00:00 2001 From: ayn2op Date: Tue, 25 Mar 2025 19:02:26 -0400 Subject: [PATCH] feat(login): use user_agent from config instead of default --- cmd/app.go | 2 +- internal/login/form.go | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/cmd/app.go b/cmd/app.go index d02c84f..f70d565 100644 --- a/cmd/app.go +++ b/cmd/app.go @@ -43,7 +43,7 @@ func newApp(cfg *config.Config) *App { func (app *App) show(token string) error { if token == "" { - loginForm := login.NewForm(app.Application, func(token string) { + loginForm := login.NewForm(app.cfg, app.Application, func(token string) { if err := app.show(token); err != nil { slog.Error("failed to show app", "err", err) return diff --git a/internal/login/form.go b/internal/login/form.go index 3dfe48a..592aa8f 100644 --- a/internal/login/form.go +++ b/internal/login/form.go @@ -5,6 +5,7 @@ import ( "log/slog" "net/http" + "github.com/ayn2op/discordo/internal/config" "github.com/ayn2op/discordo/internal/consts" "github.com/diamondburned/arikawa/v3/api" "github.com/diamondburned/arikawa/v3/utils/httputil" @@ -16,16 +17,18 @@ type DoneFn = func(token string) type Form struct { *tview.Pages - form *tview.Form + cfg *config.Config app *tview.Application + form *tview.Form done DoneFn } -func NewForm(app *tview.Application, done DoneFn) *Form { +func NewForm(cfg *config.Config, app *tview.Application, done DoneFn) *Form { f := &Form{ Pages: tview.NewPages(), - form: tview.NewForm(), + cfg: cfg, app: app, + form: tview.NewForm(), done: done, } @@ -48,7 +51,7 @@ func (f *Form) login() { // Create an API client without an authentication token. client := api.NewClient("") // Spoof the user agent of a web browser. - client.UserAgent = consts.UserAgent + client.UserAgent = f.cfg.Identify.UserAgent body := httputil.WithJSONBody(struct { Email string `json:"login"`