From f2e8a05bac941daa2d06c1be83f3de86fb761c39 Mon Sep 17 00:00:00 2001 From: Ayyan Date: Thu, 23 Jan 2025 20:26:05 -0500 Subject: [PATCH] feat(config): add user_agent field (#486) Co-authored-by: ayn2op --- cmd/state.go | 23 +++++++++---------- internal/config/config.go | 47 +++++++++++++++++++++++---------------- internal/login/form.go | 2 ++ 3 files changed, 40 insertions(+), 32 deletions(-) diff --git a/cmd/state.go b/cmd/state.go index ce8b47b..f9ee682 100644 --- a/cmd/state.go +++ b/cmd/state.go @@ -16,19 +16,6 @@ import ( "github.com/rivo/tview" ) -const userAgent = config.Name + "/0.1 (https://github.com/diamondburned/arikawa, v3)" - -func init() { - api.UserAgent = userAgent - gateway.DefaultIdentity = gateway.IdentifyProperties{ - OS: runtime.GOOS, - Device: "", - - Browser: config.Name, - BrowserUserAgent: userAgent, - } -} - type State struct { *ningen.State cfg *config.Config @@ -36,6 +23,16 @@ type State struct { } func openState(token string, app *tview.Application, cfg *config.Config) error { + api.UserAgent = cfg.UserAgent + gateway.DefaultIdentity = gateway.IdentifyProperties{ + OS: runtime.GOOS, + Device: "", + + Browser: cfg.Browser, + BrowserVersion: cfg.BrowserVersion, + BrowserUserAgent: cfg.UserAgent, + } + discordState = &State{ State: ningen.New(token), cfg: cfg, diff --git a/internal/config/config.go b/internal/config/config.go index 7fa3b77..2e0271a 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -9,35 +9,44 @@ import ( "github.com/BurntSushi/toml" ) -const Name = "discordo" +const ( + Name = "discordo" + + Browser = "Chrome" + BrowserVersion = "132.0.0.0" + UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) " + Browser + "/" + BrowserVersion + " Safari/537.36" +) type Config struct { - Mouse bool `toml:"mouse"` - HideBlockedUsers bool `toml:"hide_blocked_users"` + Mouse bool `toml:"mouse"` + HideBlockedUsers bool `toml:"hide_blocked_users"` + Timestamps bool `toml:"timestamps"` + ShowAttachmentLinks bool `toml:"show_attachment_links"` + MessagesLimit uint8 `toml:"messages_limit"` + Editor string `toml:"editor"` - MessagesLimit uint8 `toml:"messages_limit"` - Editor string `toml:"editor"` + Browser string `toml:"browser"` + BrowserVersion string `toml:"browser_version"` + UserAgent string `toml:"user_agent"` - Timestamps bool `toml:"timestamps"` TimestampsFormat string `toml:"timestamps_format"` - - ShowAttachmentLinks bool `toml:"show_attachment_links"` - - Keys Keys `toml:"keys"` - Theme Theme `toml:"theme"` + Keys Keys `toml:"keys"` + Theme Theme `toml:"theme"` } func defaultConfig() *Config { return &Config{ - Mouse: true, - HideBlockedUsers: true, - MessagesLimit: 50, - Editor: "default", - - Timestamps: false, - TimestampsFormat: time.Kitchen, - + Mouse: true, + HideBlockedUsers: true, + Timestamps: false, ShowAttachmentLinks: true, + MessagesLimit: 50, + Editor: "default", + TimestampsFormat: time.Kitchen, + + Browser: Browser, + BrowserVersion: BrowserVersion, + UserAgent: UserAgent, Keys: defaultKeys(), Theme: defaultTheme(), diff --git a/internal/login/form.go b/internal/login/form.go index eaabaff..7bdcc61 100644 --- a/internal/login/form.go +++ b/internal/login/form.go @@ -108,6 +108,8 @@ func (self *Form) login() { // Create an API client without an authentication token. client := api.NewClient("") + // Spoof the user agent of a web browser. + client.UserAgent = config.UserAgent // Attempt to login using the email and password. resp, err := client.Login(email, password)