Skip to content

Commit

Permalink
Sync branch with master, fix conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
Tkd-Alex committed Feb 26, 2021
2 parents aaea73b + b8f6fd0 commit b034931
Show file tree
Hide file tree
Showing 8 changed files with 281 additions and 37 deletions.
77 changes: 61 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ If you have any issues or you want to contribute, you are welcome! But please be

## Main differences from the original repository:

- Improve the logging
- Improve the logging - Emoji, colors, file and soo on
- Final report with all the data
- Rewrite the entire code using classe instead of module with global variables
- Automatic download the follower's list and use it as input
Expand Down Expand Up @@ -172,8 +172,9 @@ pip install -r requirements.txt
# -*- coding: utf-8 -*-

import logging
from colorama import Fore
from TwitchChannelPointsMiner import TwitchChannelPointsMiner
from TwitchChannelPointsMiner.logger import LoggerSettings
from TwitchChannelPointsMiner.logger import LoggerSettings, ColorPalette
from TwitchChannelPointsMiner.classes.Settings import Priority
from TwitchChannelPointsMiner.classes.entities.Bet import Strategy, BetSettings, Condition, OutcomeKeys, FilterCondition
from TwitchChannelPointsMiner.classes.entities.Streamer import Streamer, StreamerSettings
Expand All @@ -192,7 +193,13 @@ twitch_miner = TwitchChannelPointsMiner(
console_level=logging.INFO, # Level of logs - use logging.DEBUG for more info)
file_level=logging.DEBUG, # Level of logs - If you think the log file it's too big, use logging.INFO
emoji=True, # On Windows, we have a problem printing emoji. Set to false if you have a problem
less=False # If you think that the logs are too verbose, set this to True
less=False, # If you think that the logs are too verbose, set this to True
colored=True, # If you want to print colored text
color_palette=ColorPalette( # You can also create a custom palette color (for the common message).
STREAMER_online="GREEN", # Don't worry about lower/upper case the script will be parse all the values.
streamer_offline="red", # Read more in README.md
BET_wiN=Fore.MAGENTA # Color allowed are: [BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET].
)
),
streamer_settings=StreamerSettings(
make_predictions=True, # If you want to Bet / Make prediction
Expand Down Expand Up @@ -273,21 +280,59 @@ Available values are the following:
You can combine all priority but keep in mind that use `ORDER` and `POINTS_ASCENDING` in the same settings doesn't make sense.

### LoggerSettings
| Key | Type | Default | Description |
|----------------- |----------------- |-------------------------------- |---------------------------------------------------------------------------------------------------------------------------- |
| `save` | bool | True | If you want to save logs in file (suggested) |
| `less` | bool | False | Reduce the logging format and message verbosity [#10](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/issues/10) |
| `console_level` | level | logging.INFO | Level of logs in terminal - Use logging.DEBUG for more helpful messages. |
| `file_level` | level | logging.DEBUG | Level of logs in file save - If you think the log file it's too big, use logging.INFO |
| `emoji` | bool | For Windows is False else True | On Windows, we have a problem printing emoji. Set to false if you have a problem |
| Key | Type | Default | Description |
|----------------- |----------------- |-------------------------------------------------------------------- |------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `save` | bool | True | If you want to save logs in file (suggested) |
| `less` | bool | False | Reduce the logging format and message verbosity [#10](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/issues/10) |
| `console_level` | level | logging.INFO | Level of logs in terminal - Use logging.DEBUG for more helpful messages. |
| `file_level` | level | logging.DEBUG | Level of logs in file save - If you think the log file it's too big, use logging.INFO |
| `emoji` | bool | For Windows is False else True | On Windows, we have a problem printing emoji. Set to false if you have a problem |
| `colored` | bool | True | If you want to print colored text [#45](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/issues/45) [#82](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/issues/82) |
| `color_palette` | ColorPalette | All messages are Fore.RESET except WIN and LOSE bet (GREEN and RED) | Create your custom color palette. Read more above. |

#### Color Palette
Now you can customize the color of the terminal message. We have created a default ColorPalette that provide all the message with `DEFAULT (RESET)` color and the `BET_WIN` and `BET_LOSE` message `GREEN` and `RED` respectively.
Currently you can only change the following types of messages:
- `STREAMER_ONLINE`
- `STREAMER_OFFLINE`
- `GAIN_FOR_RAID`
- `GAIN_FOR_CLAIM`
- `GAIN_FOR_WATCH`
- `BET_WIN`
- `BET_LOSE`
- `BET_REFUND`
- `BET_FILTERS`
- `BET_GENERAL`
- `BET_FAILED`
- `BET_START`

The colors allowed are all the Fore color from Colorama: `BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET.`
The script was developed to handle all the human error, lower-case upper case and more, but I want to suggest using the following code-style
```python
from colorama import Fore
ColorPalette(
"STREAMER_ONLINE" = Fore.GREEN,
"STREAMER_OFFLINE" = Fore.RED,
"GAIN_FOR_RAID" = Fore.YELLOW,
"GAIN_FOR_CLAIM" = Fore.YELLOW,
"GAIN_FOR_WATCH" = Fore.YELLOW,
"BET_WIN" = Fore.GREEN,
"BET_LOSE" = Fore.RED,
"BET_REFUND" = Fore.RESET,
"BET_FILTERS" = Fore.MAGENTA,
"BET_GENERAL" = Fore.BLUE,
"BET_FAILED" = Fore.RED,
)
```

### StreamerSettings
| Key | Type | Default | Description |
|-------------------- |------------- |-------------------------------- |--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `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 |
| Key | Type | Default | Description |
|-------------------- |------------- |-------------------------------- |---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `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 are able to claim the drops from Twitch Inventory [#21](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/issues/21) |
| `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 |
| `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 |
### BetSettings
| Key | Type | Default | Description |
|-------------------- |----------------- |--------- |--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
Expand Down
26 changes: 21 additions & 5 deletions TwitchChannelPointsMiner/classes/Twitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,23 +392,36 @@ def make_predictions(self, event):

logger.info(
f"Going to complete bet for {event}",
extra={"emoji": ":four_leaf_clover:"},
extra={
"emoji": ":four_leaf_clover:",
"color": Settings.logger.color_palette.BET_GENERAL,
},
)
if event.status == "ACTIVE":
skip, compared_value = event.bet.skip()
if skip is True:
logger.info(
f"Skip betting for the event {event}", extra={"emoji": ":pushpin:"}
f"Skip betting for the event {event}",
extra={
"emoji": ":pushpin:",
"color": Settings.logger.color_palette.BET_FILTERS,
},
)
logger.info(
f"Skip settings {event.bet.settings.filter_condition}, current value is: {compared_value}",
extra={"emoji": ":pushpin:"},
extra={
"emoji": ":pushpin:",
"color": Settings.logger.color_palette.BET_FILTERS,
},
)
else:
if decision["amount"] >= 10:
logger.info(
f"Place {_millify(decision['amount'])} channel points on: {event.bet.get_outcome(selector_index)}",
extra={"emoji": ":four_leaf_clover:"},
extra={
"emoji": ":four_leaf_clover:",
"color": Settings.logger.color_palette.BET_GENERAL,
},
)

json_data = copy.deepcopy(GQLOperations.MakePrediction)
Expand All @@ -424,7 +437,10 @@ def make_predictions(self, event):
else:
logger.info(
f"Oh no! The event is not active anymore! Current status: {event.status}",
extra={"emoji": ":disappointed_relieved:"},
extra={
"emoji": ":disappointed_relieved:",
"color": Settings.logger.color_palette.BET_FAILED,
},
)

def claim_bonus(self, streamer, claim_id):
Expand Down
22 changes: 17 additions & 5 deletions TwitchChannelPointsMiner/classes/WebSocketsPool.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
from TwitchChannelPointsMiner.classes.entities.EventPrediction import EventPrediction
from TwitchChannelPointsMiner.classes.entities.Message import Message
from TwitchChannelPointsMiner.classes.entities.Raid import Raid

# from TwitchChannelPointsMiner.classes.Exceptions import TimeBasedDropNotFound
from TwitchChannelPointsMiner.classes.Settings import Settings
from TwitchChannelPointsMiner.classes.TwitchWebSocket import TwitchWebSocket
from TwitchChannelPointsMiner.constants import WEBSOCKET
from TwitchChannelPointsMiner.utils import (
Expand Down Expand Up @@ -188,7 +187,12 @@ def on_message(ws, message):
reason_code = message.data["point_gain"]["reason_code"]
logger.info(
f"+{earned}{ws.streamers[streamer_index]} - Reason: {reason_code}.",
extra={"emoji": ":rocket:"},
extra={
"emoji": ":rocket:",
"color": Settings.logger.color_palette.get(
f"GAIN_FOR_{reason_code}"
),
},
)
ws.streamers[streamer_index].update_history(
reason_code, earned
Expand Down Expand Up @@ -274,7 +278,10 @@ def on_message(ws, message):

logger.info(
f"Place the bet after: {start_after}s for: {ws.events_predictions[event_id]}",
extra={"emoji": ":alarm_clock:"},
extra={
"emoji": ":alarm_clock:",
"color": Settings.logger.color_palette.BET_START,
},
)

elif (
Expand Down Expand Up @@ -325,7 +332,12 @@ def on_message(ws, message):
)
logger.info(
f"{ws.events_predictions[event_id]} - Result: {result_type}, {action}: {points_prefix}{_millify(points_gained)}",
extra={"emoji": ":bar_chart:"},
extra={
"emoji": ":bar_chart:",
"color": Settings.logger.color_palette.get(
f"BET_{result_type}"
),
},
)
ws.events_predictions[event_id].final_result = {
"type": event_result["type"],
Expand Down
16 changes: 14 additions & 2 deletions TwitchChannelPointsMiner/classes/entities/Streamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,27 @@ def set_offline(self):
self.offline_at = time.time()
self.is_online = False

logger.info(f"{self} is Offline!", extra={"emoji": ":sleeping:"})
logger.info(
f"{self} is Offline!",
extra={
"emoji": ":sleeping:",
"color": Settings.logger.color_palette.STREAMER_OFFLINE,
},
)

def set_online(self):
if self.is_online is False:
self.online_at = time.time()
self.is_online = True
self.stream.init_watch_streak()

logger.info(f"{self} is Online!", extra={"emoji": ":partying_face:"})
logger.info(
f"{self} is Online!",
extra={
"emoji": ":partying_face:",
"color": Settings.logger.color_palette.STREAMER_ONLINE,
},
)

def print_history(self):
return ", ".join(
Expand Down
Loading

0 comments on commit b034931

Please sign in to comment.