Make IDLE able to switch to mining if a channel comes online
This commit is contained in:
1 parent
2c6ee2939e
commit
4b97b26630
1 file changed
+24
-14
@@ -274,12 +274,14 @@ class Twitch:
|
|||||||
live_streams: List[Channel] = await self.get_live_streams()
|
live_streams: List[Channel] = await self.get_live_streams()
|
||||||
for channel in live_streams:
|
for channel in live_streams:
|
||||||
new_channels.add(channel)
|
new_channels.add(channel)
|
||||||
if any(self.can_watch(channel) for channel in new_channels):
|
for channel in new_channels:
|
||||||
# there are streams we can watch, so let's pre-display the active drop
|
if self.can_watch(channel):
|
||||||
# again, but this time with a substracted minute
|
# there are streams we can watch, so let's pre-display the active drop
|
||||||
active_drop = self.get_active_drop()
|
# again, but this time with a substracted minute
|
||||||
if active_drop is not None:
|
active_drop = self.get_active_drop(channel)
|
||||||
active_drop.display(countdown=False, subone=True)
|
if active_drop is not None:
|
||||||
|
active_drop.display(countdown=False, subone=True)
|
||||||
|
break
|
||||||
# add them, filtering out ones we already have
|
# add them, filtering out ones we already have
|
||||||
for channel in new_channels:
|
for channel in new_channels:
|
||||||
channel_id = channel.id
|
channel_id = channel.id
|
||||||
@@ -397,7 +399,9 @@ class Twitch:
|
|||||||
return (
|
return (
|
||||||
channel.online # steam online
|
channel.online # steam online
|
||||||
and channel.drops_enabled # drops are enabled
|
and channel.drops_enabled # drops are enabled
|
||||||
and channel.game == self.game # it's a game we've selected
|
# it's a game we've selected
|
||||||
|
and channel.game is not None
|
||||||
|
and channel.game == self.game
|
||||||
# we can progress any campaign for the selected game
|
# we can progress any campaign for the selected game
|
||||||
and any(
|
and any(
|
||||||
drop.can_earn(channel)
|
drop.can_earn(channel)
|
||||||
@@ -447,11 +451,17 @@ class Twitch:
|
|||||||
Called by a Channel when it goes online (after pending).
|
Called by a Channel when it goes online (after pending).
|
||||||
"""
|
"""
|
||||||
logger.debug(f"{channel.name} goes ONLINE")
|
logger.debug(f"{channel.name} goes ONLINE")
|
||||||
if channel.priority:
|
watching_channel = self.watching_channel.get_with_default(None)
|
||||||
wch = self.watching_channel.get_with_default(None)
|
if (
|
||||||
if wch is not None and not wch.priority and self.can_watch(channel):
|
(
|
||||||
self.gui.print(f"{channel.name} goes ONLINE, switching...")
|
self._state is State.IDLE # we're currently idle
|
||||||
self.watch(channel)
|
or channel.priority # or this channel has priority
|
||||||
|
and watching_channel is not None # and we're watching...
|
||||||
|
and not watching_channel.priority # ... a non-priority channel
|
||||||
|
) and self.can_watch(channel)
|
||||||
|
):
|
||||||
|
self.gui.print(f"{channel.name} goes ONLINE, switching...")
|
||||||
|
self.watch(channel)
|
||||||
|
|
||||||
def on_offline(self, channel: Channel):
|
def on_offline(self, channel: Channel):
|
||||||
"""
|
"""
|
||||||
@@ -815,10 +825,10 @@ class Twitch:
|
|||||||
return drop
|
return drop
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_active_drop(self) -> Optional[TimedDrop]:
|
def get_active_drop(self, channel: Optional[Channel] = None) -> Optional[TimedDrop]:
|
||||||
if self.game is None:
|
if self.game is None:
|
||||||
return None
|
return None
|
||||||
watching_channel = self.watching_channel.get_with_default(None)
|
watching_channel = self.watching_channel.get_with_default(channel)
|
||||||
drops = sorted(
|
drops = sorted(
|
||||||
(
|
(
|
||||||
drop
|
drop
|
||||||
|
|||||||
Reference in new issue
Block a user