Change campaigns refresh every hour to channel cleanup;
Separate off GAMES_UPDATE from INVENTORY_FETCH
This commit is contained in:
1 parent
6b30f93f71
commit
cab3c584fb
2 files changed
+17
-15
No files matched your search
+3
-2
@@ -43,9 +43,10 @@ FORMATTER = logging.Formatter(
|
|||||||
|
|
||||||
class State(Enum):
|
class State(Enum):
|
||||||
INVENTORY_FETCH = auto()
|
INVENTORY_FETCH = auto()
|
||||||
|
GAMES_UPDATE = auto()
|
||||||
GAME_SELECT = auto()
|
GAME_SELECT = auto()
|
||||||
CHANNEL_FETCH = auto()
|
CHANNELS_FETCH = auto()
|
||||||
CHANNEL_CLEANUP = auto()
|
CHANNELS_CLEANUP = auto()
|
||||||
CHANNEL_SWITCH = auto()
|
CHANNEL_SWITCH = auto()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -206,18 +206,19 @@ class Twitch:
|
|||||||
self.change_state(State.INVENTORY_FETCH)
|
self.change_state(State.INVENTORY_FETCH)
|
||||||
while True:
|
while True:
|
||||||
if self._state is State.INVENTORY_FETCH:
|
if self._state is State.INVENTORY_FETCH:
|
||||||
# Claim the drops we can
|
|
||||||
await self.fetch_inventory()
|
await self.fetch_inventory()
|
||||||
|
self.change_state(State.GAMES_UPDATE)
|
||||||
|
elif self._state is State.GAMES_UPDATE:
|
||||||
|
# Figure out which games to watch, and claim the drops we can
|
||||||
games.clear()
|
games.clear()
|
||||||
for campaign in self.inventory:
|
for campaign in self.inventory:
|
||||||
if campaign.upcoming:
|
|
||||||
# we have no use in processing upcoming campaigns here
|
# we have no use in processing upcoming campaigns here
|
||||||
continue
|
if not campaign.upcoming:
|
||||||
for drop in campaign.timed_drops.values():
|
for drop in campaign.timed_drops.values():
|
||||||
if drop.can_earn and (game := campaign.game) not in games:
|
|
||||||
games.append(game)
|
|
||||||
if drop.can_claim:
|
if drop.can_claim:
|
||||||
await drop.claim()
|
await drop.claim()
|
||||||
|
if drop.can_earn and (game := campaign.game) not in games:
|
||||||
|
games.append(game)
|
||||||
self.change_state(State.GAME_SELECT)
|
self.change_state(State.GAME_SELECT)
|
||||||
elif self._state is State.GAME_SELECT:
|
elif self._state is State.GAME_SELECT:
|
||||||
# 'games' has all games we want to mine drops for
|
# 'games' has all games we want to mine drops for
|
||||||
@@ -233,8 +234,8 @@ class Twitch:
|
|||||||
active_drop = self.get_active_drop(selected_game)
|
active_drop = self.get_active_drop(selected_game)
|
||||||
if active_drop is not None:
|
if active_drop is not None:
|
||||||
active_drop.display(countdown=False)
|
active_drop.display(countdown=False)
|
||||||
self.change_state(State.CHANNEL_CLEANUP)
|
self.change_state(State.CHANNELS_CLEANUP)
|
||||||
elif self._state is State.CHANNEL_CLEANUP:
|
elif self._state is State.CHANNELS_CLEANUP:
|
||||||
# remove all channels that are offline,
|
# remove all channels that are offline,
|
||||||
# or aren't streaming the game we want anymore
|
# or aren't streaming the game we want anymore
|
||||||
to_remove = [
|
to_remove = [
|
||||||
@@ -250,8 +251,8 @@ class Twitch:
|
|||||||
del self.channels[channel.id]
|
del self.channels[channel.id]
|
||||||
channel.remove()
|
channel.remove()
|
||||||
self.gui.channels.shrink()
|
self.gui.channels.shrink()
|
||||||
self.change_state(State.CHANNEL_FETCH)
|
self.change_state(State.CHANNELS_FETCH)
|
||||||
elif self._state is State.CHANNEL_FETCH:
|
elif self._state is State.CHANNELS_FETCH:
|
||||||
if selected_game is None:
|
if selected_game is None:
|
||||||
self.change_state(State.GAME_SELECT)
|
self.change_state(State.GAME_SELECT)
|
||||||
else:
|
else:
|
||||||
@@ -305,7 +306,7 @@ class Twitch:
|
|||||||
self.gui.print("No suitable channel to watch.")
|
self.gui.print("No suitable channel to watch.")
|
||||||
# TODO: Figure out what to do here.
|
# TODO: Figure out what to do here.
|
||||||
return
|
return
|
||||||
self.change_state(State.CHANNEL_CLEANUP)
|
self.change_state(State.CHANNELS_CLEANUP)
|
||||||
await self._state_change.wait()
|
await self._state_change.wait()
|
||||||
|
|
||||||
async def _watch_loop(self) -> None:
|
async def _watch_loop(self) -> None:
|
||||||
@@ -355,8 +356,8 @@ class Twitch:
|
|||||||
# ensure every 30 minutes that we don't have unclaimed points bonus
|
# ensure every 30 minutes that we don't have unclaimed points bonus
|
||||||
await channel.claim_bonus()
|
await channel.claim_bonus()
|
||||||
if i % 60 == 0:
|
if i % 60 == 0:
|
||||||
# refresh inventory every hour
|
# cleanup channels every hour
|
||||||
self.change_state(State.INVENTORY_FETCH)
|
self.change_state(State.CHANNELS_CLEANUP)
|
||||||
i = (i + 1) % 3600
|
i = (i + 1) % 3600
|
||||||
self._watching_restart.clear()
|
self._watching_restart.clear()
|
||||||
try:
|
try:
|
||||||
@@ -443,7 +444,7 @@ class Twitch:
|
|||||||
else:
|
else:
|
||||||
logger.error(f"Drop claim failed! Drop ID: {drop_id}")
|
logger.error(f"Drop claim failed! Drop ID: {drop_id}")
|
||||||
if not mined or campaign.remaining_drops == 0:
|
if not mined or campaign.remaining_drops == 0:
|
||||||
self.change_state(State.INVENTORY_FETCH)
|
self.change_state(State.GAMES_UPDATE)
|
||||||
return
|
return
|
||||||
# About 4-20s after claiming the drop, next drop can be started
|
# About 4-20s after claiming the drop, next drop can be started
|
||||||
# by re-sending the watch payload. We can test for it by fetching the current drop
|
# by re-sending the watch payload. We can test for it by fetching the current drop
|
||||||
|
|||||||
Reference in new issue
Block a user