Improve handling after claiming a drop
This commit is contained in:
1 parent
c1f4233111
commit
12da851800
1 file changed
+22
-10
@@ -356,6 +356,15 @@ class Twitch:
|
|||||||
self._watching_task = None
|
self._watching_task = None
|
||||||
self._watching_channel = None
|
self._watching_channel = None
|
||||||
|
|
||||||
|
def restart_watching(self, channel: Optional[Channel] = None):
|
||||||
|
# this forcibly re-sends the watching payload to the specified or currently watched channel
|
||||||
|
if channel is None:
|
||||||
|
channel = self._watching_channel
|
||||||
|
if channel is not None:
|
||||||
|
self.stop_watching()
|
||||||
|
self._last_watch = time() - 60
|
||||||
|
self.watch(channel)
|
||||||
|
|
||||||
async def process_stream_state(self, channel_id: int, message: JsonType):
|
async def process_stream_state(self, channel_id: int, message: JsonType):
|
||||||
msg_type = message["type"]
|
msg_type = message["type"]
|
||||||
channel = self.channels.get(channel_id)
|
channel = self.channels.get(channel_id)
|
||||||
@@ -408,18 +417,21 @@ 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 campaign.remaining_drops == 0:
|
if not mined or campaign.remaining_drops == 0:
|
||||||
self.change_state(State.INVENTORY_FETCH)
|
self.change_state(State.INVENTORY_FETCH)
|
||||||
return
|
return
|
||||||
# About 6s after claiming the drop, next drop can be started
|
# About 4-6s after claiming the drop, next drop can be started
|
||||||
# by resending the watch payload
|
# by re-sending the watch payload
|
||||||
await asyncio.sleep(6)
|
await asyncio.sleep(4)
|
||||||
# Force-restart the watch task to send the watch payload right away
|
for attempt in range(6):
|
||||||
channel = self._watching_channel
|
context = await self.gql_request(GQL_OPERATIONS["CurrentDrop"])
|
||||||
if channel is not None:
|
drop_data: JsonType = context["data"]["currentUser"]["dropCurrentSession"]
|
||||||
self.stop_watching()
|
with open("log.txt", 'a') as file:
|
||||||
self._last_watch = time() - 60
|
print(format(time(), ".6f"), attempt, drop_data["dropID"], file=file)
|
||||||
self.watch(channel)
|
if drop_data["dropID"] != drop.id:
|
||||||
|
self.restart_watching()
|
||||||
|
break
|
||||||
|
await asyncio.sleep(1)
|
||||||
return
|
return
|
||||||
assert msg_type == "drop-progress"
|
assert msg_type == "drop-progress"
|
||||||
if self._drop_update is None:
|
if self._drop_update is None:
|
||||||
|
|||||||
Reference in new issue
Block a user