consts.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package consts
  2. import (
  3. "encoding/json"
  4. "net/http"
  5. "github.com/diamondburned/arikawa/v3/discord"
  6. "github.com/diamondburned/arikawa/v3/gateway"
  7. )
  8. const Name = "discordo"
  9. const (
  10. identifyPropertiesURL = "https://cordapi.dolfi.es/api/v2/properties/web"
  11. loginURL = "https://discord.com/login"
  12. )
  13. var defaultIdentifyProps = gateway.IdentifyProperties{
  14. Device: "",
  15. Browser: "Chrome",
  16. BrowserUserAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36",
  17. BrowserVersion: "138.0.0.0",
  18. OS: "Windows",
  19. OSVersion: "10",
  20. ClientBuildNumber: 415522,
  21. ReleaseChannel: "stable",
  22. SystemLocale: discord.EnglishUS,
  23. HasClientMods: false,
  24. }
  25. func GetIdentifyProps() gateway.IdentifyProperties {
  26. resp, err := http.Get(identifyPropertiesURL)
  27. if err != nil {
  28. return defaultIdentifyProps
  29. }
  30. defer resp.Body.Close()
  31. var props struct {
  32. Client struct {
  33. Type string `json:"type"`
  34. BuildNumber int `json:"build_number"`
  35. BuildHash string `json:"build_hash"`
  36. ReleaseChannel string `json:"release_channel"`
  37. } `json:"client"`
  38. Browser struct {
  39. Type string `json:"type"`
  40. UserAgent string `json:"user_agent"`
  41. Version string `json:"version"`
  42. OS struct {
  43. Type string `json:"type"`
  44. Version string `json:"version"`
  45. } `json:"os"`
  46. } `json:"browser"`
  47. }
  48. if err := json.NewDecoder(resp.Body).Decode(&props); err != nil {
  49. return defaultIdentifyProps
  50. }
  51. return gateway.IdentifyProperties{
  52. Device: "",
  53. Browser: props.Browser.Type,
  54. BrowserUserAgent: props.Browser.UserAgent,
  55. BrowserVersion: props.Browser.Version,
  56. OS: props.Browser.OS.Type,
  57. OSVersion: props.Browser.OS.Version,
  58. ClientBuildNumber: props.Client.BuildNumber,
  59. ReleaseChannel: props.Client.ReleaseChannel,
  60. SystemLocale: discord.EnglishUS,
  61. HasClientMods: false,
  62. }
  63. }