consts.go 1.8 KB

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