diff --git a/channel.py b/channel.py index 469e277..97f5df9 100644 --- a/channel.py +++ b/channel.py @@ -17,6 +17,7 @@ from constants import JsonType, BASE_URL, GQL_OPERATIONS, ONLINE_DELAY, DROPS_EN if TYPE_CHECKING: from twitch import Twitch + from gui import ChannelList logger = logging.getLogger("TwitchDrops") @@ -52,6 +53,7 @@ class Stream: class Channel: def __init__(self, twitch: Twitch, data: JsonType, *, priority: bool = False): self._twitch: Twitch = twitch + self._gui_channels: ChannelList = twitch.gui.channels self.id: int = int(data["id"]) self._login: str = data["name"] self._display_name: Optional[str] = data.get("displayName") @@ -169,7 +171,6 @@ class Channel: def viewers(self, value: int): if self._stream is not None: self._stream.viewers = value - self.display() @property def drops_enabled(self) -> bool: @@ -178,13 +179,13 @@ class Channel: return False def display(self): - self._twitch.gui.channels.display(self) + self._gui_channels.display(self) def remove(self): if self._pending_stream_up is not None: self._pending_stream_up.cancel() self._pending_stream_up = None - self._twitch.gui.channels.remove(self) + self._gui_channels.remove(self) async def get_spade_url(self) -> str: """ diff --git a/inventory.py b/inventory.py index 6c8be02..0e003d8 100644 --- a/inventory.py +++ b/inventory.py @@ -10,6 +10,7 @@ from utils import timestamp, invalidate_cache, Game if TYPE_CHECKING: from twitch import Twitch + from gui import CampaignProgress class BaseDrop: @@ -62,7 +63,6 @@ class BaseDrop: return all(campaign.timed_drops[pid].is_claimed for pid in self._precondition_drops) def can_earn(self, channel: Optional[Channel] = None) -> bool: - allowed_channels = self.campaign.allowed_channels return ( self.preconditions # preconditions are met and not self.is_claimed # drop isn't already claimed @@ -70,7 +70,11 @@ class BaseDrop: # drop is within the active timeframe and self.starts_at <= datetime.now(timezone.utc) < self.ends_at # channel isn't specified, or there's no ACL, or the channel is in the ACL - and (channel is None or not allowed_channels or channel in allowed_channels) + and ( + channel is None + or not (allowed_channels := self.campaign.allowed_channels) + or channel in allowed_channels + ) ) @property @@ -127,6 +131,7 @@ class TimedDrop(BaseDrop): self, campaign: DropsCampaign, data: JsonType, claimed_benefits: Dict[str, datetime] ): super().__init__(campaign, data, claimed_benefits) + self._gui_progress: CampaignProgress = self._twitch.gui.progress self.current_minutes: int = 0 if "self" in data: self.current_minutes = data["self"]["currentMinutesWatched"] @@ -171,7 +176,7 @@ class TimedDrop(BaseDrop): self._on_minutes_changed() def display(self, *, countdown: bool = True, subone: bool = False): - self.campaign._twitch.gui.progress.display(self, countdown=countdown, subone=subone) + self._gui_progress.display(self, countdown=countdown, subone=subone) def bump_minutes(self): if self.current_minutes < self.required_minutes: diff --git a/twitch.py b/twitch.py index e8f5941..f9f3ff5 100644 --- a/twitch.py +++ b/twitch.py @@ -450,6 +450,7 @@ class Twitch: else: viewers = message["viewers"] channel.viewers = viewers + channel.display() # logger.debug(f"{channel.name} viewers: {viewers}") def on_online(self, channel: Channel):