Fix the possibility of stream_data being None
This commit is contained in:
1 parent
b0007eaab2
commit
32f475d7ed
1 file changed
+9
-6
+9
-6
@@ -212,17 +212,20 @@ class Channel:
|
|||||||
return match.group(1)
|
return match.group(1)
|
||||||
|
|
||||||
async def get_stream(self) -> Optional[Stream]:
|
async def get_stream(self) -> Optional[Stream]:
|
||||||
response = await self._twitch.gql_request(
|
response: Optional[JsonType] = await self._twitch.gql_request(
|
||||||
GQL_OPERATIONS["GetStreamInfo"].with_variables({"channel": self._login})
|
GQL_OPERATIONS["GetStreamInfo"].with_variables({"channel": self._login})
|
||||||
)
|
)
|
||||||
if response:
|
if not response:
|
||||||
stream_data = response["data"]["user"]
|
return None
|
||||||
# fill channel_id and display name
|
stream_data: Optional[JsonType] = response["data"]["user"]
|
||||||
|
if not stream_data:
|
||||||
|
return None
|
||||||
|
# fill in channel_id and display name
|
||||||
self.id = int(stream_data["id"])
|
self.id = int(stream_data["id"])
|
||||||
self._display_name = stream_data["displayName"]
|
self._display_name = stream_data["displayName"]
|
||||||
if stream_data["stream"]:
|
if not stream_data["stream"]:
|
||||||
return Stream(self, stream_data)
|
|
||||||
return None
|
return None
|
||||||
|
return Stream(self, stream_data)
|
||||||
|
|
||||||
async def check_online(self) -> bool:
|
async def check_online(self) -> bool:
|
||||||
stream = await self.get_stream()
|
stream = await self.get_stream()
|
||||||
|
|||||||
Reference in new issue
Block a user