Fix an issue with the drop claim operation having no notifications
This commit is contained in:
1 parent
240ba23b0c
commit
ceb9959abd
2 files changed
+17
-12
No files matched your search
@@ -2,12 +2,14 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import re
|
import re
|
||||||
import math
|
import math
|
||||||
|
import logging
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
from functools import cached_property
|
from functools import cached_property
|
||||||
from datetime import datetime, timedelta, timezone
|
from datetime import datetime, timedelta, timezone
|
||||||
|
|
||||||
|
from translate import _
|
||||||
from channel import Channel
|
from channel import Channel
|
||||||
from exceptions import GQLException
|
from exceptions import GQLException
|
||||||
from constants import GQL_OPERATIONS, URLType
|
from constants import GQL_OPERATIONS, URLType
|
||||||
@@ -21,6 +23,7 @@ if TYPE_CHECKING:
|
|||||||
from gui import GUIManager, InventoryOverview
|
from gui import GUIManager, InventoryOverview
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger("TwitchDrops")
|
||||||
DIMS_PATTERN = re.compile(r'-\d+x\d+(?=\.(?:jpg|png|gif)$)', re.I)
|
DIMS_PATTERN = re.compile(r'-\d+x\d+(?=\.(?:jpg|png|gif)$)', re.I)
|
||||||
|
|
||||||
|
|
||||||
@@ -162,6 +165,19 @@ class BaseDrop:
|
|||||||
# notify the campaign about claiming
|
# notify the campaign about claiming
|
||||||
# this will cause it to call our _on_claim, so no need to call it ourselves here
|
# this will cause it to call our _on_claim, so no need to call it ourselves here
|
||||||
self.campaign._on_claim()
|
self.campaign._on_claim()
|
||||||
|
claim_text = (
|
||||||
|
f"{self.campaign.game.name}\n"
|
||||||
|
f"{self.rewards_text()} "
|
||||||
|
f"({self.campaign.claimed_drops}/{self.campaign.total_drops})"
|
||||||
|
)
|
||||||
|
# two different claim texts, becase a new line after the game name
|
||||||
|
# looks ugly in the output window - replace it with a space
|
||||||
|
self._twitch.print(
|
||||||
|
_("status", "claimed_drop").format(drop=claim_text.replace('\n', ' '))
|
||||||
|
)
|
||||||
|
self._twitch.gui.tray.notify(claim_text, _("gui", "tray", "notification_title"))
|
||||||
|
else:
|
||||||
|
logger.error(f"Drop claim has potentially failed! Drop ID: {self.id}")
|
||||||
return result
|
return result
|
||||||
|
|
||||||
async def _claim(self) -> bool:
|
async def _claim(self) -> bool:
|
||||||
|
|||||||
@@ -1146,19 +1146,8 @@ class Twitch:
|
|||||||
return
|
return
|
||||||
drop.update_claim(message["data"]["drop_instance_id"])
|
drop.update_claim(message["data"]["drop_instance_id"])
|
||||||
campaign = drop.campaign
|
campaign = drop.campaign
|
||||||
mined = await drop.claim()
|
await drop.claim()
|
||||||
drop.display()
|
drop.display()
|
||||||
if mined:
|
|
||||||
claim_text = (
|
|
||||||
f"{campaign.game.name}\n"
|
|
||||||
f"{drop.rewards_text()} ({campaign.claimed_drops}/{campaign.total_drops})"
|
|
||||||
)
|
|
||||||
# two different claim texts, becase a new line after the game name
|
|
||||||
# looks ugly in the output window - replace it with a space
|
|
||||||
self.print(_("status", "claimed_drop").format(drop=claim_text.replace('\n', ' ')))
|
|
||||||
self.gui.tray.notify(claim_text, _("gui", "tray", "notification_title"))
|
|
||||||
else:
|
|
||||||
logger.error(f"Drop claim has potentially failed! Drop ID: {drop_id}")
|
|
||||||
# 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
|
||||||
# via GQL, and then comparing drop IDs.
|
# via GQL, and then comparing drop IDs.
|
||||||
|
|||||||
Reference in new issue
Block a user