Skip to content

Commit

Permalink
Merge pull request #191 from rdavydov/moments
Browse files Browse the repository at this point in the history
Moments
  • Loading branch information
rdavydov authored Mar 8, 2023
2 parents 0004491 + 8058989 commit 6bf09b8
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ twitch_miner = TwitchChannelPointsMiner(
make_predictions=True, # If you want to Bet / Make prediction
follow_raid=True, # Follow raid to obtain more points
claim_drops=True, # We can't filter rewards base on stream. Set to False for skip viewing counter increase and you will never obtain a drop reward from this script. Issue #21
claim_moments=True, # If set to True, https://help.twitch.tv/s/article/moments will be claimed when available
watch_streak=True, # If a streamer go online change the priority of streamers array and catch the watch screak. Issue #11
chat=ChatPresence.ONLINE, # Join irc chat to increase watch-time [ALWAYS, NEVER, ONLINE, OFFLINE]
bet=BetSettings(
Expand Down Expand Up @@ -514,6 +515,7 @@ Discord(
- `BET_FAILED`
- `BET_START`
- `BONUS_CLAIM`
- `MOMENT_CLAIM`
- `JOIN_RAID`
- `DROP_CLAIM`
- `DROP_STATUS`
Expand All @@ -524,6 +526,7 @@ Discord(
| `make_predictions` | bool | True | Choose if you want to make predictions / bet or not |
| `follow_raid` | bool | True | Choose if you want to follow raid +250 points |
| `claim_drops` | bool | True | If this value is True, the script will increase the watch-time for the current game. With this, you can claim the drops from Twitch Inventory [#21](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/issues/21) |
| `claim_moments` | bool | True | If set to True, [moments](https://help.twitch.tv/s/article/moments) will be claimed when available |
| `watch_streak` | bool | True | Choose if you want to change a priority for these streamers and try to catch the Watch Streak event [#11](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/issues/11) |
| `bet` | BetSettings | | Rules to follow for the bet |
| `chat` | ChatPresence | ONLINE | Join IRC-Chat to appear online in chat and attempt to get StreamElements channel points and increase view-time [#47](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/issues/47) |
Expand Down
6 changes: 6 additions & 0 deletions TwitchChannelPointsMiner/TwitchChannelPointsMiner.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,12 @@ def run(
streamer=streamer)
)

if streamer.settings.claim_moments is True:
self.ws_pool.submit(
PubsubTopic("community-moments-channel-v1",
streamer=streamer)
)

refresh_context = time.time()
while self.running:
time.sleep(random.uniform(20, 60))
Expand Down
1 change: 1 addition & 0 deletions TwitchChannelPointsMiner/classes/Settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Events(Enum):
BET_FAILED = auto()
BET_START = auto()
BONUS_CLAIM = auto()
MOMENT_CLAIM = auto()
JOIN_RAID = auto()
DROP_CLAIM = auto()
DROP_STATUS = auto()
Expand Down
15 changes: 15 additions & 0 deletions TwitchChannelPointsMiner/classes/Twitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,21 @@ def claim_bonus(self, streamer, claim_id):
}
self.post_gql_request(json_data)

# === MOMENTS === #
def claim_moment(self, streamer, moment_id):
if Settings.logger.less is False:
logger.info(
f"Claiming the moment for {streamer}!",
extra={"emoji": ":video_camera:",
"event": Events.MOMENT_CLAIM},
)

json_data = copy.deepcopy(GQLOperations.CommunityMomentCallout_Claim)
json_data["variables"] = {
"input": {"momentID": moment_id}
}
self.post_gql_request(json_data)

# === CAMPAIGNS / DROPS / INVENTORY === #
def __get_campaign_ids_from_streamer(self, streamer):
json_data = copy.deepcopy(
Expand Down
7 changes: 7 additions & 0 deletions TwitchChannelPointsMiner/classes/WebSocketsPool.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,13 @@ def on_message(ws, message):
ws.twitch.update_raid(
ws.streamers[streamer_index], raid)

elif message.topic == "community-moments-channel-v1":
if message.type == "active":
ws.twitch.claim_moment(
ws.streamers[streamer_index],
message.data["moment_id"]
)

elif message.topic == "predictions-channel-v1":

event_dict = message.data["event"]
Expand Down
9 changes: 7 additions & 2 deletions TwitchChannelPointsMiner/classes/entities/Streamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class StreamerSettings(object):
"make_predictions",
"follow_raid",
"claim_drops",
"claim_moments",
"watch_streak",
"bet",
"chat",
Expand All @@ -30,13 +31,15 @@ def __init__(
make_predictions: bool = None,
follow_raid: bool = None,
claim_drops: bool = None,
claim_moments: bool = None,
watch_streak: bool = None,
bet: BetSettings = None,
chat: ChatPresence = None,
):
self.make_predictions = make_predictions
self.follow_raid = follow_raid
self.claim_drops = claim_drops
self.claim_moments = claim_moments
self.watch_streak = watch_streak
self.bet = bet
self.chat = chat
Expand All @@ -46,6 +49,7 @@ def default(self):
"make_predictions",
"follow_raid",
"claim_drops",
"claim_moments",
"watch_streak",
]:
if getattr(self, name) is None:
Expand All @@ -56,7 +60,7 @@ def default(self):
self.chat = ChatPresence.ONLINE

def __repr__(self):
return f"BetSettings(make_predictions={self.make_predictions}, follow_raid={self.follow_raid}, claim_drops={self.claim_drops}, watch_streak={self.watch_streak}, bet={self.bet}, chat={self.chat})"
return f"BetSettings(make_predictions={self.make_predictions}, follow_raid={self.follow_raid}, claim_drops={self.claim_drops}, claim_moments={self.claim_moments}, watch_streak={self.watch_streak}, bet={self.bet}, chat={self.chat})"


class Streamer(object):
Expand Down Expand Up @@ -233,7 +237,8 @@ def __save_json(self, key, data={}, event_type="Watch"):

fname = os.path.join(Settings.analytics_path, f"{self.username}.json")
with self.mutex:
json_data = json.load(open(fname, "r")) if os.path.isfile(fname) else {}
json_data = json.load(
open(fname, "r")) if os.path.isfile(fname) else {}
if key not in json_data:
json_data[key] = []

Expand Down
9 changes: 9 additions & 0 deletions TwitchChannelPointsMiner/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ class GQLOperations:
}
},
}
CommunityMomentCallout_Claim = {
"operationName": "CommunityMomentCallout_Claim",
"extensions": {
"persistedQuery": {
"version": 1,
"sha256Hash": "e2d67415aead910f7f9ceb45a77b750a1e1d9622c936d832328a0689e054db62",
}
},
}
DropsPage_ClaimDropRewards = {
"operationName": "DropsPage_ClaimDropRewards",
"extensions": {
Expand Down
1 change: 1 addition & 0 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
make_predictions=True, # If you want to Bet / Make prediction
follow_raid=True, # Follow raid to obtain more points
claim_drops=True, # We can't filter rewards base on stream. Set to False for skip viewing counter increase and you will never obtain a drop reward from this script. Issue #21
claim_moments=True, # If set to True, https://help.twitch.tv/s/article/moments will be claimed when available
watch_streak=True, # If a streamer go online change the priority of streamers array and catch the watch screak. Issue #11
chat=ChatPresence.ONLINE, # Join irc chat to increase watch-time [ALWAYS, NEVER, ONLINE, OFFLINE]
bet=BetSettings(
Expand Down

0 comments on commit 6bf09b8

Please sign in to comment.