More URLs cleanup

This commit is contained in:
DevilXD committed 2022-03-11 17:28:50 +01:00
1 parent 9ad0979d0e
commit 25bc398ec1
3 files changed
+15 -13

No files matched your search

+1 -4
View File
@@ -20,11 +20,8 @@ TopicProcess: TypeAlias = "abc.Callable[[int, JsonType], Any]"
# Values
MAX_WEBSOCKETS = 8
WS_TOPICS_LIMIT = 50
# URLs
# Misc
BASE_URL = "https://twitch.tv"
WEBSOCKET_URL = "wss://pubsub-edge.twitch.tv/v1"
GQL_URL = "https://gql.twitch.tv/gql"
# Misc for Twitch
CLIENT_ID = "kimne78kx3ncx6brgo4mv6wki5h1ko"
USER_AGENT = (
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
+9 -6
View File
@@ -23,7 +23,6 @@ from inventory import DropsCampaign
from utils import task_wrapper, timestamp, AwaitableValue, OrderedSet
from exceptions import RequestException, LoginException, CaptchaRequired
from constants import (
GQL_URL,
BASE_URL,
CLIENT_ID,
USER_AGENT,
@@ -824,12 +823,16 @@ class Twitch:
) from cause
async def gql_request(self, op: GQLOperation) -> JsonType:
headers = {
"Authorization": f"OAuth {self._access_token}",
"Client-Id": CLIENT_ID,
}
gql_logger.debug(f"GQL Request: {op}")
async with self.request("POST", GQL_URL, json=op, headers=headers) as response:
async with self.request(
"POST",
"https://gql.twitch.tv/gql",
json=op,
headers={
"Authorization": f"OAuth {self._access_token}",
"Client-Id": CLIENT_ID,
}
) as response:
response_json: JsonType = await response.json()
gql_logger.debug(f"GQL Response: {response_json}")
return response_json
+5 -3
View File
@@ -15,7 +15,7 @@ except ModuleNotFoundError as exc:
from exceptions import MinerException
from utils import task_wrapper, create_nonce, AwaitableValue
from constants import WEBSOCKET_URL, PING_INTERVAL, PING_TIMEOUT, MAX_WEBSOCKETS, WS_TOPICS_LIMIT
from constants import PING_INTERVAL, PING_TIMEOUT, MAX_WEBSOCKETS, WS_TOPICS_LIMIT
if TYPE_CHECKING:
from twitch import Twitch
@@ -110,10 +110,12 @@ class Websocket:
async def _handle(self):
# ensure we're logged in before connecting
await self._twitch.wait_until_login()
self.set_status("Connecting...")
ws_logger.info(f"Websocket[{self._idx}] connecting...")
self.set_status("Connecting...")
# Connect/Reconnect loop
async for websocket in websocket_connect(WEBSOCKET_URL, ssl=True, ping_interval=None):
async for websocket in websocket_connect(
"wss://pubsub-edge.twitch.tv/v1", ssl=True, ping_interval=None
):
# 3 minutes of max backoff
websocket.BACKOFF_MAX = 3 * 60 # type: ignore
self._ws.set(websocket)