Redo some of the typing
This commit is contained in:
1 parent
ac8d15a43b
commit
76a34685da
2 files changed
+15
-12
No files matched your search
@@ -807,10 +807,10 @@ class Twitch:
|
|||||||
login_form.clear()
|
login_form.clear()
|
||||||
return self._access_token
|
return self._access_token
|
||||||
|
|
||||||
async def check_login(self) -> None:
|
async def check_login(self) -> tuple[str, int]:
|
||||||
if self._access_token is not None and self._user_id is not None:
|
if self._access_token is not None and self._user_id is not None:
|
||||||
# we're all good
|
# we're all good
|
||||||
return
|
return (self._access_token, self._user_id)
|
||||||
# looks like we're missing something
|
# looks like we're missing something
|
||||||
login_form: LoginForm = self.gui.login
|
login_form: LoginForm = self.gui.login
|
||||||
logger.debug("Checking login")
|
logger.debug("Checking login")
|
||||||
@@ -824,14 +824,16 @@ class Twitch:
|
|||||||
cookie = jar.filter_cookies(url)
|
cookie = jar.filter_cookies(url)
|
||||||
if not cookie:
|
if not cookie:
|
||||||
# no cookie - login
|
# no cookie - login
|
||||||
await self._login()
|
access_token: str = await self._login()
|
||||||
# store our auth token inside the cookie
|
# store the auth token inside the cookie
|
||||||
cookie["auth-token"] = cast(str, self._access_token)
|
cookie["auth-token"] = access_token
|
||||||
elif self._access_token is None:
|
elif self._access_token is None:
|
||||||
# have cookie - get our access token
|
# have cookie - get our access token
|
||||||
self._access_token = cookie["auth-token"].value
|
access_token = cookie["auth-token"].value
|
||||||
logger.debug("Restoring session from cookie")
|
logger.debug("Restoring session from cookie")
|
||||||
# validate our access token, by obtaining user_id
|
# store the auth token within the application
|
||||||
|
self._access_token = access_token
|
||||||
|
# validate the auth token, by obtaining user_id
|
||||||
async with self.request(
|
async with self.request(
|
||||||
"GET",
|
"GET",
|
||||||
"https://id.twitch.tv/oauth2/validate",
|
"https://id.twitch.tv/oauth2/validate",
|
||||||
@@ -856,6 +858,7 @@ class Twitch:
|
|||||||
# update our cookie and save it
|
# update our cookie and save it
|
||||||
jar.update_cookies(cookie, url)
|
jar.update_cookies(cookie, url)
|
||||||
jar.save(COOKIES_PATH)
|
jar.save(COOKIES_PATH)
|
||||||
|
return (self._access_token, self._user_id)
|
||||||
|
|
||||||
@asynccontextmanager
|
@asynccontextmanager
|
||||||
async def request(
|
async def request(
|
||||||
@@ -901,13 +904,13 @@ class Twitch:
|
|||||||
|
|
||||||
async def gql_request(self, op: GQLOperation) -> JsonType:
|
async def gql_request(self, op: GQLOperation) -> JsonType:
|
||||||
gql_logger.debug(f"GQL Request: {op}")
|
gql_logger.debug(f"GQL Request: {op}")
|
||||||
await self.check_login()
|
access_token, user_id = await self.check_login()
|
||||||
async with self.request(
|
async with self.request(
|
||||||
"POST",
|
"POST",
|
||||||
"https://gql.twitch.tv/gql",
|
"https://gql.twitch.tv/gql",
|
||||||
json=op,
|
json=op,
|
||||||
headers={
|
headers={
|
||||||
"Authorization": f"OAuth {self._access_token}",
|
"Authorization": f"OAuth {access_token}",
|
||||||
"Client-Id": CLIENT_ID,
|
"Client-Id": CLIENT_ID,
|
||||||
}
|
}
|
||||||
) as response:
|
) as response:
|
||||||
|
|||||||
+3
-3
@@ -200,7 +200,7 @@ class Websocket:
|
|||||||
# nothing to do
|
# nothing to do
|
||||||
return
|
return
|
||||||
self._topics_changed.clear()
|
self._topics_changed.clear()
|
||||||
await self._twitch.check_login()
|
access_token, user_id = await self._twitch.check_login()
|
||||||
current: set[WebsocketTopic] = set(self.topics.values())
|
current: set[WebsocketTopic] = set(self.topics.values())
|
||||||
# handle removed topics
|
# handle removed topics
|
||||||
removed = self._submitted.difference(current)
|
removed = self._submitted.difference(current)
|
||||||
@@ -212,7 +212,7 @@ class Websocket:
|
|||||||
"type": "UNLISTEN",
|
"type": "UNLISTEN",
|
||||||
"data": {
|
"data": {
|
||||||
"topics": topics_list,
|
"topics": topics_list,
|
||||||
"auth_token": self._twitch._access_token,
|
"auth_token": access_token,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -227,7 +227,7 @@ class Websocket:
|
|||||||
"type": "LISTEN",
|
"type": "LISTEN",
|
||||||
"data": {
|
"data": {
|
||||||
"topics": topics_list,
|
"topics": topics_list,
|
||||||
"auth_token": self._twitch._access_token,
|
"auth_token": access_token,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in new issue
Block a user