Fix claim bonus, insert emoji in logger

This commit is contained in:
Alessandro Maggio
2021-01-13 13:09:53 +01:00
parent 2085118198
commit cbac5db4b6
4 changed files with 20 additions and 18 deletions

View File

@@ -18,7 +18,6 @@ class TwitchChannelPointsMiner:
def __init__(
self,
username: str,
password: str = None,
predictions: bool = True,
raid: bool = True,
):
@@ -40,13 +39,14 @@ class TwitchChannelPointsMiner:
try:
channel_id = self.twitch.get_channel_id(streamer_username)
streamer = Streamer(streamer_username, channel_id)
self.twitch.check_streamer_online(streamer)
self.twitch.load_channel_points_context(streamer)
self.streamers.append(streamer)
logger.info(streamer.__repr__())
except StreamerDoesNotExistException:
logger.info(f"Streamer {streamer_username} does not exist")
logger.info(f"😞 Streamer {streamer_username} does not exist")
for streamer in self.streamers:
self.twitch.load_channel_points_context(streamer)
self.twitch.check_streamer_online(streamer)
# logger.info(streamer)
self.minute_watcher_thread = threading.Thread(
target=self.twitch.send_minute_watched_events, args=(self.streamers,)

View File

@@ -1,4 +1,7 @@
import time
import logging
logger = logging.getLogger(__name__)
class Streamer:
@@ -20,12 +23,14 @@ class Streamer:
self.char_url = f"https://www.twitch.tv/popout/{self.username}/chat?popout="
def __repr__(self):
return f"Streamer(username={self.username}, channel_id={self.channel_id}, is_online={self.is_online}, online_at={self.online_at}, offline_at={self.offline_at}, channel_points={self.channel_points})"
return f"Streamer(username={self.username}, channel_id={self.channel_id}, channel_points={self.channel_points})"
def set_offline(self):
self.offline_at = time.time()
self.is_online = False
logger.info(f"😴 {self} is Offline!")
def set_online(self):
self.online_at = time.time()
self.is_online = True
logger.info(f"🥳 {self} is Online!")

View File

@@ -108,14 +108,13 @@ class Twitch:
if streamer.is_online is False:
try:
self.update_minute_watched_event_request(streamer)
streamer.set_online()
except StreamerIsOfflineException:
streamer.set_offline()
else:
logger.info(f"{streamer.username} is live!")
streamer.set_online()
def claim_channel_points_bonus(self, streamer, claim_id):
logger.info(f"Claiming the bonus for {streamer.username}!")
logger.info(f"🎁 Claiming the bonus for {streamer.username}!")
json_data = {
"operationName": "ClaimCommunityPoints",
"variables": {
@@ -149,12 +148,10 @@ class Twitch:
"communityPoints"
]
streamer.channel_points = community_points["balance"]
logger.info(
f"{community_points['balance']} channel points for {streamer.username}!"
)
# logger.info(f"{streamer.channel_points} channel points for {streamer.username}!")
if community_points["availableClaim"] is not None:
self.claim_channel_points_bonus(
streamer.username, community_points["availableClaim"]["id"]
streamer, community_points["availableClaim"]["id"]
)
def send_minute_watched_events(self, streamers):
@@ -215,5 +212,5 @@ class Twitch:
)
logger.info(
f"Joining raid from {streamer.username} to {raid.target_login}!"
f"⚔️ Joining raid from {streamer.username} to {raid.target_login}!"
)

View File

@@ -112,14 +112,14 @@ class WebSocketsPool:
if message_type == "points-earned":
streamer_index = get_streamer_index(ws.streamers, message_data["channel_id"])
earned = message_data["point_gain"]["total_points"]
balance = message_data["balance"]["balance"]
ws.streamers[streamer_index].channel_points = message_data["balance"]["balance"]
logger.info(
f"+{earned}{balance} channel points for {ws.streamers[streamer_index]}! Reason: {message_data['point_gain']['reason_code']}."
f"🚀 +{earned}{ws.streamers[streamer_index]} - Reason: {message_data['point_gain']['reason_code']}."
)
elif message_type == "claim-available":
streamer_index = get_streamer_index(ws.streamers, message_data["claim"]["channel_id"])
ws.twitch.claim_channel_points_bonus(
ws.streamers[streamer_index].username, message_data["claim"]["id"]
ws.streamers[streamer_index], message_data["claim"]["id"]
)
elif topic == "video-playback-by-id":