From ceb9959abd706874dd72ee7521beb6050189ec4c Mon Sep 17 00:00:00 2001 From: DevilXD <4180725+DevilXD@users.noreply.github.com> Date: Thu, 1 May 2025 17:41:38 +0200 Subject: [PATCH] Fix an issue with the drop claim operation having no notifications --- inventory.py | 16 ++++++++++++++++ twitch.py | 13 +------------ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/inventory.py b/inventory.py index e572f8a..6493995 100644 --- a/inventory.py +++ b/inventory.py @@ -2,12 +2,14 @@ from __future__ import annotations import re import math +import logging from enum import Enum from itertools import chain from typing import TYPE_CHECKING from functools import cached_property from datetime import datetime, timedelta, timezone +from translate import _ from channel import Channel from exceptions import GQLException from constants import GQL_OPERATIONS, URLType @@ -21,6 +23,7 @@ if TYPE_CHECKING: from gui import GUIManager, InventoryOverview +logger = logging.getLogger("TwitchDrops") DIMS_PATTERN = re.compile(r'-\d+x\d+(?=\.(?:jpg|png|gif)$)', re.I) @@ -162,6 +165,19 @@ class BaseDrop: # notify the campaign about claiming # this will cause it to call our _on_claim, so no need to call it ourselves here 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 async def _claim(self) -> bool: diff --git a/twitch.py b/twitch.py index c62eff8..ce6b466 100644 --- a/twitch.py +++ b/twitch.py @@ -1146,19 +1146,8 @@ class Twitch: return drop.update_claim(message["data"]["drop_instance_id"]) campaign = drop.campaign - mined = await drop.claim() + await drop.claim() 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 # by re-sending the watch payload. We can test for it by fetching the current drop # via GQL, and then comparing drop IDs.