Implement "special games" game check for badge handling
This commit is contained in:
1 parent
7ad84d5b5f
commit
165f9eccb3
3 files changed
+21
-9
No files matched your search
+3
-1
@@ -455,10 +455,12 @@ class DropsCampaign:
|
||||
channel is None or ( # channel isn't specified,
|
||||
# or there's no ACL, or the channel is in the ACL
|
||||
(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 (
|
||||
ignore_channel_status
|
||||
or channel.game is not None and channel.game == self.game
|
||||
or self.game.is_special_events()
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
@@ -981,16 +981,21 @@ class Twitch:
|
||||
"""
|
||||
Determines if the given channel qualifies as a watching candidate.
|
||||
"""
|
||||
if not self.wanted_games:
|
||||
return False
|
||||
# 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:
|
||||
# exit early if stream is offline
|
||||
if not channel.online:
|
||||
return False
|
||||
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 False
|
||||
|
||||
|
||||
@@ -402,6 +402,8 @@ class AwaitableValue(Generic[_T]):
|
||||
|
||||
|
||||
class Game:
|
||||
SPECIAL_EVENTS_GAME_ID: int = 509663
|
||||
|
||||
def __init__(self, data: JsonType):
|
||||
self.id: int = int(data["id"])
|
||||
self.name: str = data.get("displayName") or data["name"]
|
||||
@@ -434,3 +436,6 @@ class Game:
|
||||
# strip and collapse dashes
|
||||
slug_text = re.sub(r'-{2,}', '-', slug_text.strip('-'))
|
||||
return slug_text
|
||||
|
||||
def is_special_events(self) -> bool:
|
||||
return self.id == self.SPECIAL_EVENTS_GAME_ID
|
||||
Reference in new issue
Block a user