Browse Source

Set X-Discord-Locale header based on user settings

pull/10109/head
dolfies 2 years ago
parent
commit
7167014a6e
  1. 1
      discord/client.py
  2. 7
      discord/http.py

1
discord/client.py

@ -260,6 +260,7 @@ class Client:
http_trace=http_trace, http_trace=http_trace,
captcha_handler=captcha_handler, captcha_handler=captcha_handler,
max_ratelimit_timeout=max_ratelimit_timeout, max_ratelimit_timeout=max_ratelimit_timeout,
locale=lambda: self._connection.locale,
) )
self._handlers: Dict[str, Callable[..., None]] = { self._handlers: Dict[str, Callable[..., None]] = {

7
discord/http.py

@ -31,6 +31,7 @@ import ssl
import string import string
from typing import ( from typing import (
Any, Any,
Callable,
ClassVar, ClassVar,
Coroutine, Coroutine,
Dict, Dict,
@ -573,6 +574,7 @@ class HTTPClient:
http_trace: Optional[aiohttp.TraceConfig] = None, http_trace: Optional[aiohttp.TraceConfig] = None,
captcha_handler: Optional[CaptchaHandler] = None, captcha_handler: Optional[CaptchaHandler] = None,
max_ratelimit_timeout: Optional[float] = None, max_ratelimit_timeout: Optional[float] = None,
locale: Callable[[], str] = lambda: 'en-US',
) -> None: ) -> None:
self.loop: asyncio.AbstractEventLoop = loop self.loop: asyncio.AbstractEventLoop = loop
self.connector: aiohttp.BaseConnector = connector or MISSING self.connector: aiohttp.BaseConnector = connector or MISSING
@ -595,6 +597,7 @@ class HTTPClient:
self.use_clock: bool = not unsync_clock self.use_clock: bool = not unsync_clock
self.captcha_handler: Optional[CaptchaHandler] = captcha_handler self.captcha_handler: Optional[CaptchaHandler] = captcha_handler
self.max_ratelimit_timeout: Optional[float] = max(30.0, max_ratelimit_timeout) if max_ratelimit_timeout else None self.max_ratelimit_timeout: Optional[float] = max(30.0, max_ratelimit_timeout) if max_ratelimit_timeout else None
self.get_locale: Callable[[], str] = locale
self.super_properties: Dict[str, Any] = {} self.super_properties: Dict[str, Any] = {}
self.encoded_super_properties: str = MISSING self.encoded_super_properties: str = MISSING
@ -713,7 +716,7 @@ class HTTPClient:
'Origin': 'https://discord.com', 'Origin': 'https://discord.com',
'Pragma': 'no-cache', 'Pragma': 'no-cache',
'Referer': 'https://discord.com/channels/@me', 'Referer': 'https://discord.com/channels/@me',
'Sec-CH-UA': '"Google Chrome";v="{0}", "Chromium";v="{0}", ";Not A Brand";v="99"'.format( 'Sec-CH-UA': '"Google Chrome";v="{0}", "Chromium";v="{0}", ";Not-A.Brand";v="24"'.format(
self.browser_version.split('.')[0] self.browser_version.split('.')[0]
), ),
'Sec-CH-UA-Mobile': '?0', 'Sec-CH-UA-Mobile': '?0',
@ -722,7 +725,7 @@ class HTTPClient:
'Sec-Fetch-Mode': 'cors', 'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-origin', 'Sec-Fetch-Site': 'same-origin',
'User-Agent': self.user_agent, 'User-Agent': self.user_agent,
'X-Discord-Locale': 'en-US', 'X-Discord-Locale': self.get_locale(),
'X-Debug-Options': 'bugReporterEnabled', 'X-Debug-Options': 'bugReporterEnabled',
'X-Super-Properties': self.encoded_super_properties, 'X-Super-Properties': self.encoded_super_properties,
} }

Loading…
Cancel
Save