Latest user agent, cleanup comments and docstrings;

ONLINE_DELAY: 60s -> 120s
This commit is contained in:
DevilXD committed 2022-01-12 12:11:04 +01:00
1 parent cab3c584fb
commit a91644d6de
2 files changed
+27 -13

No files matched your search

+25 -11
View File
@@ -4,7 +4,6 @@ import re
import json import json
import asyncio import asyncio
import logging import logging
from time import time
from base64 import b64encode from base64 import b64encode
from datetime import datetime, timezone from datetime import datetime, timezone
from typing import Any, Optional, TYPE_CHECKING from typing import Any, Optional, TYPE_CHECKING
@@ -97,7 +96,9 @@ class Channel:
@property @property
def iid(self) -> str: def iid(self) -> str:
# this is responsible for the ID/Key of the columns inside channel list """
Returns a string to be used as ID/key of the columns inside channel list.
"""
return str(self.id) return str(self.id)
@property @property
@@ -193,6 +194,10 @@ class Channel:
return True return True
async def _online_delay(self): async def _online_delay(self):
"""
The 'stream-up' event is sent before the stream actually goes online,
so just wait a bit and check if it's actually online by then.
"""
self.display() self.display()
await asyncio.sleep(ONLINE_DELAY.total_seconds()) await asyncio.sleep(ONLINE_DELAY.total_seconds())
await self.check_online() await self.check_online()
@@ -200,24 +205,34 @@ class Channel:
self.display() self.display()
def set_online(self): def set_online(self):
"""
Sets the channel status to OFFLINE.
This is called externally, if we receive an event about this happening.
"""
if self.online or self.pending_online: if self.online or self.pending_online:
# we're already online, or about to be # we're already online, or about to be
return return
# stream-up is sent before the stream actually goes online, so just wait a bit
# and check if it's actually online by then
self._pending_stream_up = asyncio.create_task(self._online_delay()) self._pending_stream_up = asyncio.create_task(self._online_delay())
# display is called from within the task # display is called from within the task
def set_offline(self): def set_offline(self):
# to be called externally, if we receive an event about this happening """
Sets the channel status to OFFLINE.
This is called externally, if we receive an event about this happening.
"""
if self._pending_stream_up is not None: if self._pending_stream_up is not None:
self._pending_stream_up.cancel() self._pending_stream_up.cancel()
self._pending_stream_up = None self._pending_stream_up = None
self._stream = None if self.online:
self.display() self._stream = None
self.display()
async def claim_bonus(self): async def claim_bonus(self):
# this also fills out the 'points' attribute """
This claims bonus points if they're available, and fills out the 'points' attribute.
"""
response = await self._twitch.gql_request( response = await self._twitch.gql_request(
GQL_OPERATIONS["ChannelPointsContext"].with_variables({"channelLogin": self.name}) GQL_OPERATIONS["ChannelPointsContext"].with_variables({"channelLogin": self.name})
) )
@@ -230,8 +245,8 @@ class Channel:
await self._twitch.claim_points(channel_data["id"], claim_available["id"]) await self._twitch.claim_points(channel_data["id"], claim_available["id"])
logger.info("Claimed bonus points") logger.info("Claimed bonus points")
else: else:
# calling claim_points is going to refresh the display, so if we're not calling it, # calling 'claim_points' is going to refresh the display via the websocket payload,
# we need to do it ourselves # so if we're not calling it, we need to do it ourselves
self.display() self.display()
def _encode_payload(self): def _encode_payload(self):
@@ -260,7 +275,6 @@ class Channel:
if self._spade_url is None: if self._spade_url is None:
self._spade_url = await self.get_spade_url() self._spade_url = await self.get_spade_url()
logger.debug(f"Sending minute-watched to {self.name}") logger.debug(f"Sending minute-watched to {self.name}")
self._twitch._last_watch = time()
async with self._twitch._session.post( async with self._twitch._session.post(
self._spade_url, data=self._encode_payload() self._spade_url, data=self._encode_payload()
) as response: ) as response:
+2 -2
View File
@@ -21,7 +21,7 @@ GQL_URL = "https://gql.twitch.tv/gql"
CLIENT_ID = "kimne78kx3ncx6brgo4mv6wki5h1ko" CLIENT_ID = "kimne78kx3ncx6brgo4mv6wki5h1ko"
USER_AGENT = ( USER_AGENT = (
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) " "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/96.0.4664.45 Safari/537.36" "Chrome/97.0.4692.71 Safari/537.36"
) )
# Paths # Paths
LOG_PATH = "log.txt" LOG_PATH = "log.txt"
@@ -30,7 +30,7 @@ SETTINGS_PATH = "settings.json"
# Intervals and Delays # Intervals and Delays
PING_INTERVAL = timedelta(minutes=3) PING_INTERVAL = timedelta(minutes=3)
PING_TIMEOUT = timedelta(seconds=10) PING_TIMEOUT = timedelta(seconds=10)
ONLINE_DELAY = timedelta(seconds=60) ONLINE_DELAY = timedelta(seconds=120)
WATCH_INTERVAL = timedelta(seconds=58.8) WATCH_INTERVAL = timedelta(seconds=58.8)
# Tags # Tags
DROPS_ENABLED_TAG = "c2542d6d-cd10-4532-919b-3d19f30a768b" DROPS_ENABLED_TAG = "c2542d6d-cd10-4532-919b-3d19f30a768b"