Implement "special games" game check for badge handling

This commit is contained in:
DevilXD committed 2025-10-31 17:57:44 +01:00
1 parent 7ad84d5b5f
commit 165f9eccb3
3 files changed
+21 -9

No files matched your search

+3 -1
View File
@@ -455,10 +455,12 @@ class DropsCampaign:
channel is None or ( # channel isn't specified, channel is None or ( # channel isn't specified,
# or there's no ACL, or the channel is in the ACL # or there's no ACL, or the channel is in the ACL
(not self.allowed_channels or channel in self.allowed_channels) (not self.allowed_channels or channel in self.allowed_channels)
# and the channel is live and playing the campaign's game # and the channel is live and playing the campaign's game,
# or this campaign can be earned anywhere (special game)
and ( and (
ignore_channel_status ignore_channel_status
or channel.game is not None and channel.game == self.game or channel.game is not None and channel.game == self.game
or self.game.is_special_events()
) )
) )
) )
+13 -8
View File
@@ -981,16 +981,21 @@ class Twitch:
""" """
Determines if the given channel qualifies as a watching candidate. Determines if the given channel qualifies as a watching candidate.
""" """
if not self.wanted_games: # exit early if stream is offline
return False if not channel.online:
# exit early if stream is offline or drops aren't enabled
if not channel.online or not channel.drops_enabled:
return False
# check if we can progress any campaign for the played game
if channel.game is None or channel.game not in self.wanted_games:
return False return False
for campaign in self.inventory: for campaign in self.inventory:
if campaign.can_earn(channel): if (
campaign.can_earn(channel) # let the campaign do the "special games" check
and (
# limit watching to the games the user wants
channel.game is not None
and channel.drops_enabled
and channel.game in self.wanted_games
# let the campaign ignore all channel-related checks
or campaign.game.is_special_events()
)
):
return True return True
return False return False
+5
View File
@@ -402,6 +402,8 @@ class AwaitableValue(Generic[_T]):
class Game: class Game:
SPECIAL_EVENTS_GAME_ID: int = 509663
def __init__(self, data: JsonType): def __init__(self, data: JsonType):
self.id: int = int(data["id"]) self.id: int = int(data["id"])
self.name: str = data.get("displayName") or data["name"] self.name: str = data.get("displayName") or data["name"]
@@ -434,3 +436,6 @@ class Game:
# strip and collapse dashes # strip and collapse dashes
slug_text = re.sub(r'-{2,}', '-', slug_text.strip('-')) slug_text = re.sub(r'-{2,}', '-', slug_text.strip('-'))
return slug_text return slug_text
def is_special_events(self) -> bool:
return self.id == self.SPECIAL_EVENTS_GAME_ID