DevilXD / TwitchDropsMiner

An app that allows you to AFK mine timed Twitch drops, with automatic drop claiming and channel switching.
MIT License
1.71k stars 169 forks source link

Inventory availability method not verifying total_remaining_minutes #566

Closed jordyamc closed 2 weeks ago

jordyamc commented 1 month ago
@property
    def availability(self) -> float:
        if not self._base_can_earn():
            # this verifies "self.total_remaining_minutes > 0" and "now < self.ends_at"
            return math.inf
        now = datetime.now(timezone.utc)
        return ((self.ends_at - now).total_seconds() / 60) / self.total_remaining_minutes

It seems the method is not checking total_remaining_minutes

Traceback (most recent call last):
19:44:40:   File "main.py", line 155, in main
19:44:40:   File "twitch.py", line 587, in run
19:44:40:   File "twitch.py", line 662, in _run
19:44:40:   File "twitch.py", line 662, in <lambda>
19:44:40:   File "inventory.py", line 369, in availability
19:44:40:   File "inventory.py", line 369, in <genexpr>
19:44:40:   File "inventory.py", line 244, in availability
19:44:40: ZeroDivisionError: float division by zero
DevilXD commented 1 month ago

Hello,

Hmm. I've taken a look at the code, and it seems that the chain of calls is: TimedDrop.availability -> BaseDrop._base_can_earn -> TimedDrop._base_earn_conditions, which verifies that self.required_minutes > 0. However, availability checks self.total_remaining_minutes - the wording implies it's a different variable, required vs remaining. A drop with required_minutes > 0 and remaining_minutes <= 0 is any drop that has been finished mining, so these are possible.

I've reworked the availability method a bit, and it shouldn't cause an exception anymore. I haven't tested it though, but it should work: https://github.com/DevilXD/TwitchDropsMiner/commit/93d5d8750d9bdb5cc7749d755e9a75d659a8cb30

Please verify that everything works now.

DevilXD commented 2 weeks ago

I'm assuming that the fix worked, and this issue has been resolved by now.