From 8e264a465814bde398776184ce02ce0e64a9c8a9 Mon Sep 17 00:00:00 2001 From: Prograstinator <99142422+prograstinator@users.noreply.github.com> Date: Sun, 27 Feb 2022 00:39:15 +0100 Subject: [PATCH 01/22] Add Discord like Telegram Integrations --- README.md | 25 ++++++++++++++++++- .../classes/DiscordWebhook.py | 24 ++++++++++++++++++ TwitchChannelPointsMiner/classes/Telegram.py | 5 ++-- TwitchChannelPointsMiner/classes/Twitch.py | 7 ++++++ TwitchChannelPointsMiner/logger.py | 18 +++++++++++++ example.py | 8 +++++- 6 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 TwitchChannelPointsMiner/classes/DiscordWebhook.py diff --git a/README.md b/README.md index f5644ac..0a42f70 100644 --- a/README.md +++ b/README.md @@ -189,6 +189,7 @@ from colorama import Fore from TwitchChannelPointsMiner import TwitchChannelPointsMiner from TwitchChannelPointsMiner.logger import LoggerSettings, ColorPalette from TwitchChannelPointsMiner.classes.Telegram import Telegram +from TwitchChannelPointsMiner.classes.DiscordWebhook import Discord from TwitchChannelPointsMiner.classes.Settings import Priority, Events, FollowersOrder from TwitchChannelPointsMiner.classes.entities.Bet import Strategy, BetSettings, Condition, OutcomeKeys, FilterCondition, DelayMode from TwitchChannelPointsMiner.classes.entities.Streamer import Streamer, StreamerSettings @@ -219,7 +220,12 @@ twitch_miner = TwitchChannelPointsMiner( token="123456789:shfuihreuifheuifhiu34578347", # Telegram API token @BotFather events=[Events.STREAMER_ONLINE, Events.STREAMER_OFFLINE, "BET_LOSE"], # Only these events will be sent to the chat disable_notification=True, # Revoke the notification (sound/vibration) - ) + ), + + discord=Discord( + discord_webhook_api="https://discord.com/api/webhooks/0123456789/0a1B2c3D4e5F6g7H8i9J", #Discord Webhook URL + events=[Events.STREAMER_ONLINE, Events.STREAMER_OFFLINE, Events.BET_LOSE], # Only these events will be sent to the chat + ), ), streamer_settings=StreamerSettings( make_predictions=True, # If you want to Bet / Make prediction @@ -434,6 +440,23 @@ Telegram( ) ``` +#### Discord +If you want to reive log updates on Discord initiate a new Discord class, else leave omit this parameter or set as None +1. Go to the Server you want to recieve updates +2. Click "Edit Channel" +3. Click "Integrations" +4. Click "Webhooks" +5. Click "New Webhook" +6. Name it if you want +7. Click on "Copy Webhook URL" +```python +Discord( + discord_webhook_api="https://discord.com/api/webhooks/0123456789/0a1B2c3D4e5F6g7H8i9J", + events=[Events.STREAMER_ONLINE, Events.STREAMER_OFFLINE, Events.BET_LOSE], +) +``` + + #### Events - `STREAMER_ONLINE` - `STREAMER_OFFLINE` diff --git a/TwitchChannelPointsMiner/classes/DiscordWebhook.py b/TwitchChannelPointsMiner/classes/DiscordWebhook.py new file mode 100644 index 0000000..61582ce --- /dev/null +++ b/TwitchChannelPointsMiner/classes/DiscordWebhook.py @@ -0,0 +1,24 @@ +from textwrap import dedent + +import requests + +from TwitchChannelPointsMiner.classes.Settings import Events + + +class Discord(object): + __slots__ = ["discord_webhook_api", "events"] + + def __init__(self, discord_webhook_api: str, events: list): + self.discord_webhook_api = discord_webhook_api + self.events = [str(e) for e in events] + + def send(self, message: str, event: Events) -> None: + if str(event) in self.events: + requests.post( + url=self.discord_webhook_api, + data={ + "content": dedent(message), + "username": "Twitch Channel Points Miner", + "avatar_url": "https://i.imgur.com/X9fEkhT.png", + }, + ) diff --git a/TwitchChannelPointsMiner/classes/Telegram.py b/TwitchChannelPointsMiner/classes/Telegram.py index c6d9055..6b75f15 100644 --- a/TwitchChannelPointsMiner/classes/Telegram.py +++ b/TwitchChannelPointsMiner/classes/Telegram.py @@ -8,9 +8,8 @@ from TwitchChannelPointsMiner.classes.Settings import Events class Telegram(object): __slots__ = ["chat_id", "telegram_api", "events", "disable_notification"] - def __init__( - self, chat_id: int, token: str, events: list, disable_notification: bool = False - ): + def __init__(self, chat_id: int, token: str, events: list, disable_notification: bool = False): + self.chat_id = chat_id self.telegram_api = f"https://api.telegram.org/bot{token}/sendMessage" self.events = [str(e) for e in events] diff --git a/TwitchChannelPointsMiner/classes/Twitch.py b/TwitchChannelPointsMiner/classes/Twitch.py index c27d883..8b831d1 100644 --- a/TwitchChannelPointsMiner/classes/Twitch.py +++ b/TwitchChannelPointsMiner/classes/Twitch.py @@ -378,6 +378,7 @@ class Twitch(object): extra={ "event": Events.DROP_STATUS, "skip_telegram": True, + "skip_discord": True, }, ) @@ -387,6 +388,12 @@ class Twitch(object): Events.DROP_STATUS, ) + if Settings.logger.discord is not None: + Settings.logger.discord.send( + "\n".join(drop_messages), + Events.DROP_STATUS, + ) + except requests.exceptions.ConnectionError as e: logger.error(f"Error while trying to send minute watched: {e}") self.__check_connection_handler(chunk_size) diff --git a/TwitchChannelPointsMiner/logger.py b/TwitchChannelPointsMiner/logger.py index ecb730d..e756793 100644 --- a/TwitchChannelPointsMiner/logger.py +++ b/TwitchChannelPointsMiner/logger.py @@ -10,6 +10,7 @@ from colorama import Fore, init from TwitchChannelPointsMiner.classes.Settings import Events from TwitchChannelPointsMiner.classes.Telegram import Telegram +from TwitchChannelPointsMiner.classes.DiscordWebhook import Discord from TwitchChannelPointsMiner.utils import remove_emoji @@ -66,6 +67,7 @@ class LoggerSettings: "color_palette", "auto_clear", "telegram", + "discord", ] def __init__( @@ -79,6 +81,7 @@ class LoggerSettings: color_palette: ColorPalette = ColorPalette(), auto_clear: bool = True, telegram: Telegram or None = None, + discord: Discord or None = None, ): self.save = save self.less = less @@ -89,6 +92,7 @@ class LoggerSettings: self.color_palette = color_palette self.auto_clear = auto_clear self.telegram = telegram + self.discord = discord class GlobalFormatter(logging.Formatter): @@ -133,6 +137,20 @@ class GlobalFormatter(logging.Formatter): f"{self.settings.color_palette.get(record.event)}{record.msg}" ) + if hasattr(record, "event"): + skip_discord = ( + False + if hasattr(record, "skip_discord") is False + else True + ) + if self.settings.discord is not None and skip_discord is False: + self.settings.discord.send(record.msg, record.event) + + if self.settings.colored is True: + record.msg = ( + f"{self.settings.color_palette.get(record.event)}{record.msg}" + ) + return super().format(record) diff --git a/example.py b/example.py index feaa3a3..4a1f4d5 100644 --- a/example.py +++ b/example.py @@ -5,6 +5,7 @@ from colorama import Fore from TwitchChannelPointsMiner import TwitchChannelPointsMiner from TwitchChannelPointsMiner.logger import LoggerSettings, ColorPalette from TwitchChannelPointsMiner.classes.Telegram import Telegram +from TwitchChannelPointsMiner.classes.DiscordWebhook import Discord from TwitchChannelPointsMiner.classes.Settings import Priority, Events, FollowersOrder from TwitchChannelPointsMiner.classes.entities.Bet import Strategy, BetSettings, Condition, OutcomeKeys, FilterCondition, DelayMode from TwitchChannelPointsMiner.classes.entities.Streamer import Streamer, StreamerSettings @@ -35,7 +36,12 @@ twitch_miner = TwitchChannelPointsMiner( token="123456789:shfuihreuifheuifhiu34578347", # Telegram API token @BotFather events=[Events.STREAMER_ONLINE, Events.STREAMER_OFFLINE, "BET_LOSE"], # Only these events will be sent to the chat disable_notification=True, # Revoke the notification (sound/vibration) - ) + ), + + discord=Discord( + discord_webhook_api="https://discord.com/api/webhooks/0123456789/0a1B2c3D4e5F6g7H8i9J", #Discord Webhook URL + events=[Events.STREAMER_ONLINE, Events.STREAMER_OFFLINE, Events.BET_LOSE], # Only these events will be sent to the chat + ), ), streamer_settings=StreamerSettings( make_predictions=True, # If you want to Bet / Make prediction From af37fadab91445c85ee3c2732270336ed45acdb8 Mon Sep 17 00:00:00 2001 From: Prograstinator <99142422+prograstinator@users.noreply.github.com> Date: Sun, 27 Feb 2022 00:18:40 +0000 Subject: [PATCH 02/22] Add Discord like Telegram Integrations --- README.md | 4 ++-- TwitchChannelPointsMiner/classes/Telegram.py | 4 +++- example.py | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0a42f70..5ebb6e9 100644 --- a/README.md +++ b/README.md @@ -441,8 +441,8 @@ Telegram( ``` #### Discord -If you want to reive log updates on Discord initiate a new Discord class, else leave omit this parameter or set as None -1. Go to the Server you want to recieve updates +If you want to receive log updates on Discord initiate a new Discord class, else leave omit this parameter or set as None +1. Go to the Server you want to receive updates 2. Click "Edit Channel" 3. Click "Integrations" 4. Click "Webhooks" diff --git a/TwitchChannelPointsMiner/classes/Telegram.py b/TwitchChannelPointsMiner/classes/Telegram.py index 6b75f15..1783c27 100644 --- a/TwitchChannelPointsMiner/classes/Telegram.py +++ b/TwitchChannelPointsMiner/classes/Telegram.py @@ -8,7 +8,9 @@ from TwitchChannelPointsMiner.classes.Settings import Events class Telegram(object): __slots__ = ["chat_id", "telegram_api", "events", "disable_notification"] - def __init__(self, chat_id: int, token: str, events: list, disable_notification: bool = False): + def __init__( + self, chat_id: int, token: str, events: list, disable_notification: bool = False + ): self.chat_id = chat_id self.telegram_api = f"https://api.telegram.org/bot{token}/sendMessage" diff --git a/example.py b/example.py index 4a1f4d5..9cdad35 100644 --- a/example.py +++ b/example.py @@ -39,7 +39,7 @@ twitch_miner = TwitchChannelPointsMiner( ), discord=Discord( - discord_webhook_api="https://discord.com/api/webhooks/0123456789/0a1B2c3D4e5F6g7H8i9J", #Discord Webhook URL + discord_webhook_api="https://discord.com/api/webhooks/0123456789/0a1B2c3D4e5F6g7H8i9J", # Discord Webhook URL events=[Events.STREAMER_ONLINE, Events.STREAMER_OFFLINE, Events.BET_LOSE], # Only these events will be sent to the chat ), ), From c473711acc5dacb6089b6af08e2eb658cebc5f7e Mon Sep 17 00:00:00 2001 From: Prograstinator <99142422+prograstinator@users.noreply.github.com> Date: Sun, 27 Feb 2022 00:20:39 +0000 Subject: [PATCH 03/22] Add Discord like Telegram Integrations --- TwitchChannelPointsMiner/classes/Telegram.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/TwitchChannelPointsMiner/classes/Telegram.py b/TwitchChannelPointsMiner/classes/Telegram.py index 1783c27..a7e9e72 100644 --- a/TwitchChannelPointsMiner/classes/Telegram.py +++ b/TwitchChannelPointsMiner/classes/Telegram.py @@ -10,8 +10,7 @@ class Telegram(object): def __init__( self, chat_id: int, token: str, events: list, disable_notification: bool = False - ): - + ):Add Discord like Telegram Integrations self.chat_id = chat_id self.telegram_api = f"https://api.telegram.org/bot{token}/sendMessage" self.events = [str(e) for e in events] From 4c127f2b4b34b41064d1f508bc9f6194f91aebe0 Mon Sep 17 00:00:00 2001 From: Prograstinator <99142422+prograstinator@users.noreply.github.com> Date: Sun, 27 Feb 2022 00:20:58 +0000 Subject: [PATCH 04/22] Add Discord like Telegram Integrations --- TwitchChannelPointsMiner/classes/Telegram.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TwitchChannelPointsMiner/classes/Telegram.py b/TwitchChannelPointsMiner/classes/Telegram.py index a7e9e72..c6d9055 100644 --- a/TwitchChannelPointsMiner/classes/Telegram.py +++ b/TwitchChannelPointsMiner/classes/Telegram.py @@ -10,7 +10,7 @@ class Telegram(object): def __init__( self, chat_id: int, token: str, events: list, disable_notification: bool = False - ):Add Discord like Telegram Integrations + ): self.chat_id = chat_id self.telegram_api = f"https://api.telegram.org/bot{token}/sendMessage" self.events = [str(e) for e in events] From fb1747a1dd7f69adf0c9dda91f004ef9c757d1cf Mon Sep 17 00:00:00 2001 From: Prograstinator <99142422+prograstinator@users.noreply.github.com> Date: Sun, 27 Feb 2022 13:17:01 +0000 Subject: [PATCH 05/22] black --- TwitchChannelPointsMiner/logger.py | 6 +- example.py | 196 +++++++++++++++++++++-------- 2 files changed, 145 insertions(+), 57 deletions(-) diff --git a/TwitchChannelPointsMiner/logger.py b/TwitchChannelPointsMiner/logger.py index e756793..0ccdd3a 100644 --- a/TwitchChannelPointsMiner/logger.py +++ b/TwitchChannelPointsMiner/logger.py @@ -138,11 +138,7 @@ class GlobalFormatter(logging.Formatter): ) if hasattr(record, "event"): - skip_discord = ( - False - if hasattr(record, "skip_discord") is False - else True - ) + skip_discord = False if hasattr(record, "skip_discord") is False else True if self.settings.discord is not None and skip_discord is False: self.settings.discord.send(record.msg, record.event) diff --git a/example.py b/example.py index 9cdad35..c8a375a 100644 --- a/example.py +++ b/example.py @@ -7,64 +7,81 @@ from TwitchChannelPointsMiner.logger import LoggerSettings, ColorPalette from TwitchChannelPointsMiner.classes.Telegram import Telegram from TwitchChannelPointsMiner.classes.DiscordWebhook import Discord from TwitchChannelPointsMiner.classes.Settings import Priority, Events, FollowersOrder -from TwitchChannelPointsMiner.classes.entities.Bet import Strategy, BetSettings, Condition, OutcomeKeys, FilterCondition, DelayMode -from TwitchChannelPointsMiner.classes.entities.Streamer import Streamer, StreamerSettings +from TwitchChannelPointsMiner.classes.entities.Bet import ( + Strategy, + BetSettings, + Condition, + OutcomeKeys, + FilterCondition, + DelayMode, +) +from TwitchChannelPointsMiner.classes.entities.Streamer import ( + Streamer, + StreamerSettings, +) twitch_miner = TwitchChannelPointsMiner( username="your-twitch-username", - password="write-your-secure-psw", # If no password will be provided, the script will ask interactively - claim_drops_startup=False, # If you want to auto claim all drops from Twitch inventory on the startup - priority=[ # Custom priority in this case for example: - Priority.STREAK, # - We want first of all to catch all watch streak from all streamers - Priority.DROPS, # - When we don't have anymore watch streak to catch, wait until all drops are collected over the streamers - Priority.ORDER # - When we have all of the drops claimed and no watch-streak available, use the order priority (POINTS_ASCENDING, POINTS_DESCEDING) + password="write-your-secure-psw", # If no password will be provided, the script will ask interactively + claim_drops_startup=False, # If you want to auto claim all drops from Twitch inventory on the startup + priority=[ # Custom priority in this case for example: + Priority.STREAK, # - We want first of all to catch all watch streak from all streamers + Priority.DROPS, # - When we don't have anymore watch streak to catch, wait until all drops are collected over the streamers + Priority.ORDER, # - When we have all of the drops claimed and no watch-streak available, use the order priority (POINTS_ASCENDING, POINTS_DESCEDING) ], logger_settings=LoggerSettings( - save=True, # If you want to save logs in a file (suggested) - 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 - 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 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]. + save=True, # If you want to save logs in a file (suggested) + 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 + 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 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]. ), - telegram=Telegram( # You can omit or leave None if you don't want to receive updates on Telegram - chat_id=123456789, # Chat ID to send messages @GiveChatId - token="123456789:shfuihreuifheuifhiu34578347", # Telegram API token @BotFather - events=[Events.STREAMER_ONLINE, Events.STREAMER_OFFLINE, "BET_LOSE"], # Only these events will be sent to the chat - disable_notification=True, # Revoke the notification (sound/vibration) + telegram=Telegram( # You can omit or leave None if you don't want to receive updates on Telegram + chat_id=123456789, # Chat ID to send messages @GiveChatId + token="123456789:shfuihreuifheuifhiu34578347", # Telegram API token @BotFather + events=[ + Events.STREAMER_ONLINE, + Events.STREAMER_OFFLINE, + "BET_LOSE", + ], # Only these events will be sent to the chat + disable_notification=True, # Revoke the notification (sound/vibration) ), - discord=Discord( discord_webhook_api="https://discord.com/api/webhooks/0123456789/0a1B2c3D4e5F6g7H8i9J", # Discord Webhook URL - events=[Events.STREAMER_ONLINE, Events.STREAMER_OFFLINE, Events.BET_LOSE], # Only these events will be sent to the chat + events=[ + Events.STREAMER_ONLINE, + Events.STREAMER_OFFLINE, + Events.BET_LOSE, + ], # Only these events will be sent to the chat ), ), streamer_settings=StreamerSettings( - 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 - watch_streak=True, # If a streamer go online change the priority of streamers array and catch the watch streak. Issue #11 - join_chat=True, # Join irc chat to increase watch-time + 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 + watch_streak=True, # If a streamer go online change the priority of streamers array and catch the watch streak. Issue #11 + join_chat=True, # Join irc chat to increase watch-time bet=BetSettings( - strategy=Strategy.SMART, # Choose you strategy! - percentage=5, # Place the x% of your channel points - percentage_gap=20, # Gap difference between outcomesA and outcomesB (for SMART strategy) - max_points=50000, # If the x percentage of your channel points is gt bet_max_points set this value - stealth_mode=True, # If the calculated amount of channel points is GT the highest bet, place the highest value minus 1-2 points Issue #33 - delay_mode=DelayMode.FROM_END, # When placing a bet, we will wait until `delay` seconds before the end of the timer + strategy=Strategy.SMART, # Choose you strategy! + percentage=5, # Place the x% of your channel points + percentage_gap=20, # Gap difference between outcomesA and outcomesB (for SMART strategy) + max_points=50000, # If the x percentage of your channel points is gt bet_max_points set this value + stealth_mode=True, # If the calculated amount of channel points is GT the highest bet, place the highest value minus 1-2 points Issue #33 + delay_mode=DelayMode.FROM_END, # When placing a bet, we will wait until `delay` seconds before the end of the timer delay=6, - minimum_points=20000, # Place the bet only if we have at least 20k points. Issue #113 + minimum_points=20000, # Place the bet only if we have at least 20k points. Issue #113 filter_condition=FilterCondition( - by=OutcomeKeys.TOTAL_USERS, # Where apply the filter. Allowed [PERCENTAGE_USERS, ODDS_PERCENTAGE, ODDS, TOP_POINTS, TOTAL_USERS, TOTAL_POINTS] - where=Condition.LTE, # 'by' must be [GT, LT, GTE, LTE] than value - value=800 - ) - ) - ) + by=OutcomeKeys.TOTAL_USERS, # Where apply the filter. Allowed [PERCENTAGE_USERS, ODDS_PERCENTAGE, ODDS, TOP_POINTS, TOTAL_USERS, TOTAL_POINTS] + where=Condition.LTE, # 'by' must be [GT, LT, GTE, LTE] than value + value=800, + ), + ), + ), ) # You can customize the settings for each streamer. If not settings were provided, the script would use the streamer_settings from TwitchChannelPointsMiner. @@ -77,18 +94,93 @@ twitch_miner = TwitchChannelPointsMiner( twitch_miner.mine( [ - Streamer("streamer-username01", settings=StreamerSettings(make_predictions=True , follow_raid=False , claim_drops=True , watch_streak=True , bet=BetSettings(strategy=Strategy.SMART , percentage=5 , stealth_mode=True, percentage_gap=20 , max_points=234 , filter_condition=FilterCondition(by=OutcomeKeys.TOTAL_USERS, where=Condition.LTE, value=800 ) ) )), - Streamer("streamer-username02", settings=StreamerSettings(make_predictions=False , follow_raid=True , claim_drops=False , bet=BetSettings(strategy=Strategy.PERCENTAGE , percentage=5 , stealth_mode=False, percentage_gap=20 , max_points=1234 , filter_condition=FilterCondition(by=OutcomeKeys.TOTAL_POINTS, where=Condition.GTE, value=250 ) ) )), - Streamer("streamer-username03", settings=StreamerSettings(make_predictions=True , follow_raid=False , watch_streak=True , bet=BetSettings(strategy=Strategy.SMART , percentage=5 , stealth_mode=False, percentage_gap=30 , max_points=50000 , filter_condition=FilterCondition(by=OutcomeKeys.ODDS, where=Condition.LT, value=300 ) ) )), - Streamer("streamer-username04", settings=StreamerSettings(make_predictions=False , follow_raid=True , watch_streak=True )), - Streamer("streamer-username05", settings=StreamerSettings(make_predictions=True , follow_raid=True , claim_drops=True , watch_streak=True , bet=BetSettings(strategy=Strategy.HIGH_ODDS , percentage=7 , stealth_mode=True, percentage_gap=20 , max_points=90 , filter_condition=FilterCondition(by=OutcomeKeys.PERCENTAGE_USERS, where=Condition.GTE, value=300 ) ) )), + Streamer( + "streamer-username01", + settings=StreamerSettings( + make_predictions=True, + follow_raid=False, + claim_drops=True, + watch_streak=True, + bet=BetSettings( + strategy=Strategy.SMART, + percentage=5, + stealth_mode=True, + percentage_gap=20, + max_points=234, + filter_condition=FilterCondition( + by=OutcomeKeys.TOTAL_USERS, where=Condition.LTE, value=800 + ), + ), + ), + ), + Streamer( + "streamer-username02", + settings=StreamerSettings( + make_predictions=False, + follow_raid=True, + claim_drops=False, + bet=BetSettings( + strategy=Strategy.PERCENTAGE, + percentage=5, + stealth_mode=False, + percentage_gap=20, + max_points=1234, + filter_condition=FilterCondition( + by=OutcomeKeys.TOTAL_POINTS, where=Condition.GTE, value=250 + ), + ), + ), + ), + Streamer( + "streamer-username03", + settings=StreamerSettings( + make_predictions=True, + follow_raid=False, + watch_streak=True, + bet=BetSettings( + strategy=Strategy.SMART, + percentage=5, + stealth_mode=False, + percentage_gap=30, + max_points=50000, + filter_condition=FilterCondition( + by=OutcomeKeys.ODDS, where=Condition.LT, value=300 + ), + ), + ), + ), + Streamer( + "streamer-username04", + settings=StreamerSettings( + make_predictions=False, follow_raid=True, watch_streak=True + ), + ), + Streamer( + "streamer-username05", + settings=StreamerSettings( + make_predictions=True, + follow_raid=True, + claim_drops=True, + watch_streak=True, + bet=BetSettings( + strategy=Strategy.HIGH_ODDS, + percentage=7, + stealth_mode=True, + percentage_gap=20, + max_points=90, + filter_condition=FilterCondition( + by=OutcomeKeys.PERCENTAGE_USERS, where=Condition.GTE, value=300 + ), + ), + ), + ), Streamer("streamer-username06"), Streamer("streamer-username07"), Streamer("streamer-username08"), "streamer-username09", "streamer-username10", - "streamer-username11" - ], # Array of streamers (order = priority) - followers=False, # Automatic download the list of your followers - followers_order=FollowersOrder.ASC # Sort the followers list by follow date. ASC or DESC + "streamer-username11", + ], # Array of streamers (order = priority) + followers=False, # Automatic download the list of your followers + followers_order=FollowersOrder.ASC, # Sort the followers list by follow date. ASC or DESC ) From 2564cd6da58d2c0b1bc693902652fc1945483dc9 Mon Sep 17 00:00:00 2001 From: Prograstinator <99142422+prograstinator@users.noreply.github.com> Date: Sun, 27 Feb 2022 16:38:32 +0100 Subject: [PATCH 06/22] pre-commit --- .gitignore | 2 +- README.md | 4 ++-- TwitchChannelPointsMiner/classes/entities/__init__.py | 1 - TwitchChannelPointsMiner/logger.py | 2 +- requirements.txt | 2 +- 5 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index c1445f5..ba8ac24 100644 --- a/.gitignore +++ b/.gitignore @@ -149,4 +149,4 @@ cookies/* logs/* screenshots/* htmls/* -analytics/* \ No newline at end of file +analytics/* diff --git a/README.md b/README.md index 5ebb6e9..ef0c013 100644 --- a/README.md +++ b/README.md @@ -221,7 +221,7 @@ twitch_miner = TwitchChannelPointsMiner( events=[Events.STREAMER_ONLINE, Events.STREAMER_OFFLINE, "BET_LOSE"], # Only these events will be sent to the chat disable_notification=True, # Revoke the notification (sound/vibration) ), - + discord=Discord( discord_webhook_api="https://discord.com/api/webhooks/0123456789/0a1B2c3D4e5F6g7H8i9J", #Discord Webhook URL events=[Events.STREAMER_ONLINE, Events.STREAMER_OFFLINE, Events.BET_LOSE], # Only these events will be sent to the chat @@ -441,7 +441,7 @@ Telegram( ``` #### Discord -If you want to receive log updates on Discord initiate a new Discord class, else leave omit this parameter or set as None +If you want to receive log updates on Discord initiate a new Discord class, else leave omit this parameter or set as None 1. Go to the Server you want to receive updates 2. Click "Edit Channel" 3. Click "Integrations" diff --git a/TwitchChannelPointsMiner/classes/entities/__init__.py b/TwitchChannelPointsMiner/classes/entities/__init__.py index 8b13789..e69de29 100644 --- a/TwitchChannelPointsMiner/classes/entities/__init__.py +++ b/TwitchChannelPointsMiner/classes/entities/__init__.py @@ -1 +0,0 @@ - diff --git a/TwitchChannelPointsMiner/logger.py b/TwitchChannelPointsMiner/logger.py index 0ccdd3a..fe8a4b9 100644 --- a/TwitchChannelPointsMiner/logger.py +++ b/TwitchChannelPointsMiner/logger.py @@ -8,9 +8,9 @@ from pathlib import Path import emoji from colorama import Fore, init +from TwitchChannelPointsMiner.classes.DiscordWebhook import Discord from TwitchChannelPointsMiner.classes.Settings import Events from TwitchChannelPointsMiner.classes.Telegram import Telegram -from TwitchChannelPointsMiner.classes.DiscordWebhook import Discord from TwitchChannelPointsMiner.utils import remove_emoji diff --git a/requirements.txt b/requirements.txt index e7f39ec..f15b9b8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,4 +8,4 @@ millify==0.1.1 pre-commit==2.13.0 colorama==0.4.4 flask==2.0.1 -irc==19.0.1 \ No newline at end of file +irc==19.0.1 From e39e83bf367b8b6f77a04edfc0affe18d28d4b98 Mon Sep 17 00:00:00 2001 From: Prograstinator <99142422+prograstinator@users.noreply.github.com> Date: Mon, 28 Feb 2022 13:51:51 +0000 Subject: [PATCH 07/22] Fixes --- .../classes/{DiscordWebhook.py => Discord.py} | 8 ++++---- TwitchChannelPointsMiner/logger.py | 12 +++++++----- 2 files changed, 11 insertions(+), 9 deletions(-) rename TwitchChannelPointsMiner/classes/{DiscordWebhook.py => Discord.py} (71%) diff --git a/TwitchChannelPointsMiner/classes/DiscordWebhook.py b/TwitchChannelPointsMiner/classes/Discord.py similarity index 71% rename from TwitchChannelPointsMiner/classes/DiscordWebhook.py rename to TwitchChannelPointsMiner/classes/Discord.py index 61582ce..00b9670 100644 --- a/TwitchChannelPointsMiner/classes/DiscordWebhook.py +++ b/TwitchChannelPointsMiner/classes/Discord.py @@ -6,16 +6,16 @@ from TwitchChannelPointsMiner.classes.Settings import Events class Discord(object): - __slots__ = ["discord_webhook_api", "events"] + __slots__ = ["webhook_api", "events"] - def __init__(self, discord_webhook_api: str, events: list): - self.discord_webhook_api = discord_webhook_api + def __init__(self, webhook_api: str, events: list): + self.webhook_api = webhook_api self.events = [str(e) for e in events] def send(self, message: str, event: Events) -> None: if str(event) in self.events: requests.post( - url=self.discord_webhook_api, + url=self.webhook_api, data={ "content": dedent(message), "username": "Twitch Channel Points Miner", diff --git a/TwitchChannelPointsMiner/logger.py b/TwitchChannelPointsMiner/logger.py index fe8a4b9..912664c 100644 --- a/TwitchChannelPointsMiner/logger.py +++ b/TwitchChannelPointsMiner/logger.py @@ -126,7 +126,6 @@ class GlobalFormatter(logging.Formatter): skip_telegram = ( False if hasattr(record, "skip_telegram") is False - or hasattr(record, "skip_telegram") is False else True ) if self.settings.telegram is not None and skip_telegram is False: @@ -138,15 +137,18 @@ class GlobalFormatter(logging.Formatter): ) if hasattr(record, "event"): - skip_discord = False if hasattr(record, "skip_discord") is False else True - if self.settings.discord is not None and skip_discord is False: - self.settings.discord.send(record.msg, record.event) + skip_discord = ( + False + if hasattr(record, "skip_discord") is False + else True + ) + if self.settings.telegram is not None and skip_discord is False: + self.settings.telegram.send(record.msg, record.event) if self.settings.colored is True: record.msg = ( f"{self.settings.color_palette.get(record.event)}{record.msg}" ) - return super().format(record) From ebab14cc2c8ee6048aa47863d6af6d743994c0d6 Mon Sep 17 00:00:00 2001 From: Prograstinator <99142422+prograstinator@users.noreply.github.com> Date: Mon, 28 Feb 2022 13:54:29 +0000 Subject: [PATCH 08/22] Fixes --- README.md | 2 +- example.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ef0c013..8324567 100644 --- a/README.md +++ b/README.md @@ -451,7 +451,7 @@ If you want to receive log updates on Discord initiate a new Discord class, else 7. Click on "Copy Webhook URL" ```python Discord( - discord_webhook_api="https://discord.com/api/webhooks/0123456789/0a1B2c3D4e5F6g7H8i9J", + webhook_api="https://discord.com/api/webhooks/0123456789/0a1B2c3D4e5F6g7H8i9J", events=[Events.STREAMER_ONLINE, Events.STREAMER_OFFLINE, Events.BET_LOSE], ) ``` diff --git a/example.py b/example.py index c8a375a..b536ea7 100644 --- a/example.py +++ b/example.py @@ -5,7 +5,7 @@ from colorama import Fore from TwitchChannelPointsMiner import TwitchChannelPointsMiner from TwitchChannelPointsMiner.logger import LoggerSettings, ColorPalette from TwitchChannelPointsMiner.classes.Telegram import Telegram -from TwitchChannelPointsMiner.classes.DiscordWebhook import Discord +from TwitchChannelPointsMiner.classes.Discord import Discord from TwitchChannelPointsMiner.classes.Settings import Priority, Events, FollowersOrder from TwitchChannelPointsMiner.classes.entities.Bet import ( Strategy, @@ -52,7 +52,7 @@ twitch_miner = TwitchChannelPointsMiner( disable_notification=True, # Revoke the notification (sound/vibration) ), discord=Discord( - discord_webhook_api="https://discord.com/api/webhooks/0123456789/0a1B2c3D4e5F6g7H8i9J", # Discord Webhook URL + webhook_api="https://discord.com/api/webhooks/0123456789/0a1B2c3D4e5F6g7H8i9J", # Discord Webhook URL events=[ Events.STREAMER_ONLINE, Events.STREAMER_OFFLINE, From 99df50557e4385588f9daa199745eba45272da4b Mon Sep 17 00:00:00 2001 From: Prograstinator <99142422+prograstinator@users.noreply.github.com> Date: Mon, 28 Feb 2022 13:55:51 +0000 Subject: [PATCH 09/22] Fixes --- TwitchChannelPointsMiner/logger.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TwitchChannelPointsMiner/logger.py b/TwitchChannelPointsMiner/logger.py index 912664c..226d3d9 100644 --- a/TwitchChannelPointsMiner/logger.py +++ b/TwitchChannelPointsMiner/logger.py @@ -8,7 +8,7 @@ from pathlib import Path import emoji from colorama import Fore, init -from TwitchChannelPointsMiner.classes.DiscordWebhook import Discord +from TwitchChannelPointsMiner.classes.Discord import Discord from TwitchChannelPointsMiner.classes.Settings import Events from TwitchChannelPointsMiner.classes.Telegram import Telegram from TwitchChannelPointsMiner.utils import remove_emoji From 5ab4a04e71b4b4abc4207b134a525b3843325658 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 28 Feb 2022 15:30:22 +0000 Subject: [PATCH 10/22] Bump actions/setup-python from 2 to 3 Bumps [actions/setup-python](https://github.com/actions/setup-python) from 2 to 3. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](https://github.com/actions/setup-python/compare/v2...v3) --- updated-dependencies: - dependency-name: actions/setup-python dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/code-checker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/code-checker.yml b/.github/workflows/code-checker.yml index 2c71c89..429115b 100644 --- a/.github/workflows/code-checker.yml +++ b/.github/workflows/code-checker.yml @@ -17,7 +17,7 @@ jobs: uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v3 with: python-version: ${{ matrix.python-version }} From 7ab1b3a5d0810b5cc8453190561fd5938d0c7ac5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 28 Feb 2022 15:30:26 +0000 Subject: [PATCH 11/22] Bump docker/login-action from 1.13.0 to 1.14.0 Bumps [docker/login-action](https://github.com/docker/login-action) from 1.13.0 to 1.14.0. - [Release notes](https://github.com/docker/login-action/releases) - [Commits](https://github.com/docker/login-action/compare/v1.13.0...v1.14.0) --- updated-dependencies: - dependency-name: docker/login-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/deploy-docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-docker.yml b/.github/workflows/deploy-docker.yml index 49fd629..28ddff7 100644 --- a/.github/workflows/deploy-docker.yml +++ b/.github/workflows/deploy-docker.yml @@ -20,7 +20,7 @@ jobs: uses: docker/setup-buildx-action@v1.6.0 - name: Login to DockerHub - uses: docker/login-action@v1.13.0 + uses: docker/login-action@v1.14.0 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_TOKEN }} From 7fcf1ab483b51218a5d5c3ace59b55bae78ff759 Mon Sep 17 00:00:00 2001 From: Prograstinator <99142422+prograstinator@users.noreply.github.com> Date: Mon, 28 Feb 2022 18:51:15 +0100 Subject: [PATCH 12/22] pre-commit manually --- TwitchChannelPointsMiner/logger.py | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/TwitchChannelPointsMiner/logger.py b/TwitchChannelPointsMiner/logger.py index 226d3d9..bdf1a14 100644 --- a/TwitchChannelPointsMiner/logger.py +++ b/TwitchChannelPointsMiner/logger.py @@ -123,11 +123,7 @@ class GlobalFormatter(logging.Formatter): record.msg = remove_emoji(record.msg) if hasattr(record, "event"): - skip_telegram = ( - False - if hasattr(record, "skip_telegram") is False - else True - ) + skip_telegram = False if hasattr(record, "skip_telegram") is False else True if self.settings.telegram is not None and skip_telegram is False: self.settings.telegram.send(record.msg, record.event) @@ -137,11 +133,7 @@ class GlobalFormatter(logging.Formatter): ) if hasattr(record, "event"): - skip_discord = ( - False - if hasattr(record, "skip_discord") is False - else True - ) + skip_discord = False if hasattr(record, "skip_discord") is False else True if self.settings.telegram is not None and skip_discord is False: self.settings.telegram.send(record.msg, record.event) From 4fbe1c3cf2fb78edc3b4b0efa974dfaa3528a96f Mon Sep 17 00:00:00 2001 From: Prograstinator <99142422+prograstinator@users.noreply.github.com> Date: Mon, 28 Feb 2022 18:54:33 +0100 Subject: [PATCH 13/22] Fix --- TwitchChannelPointsMiner/logger.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TwitchChannelPointsMiner/logger.py b/TwitchChannelPointsMiner/logger.py index bdf1a14..1c4590a 100644 --- a/TwitchChannelPointsMiner/logger.py +++ b/TwitchChannelPointsMiner/logger.py @@ -134,8 +134,8 @@ class GlobalFormatter(logging.Formatter): if hasattr(record, "event"): skip_discord = False if hasattr(record, "skip_discord") is False else True - if self.settings.telegram is not None and skip_discord is False: - self.settings.telegram.send(record.msg, record.event) + if self.settings.discord is not None and skip_discord is False: + self.settings.discord.send(record.msg, record.event) if self.settings.colored is True: record.msg = ( From 80f00220b8b9fdff6b66d11dacd9734710c77222 Mon Sep 17 00:00:00 2001 From: Prograstinator <99142422+prograstinator@users.noreply.github.com> Date: Mon, 28 Feb 2022 23:06:59 +0100 Subject: [PATCH 14/22] FIx --- TwitchChannelPointsMiner/logger.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TwitchChannelPointsMiner/logger.py b/TwitchChannelPointsMiner/logger.py index 1c4590a..d55655e 100644 --- a/TwitchChannelPointsMiner/logger.py +++ b/TwitchChannelPointsMiner/logger.py @@ -132,7 +132,6 @@ class GlobalFormatter(logging.Formatter): f"{self.settings.color_palette.get(record.event)}{record.msg}" ) - if hasattr(record, "event"): skip_discord = False if hasattr(record, "skip_discord") is False else True if self.settings.discord is not None and skip_discord is False: self.settings.discord.send(record.msg, record.event) @@ -141,6 +140,7 @@ class GlobalFormatter(logging.Formatter): record.msg = ( f"{self.settings.color_palette.get(record.event)}{record.msg}" ) + return super().format(record) From cdb5ae0f0c97dd8b9e91e9ddd057ab00513aa179 Mon Sep 17 00:00:00 2001 From: Prograstinator <99142422+prograstinator@users.noreply.github.com> Date: Wed, 2 Mar 2022 05:23:26 +0100 Subject: [PATCH 15/22] Added check if config is updated --- TwitchChannelPointsMiner/logger.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/TwitchChannelPointsMiner/logger.py b/TwitchChannelPointsMiner/logger.py index d55655e..0c8cb97 100644 --- a/TwitchChannelPointsMiner/logger.py +++ b/TwitchChannelPointsMiner/logger.py @@ -124,6 +124,9 @@ class GlobalFormatter(logging.Formatter): if hasattr(record, "event"): skip_telegram = False if hasattr(record, "skip_telegram") is False else True + skip_telegram = ( + True if self.settings.telegram.chat_id == 123456789 else False + ) if self.settings.telegram is not None and skip_telegram is False: self.settings.telegram.send(record.msg, record.event) @@ -133,6 +136,12 @@ class GlobalFormatter(logging.Formatter): ) skip_discord = False if hasattr(record, "skip_discord") is False else True + skip_discord = ( + True + if self.settings.discord.webhook_api + == "https://discord.com/api/webhooks/0123456789/0a1B2c3D4e5F6g7H8i9J" + else False + ) if self.settings.discord is not None and skip_discord is False: self.settings.discord.send(record.msg, record.event) From 1cbc31f99827d60e950730f42bbc2535e2e03324 Mon Sep 17 00:00:00 2001 From: Alessandro Maggio Date: Wed, 2 Mar 2022 11:11:52 +0100 Subject: [PATCH 16/22] Custom urlparse - Fix #437 --- TwitchChannelPointsMiner/utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/TwitchChannelPointsMiner/utils.py b/TwitchChannelPointsMiner/utils.py index 7f6dbda..ea0b651 100644 --- a/TwitchChannelPointsMiner/utils.py +++ b/TwitchChannelPointsMiner/utils.py @@ -190,7 +190,12 @@ def check_versions(): current_version = "0.0.0" try: r = requests.get( - path.join(GITHUB_url, "TwitchChannelPointsMiner", "__init__.py") + "/".join( + [ + s.strip("/") + for s in [GITHUB_url, "TwitchChannelPointsMiner", "__init__.py"] + ] + ) ) github_version = init2dict(r.text) github_version = ( From 16ed804e4951e937eeaa23410a51da5d26afbf9a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 2 Mar 2022 15:34:38 +0000 Subject: [PATCH 17/22] Bump actions/checkout from 2 to 3 Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v2...v3) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/code-checker.yml | 2 +- .github/workflows/deploy-docker.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/code-checker.yml b/.github/workflows/code-checker.yml index 429115b..23dd7bb 100644 --- a/.github/workflows/code-checker.yml +++ b/.github/workflows/code-checker.yml @@ -14,7 +14,7 @@ jobs: python-version: [3.6, 3.7, 3.8] steps: - name: Clone Repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v3 diff --git a/.github/workflows/deploy-docker.yml b/.github/workflows/deploy-docker.yml index 28ddff7..d3d26d2 100644 --- a/.github/workflows/deploy-docker.yml +++ b/.github/workflows/deploy-docker.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout source - uses: actions/checkout@v2.4.0 + uses: actions/checkout@v3 - name: Set up QEMU uses: docker/setup-qemu-action@v1.2.0 From ebfb13a14e4bb6868c7c8ef27a0ecc7983adbb02 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 2 Mar 2022 15:34:40 +0000 Subject: [PATCH 18/22] Bump docker/login-action from 1.14.0 to 1.14.1 Bumps [docker/login-action](https://github.com/docker/login-action) from 1.14.0 to 1.14.1. - [Release notes](https://github.com/docker/login-action/releases) - [Commits](https://github.com/docker/login-action/compare/v1.14.0...v1.14.1) --- updated-dependencies: - dependency-name: docker/login-action dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/deploy-docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-docker.yml b/.github/workflows/deploy-docker.yml index 28ddff7..241430a 100644 --- a/.github/workflows/deploy-docker.yml +++ b/.github/workflows/deploy-docker.yml @@ -20,7 +20,7 @@ jobs: uses: docker/setup-buildx-action@v1.6.0 - name: Login to DockerHub - uses: docker/login-action@v1.14.0 + uses: docker/login-action@v1.14.1 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_TOKEN }} From 3289b2559179673b2d1e0a1826a8303dd3398dd9 Mon Sep 17 00:00:00 2001 From: Prograstinator <99142422+prograstinator@users.noreply.github.com> Date: Wed, 2 Mar 2022 20:03:42 +0100 Subject: [PATCH 19/22] Fix --- TwitchChannelPointsMiner/logger.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/TwitchChannelPointsMiner/logger.py b/TwitchChannelPointsMiner/logger.py index 0c8cb97..bf30e0c 100644 --- a/TwitchChannelPointsMiner/logger.py +++ b/TwitchChannelPointsMiner/logger.py @@ -124,10 +124,12 @@ class GlobalFormatter(logging.Formatter): if hasattr(record, "event"): skip_telegram = False if hasattr(record, "skip_telegram") is False else True - skip_telegram = ( - True if self.settings.telegram.chat_id == 123456789 else False - ) - if self.settings.telegram is not None and skip_telegram is False: + + if ( + self.settings.telegram is not None + and skip_telegram is False + and self.settings.telegram.chat_id != 123456789 + ): self.settings.telegram.send(record.msg, record.event) if self.settings.colored is True: @@ -136,13 +138,13 @@ class GlobalFormatter(logging.Formatter): ) skip_discord = False if hasattr(record, "skip_discord") is False else True - skip_discord = ( - True - if self.settings.discord.webhook_api - == "https://discord.com/api/webhooks/0123456789/0a1B2c3D4e5F6g7H8i9J" - else False - ) - if self.settings.discord is not None and skip_discord is False: + + if ( + self.settings.discord is not None + and skip_discord is False + and self.settings.discord.webhook_api + != "https://discord.com/api/webhooks/0123456789/0a1B2c3D4e5F6g7H8i9J" + ): self.settings.discord.send(record.msg, record.event) if self.settings.colored is True: From dd4e88b0f36c64cdf5da5826bdb92aa30877c198 Mon Sep 17 00:00:00 2001 From: Alessandro Maggio Date: Sat, 5 Mar 2022 14:14:21 +0100 Subject: [PATCH 20/22] Update example.py --- example.py | 199 ++++++++++++++--------------------------------------- 1 file changed, 53 insertions(+), 146 deletions(-) diff --git a/example.py b/example.py index b536ea7..c17d66b 100644 --- a/example.py +++ b/example.py @@ -4,84 +4,66 @@ import logging from colorama import Fore from TwitchChannelPointsMiner import TwitchChannelPointsMiner from TwitchChannelPointsMiner.logger import LoggerSettings, ColorPalette -from TwitchChannelPointsMiner.classes.Telegram import Telegram from TwitchChannelPointsMiner.classes.Discord import Discord +from TwitchChannelPointsMiner.classes.Telegram import Telegram from TwitchChannelPointsMiner.classes.Settings import Priority, Events, FollowersOrder -from TwitchChannelPointsMiner.classes.entities.Bet import ( - Strategy, - BetSettings, - Condition, - OutcomeKeys, - FilterCondition, - DelayMode, -) -from TwitchChannelPointsMiner.classes.entities.Streamer import ( - Streamer, - StreamerSettings, -) +from TwitchChannelPointsMiner.classes.entities.Bet import Strategy, BetSettings, Condition, OutcomeKeys, FilterCondition, DelayMode +from TwitchChannelPointsMiner.classes.entities.Streamer import Streamer, StreamerSettings twitch_miner = TwitchChannelPointsMiner( username="your-twitch-username", - password="write-your-secure-psw", # If no password will be provided, the script will ask interactively - claim_drops_startup=False, # If you want to auto claim all drops from Twitch inventory on the startup - priority=[ # Custom priority in this case for example: - Priority.STREAK, # - We want first of all to catch all watch streak from all streamers - Priority.DROPS, # - When we don't have anymore watch streak to catch, wait until all drops are collected over the streamers - Priority.ORDER, # - When we have all of the drops claimed and no watch-streak available, use the order priority (POINTS_ASCENDING, POINTS_DESCEDING) + password="write-your-secure-psw", # If no password will be provided, the script will ask interactively + claim_drops_startup=False, # If you want to auto claim all drops from Twitch inventory on the startup + priority=[ # Custom priority in this case for example: + Priority.STREAK, # - We want first of all to catch all watch streak from all streamers + Priority.DROPS, # - When we don't have anymore watch streak to catch, wait until all drops are collected over the streamers + Priority.ORDER # - When we have all of the drops claimed and no watch-streak available, use the order priority (POINTS_ASCENDING, POINTS_DESCEDING) ], logger_settings=LoggerSettings( - save=True, # If you want to save logs in a file (suggested) - 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 - 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 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]. + save=True, # If you want to save logs in a file (suggested) + 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 + 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 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]. ), - telegram=Telegram( # You can omit or leave None if you don't want to receive updates on Telegram - chat_id=123456789, # Chat ID to send messages @GiveChatId - token="123456789:shfuihreuifheuifhiu34578347", # Telegram API token @BotFather - events=[ - Events.STREAMER_ONLINE, - Events.STREAMER_OFFLINE, - "BET_LOSE", - ], # Only these events will be sent to the chat - disable_notification=True, # Revoke the notification (sound/vibration) + telegram=Telegram( # You can omit or leave None if you don't want to receive updates on Telegram + chat_id=123456789, # Chat ID to send messages @GiveChatId + token="123456789:shfuihreuifheuifhiu34578347", # Telegram API token @BotFather + events=[Events.STREAMER_ONLINE, Events.STREAMER_OFFLINE, "BET_LOSE"], # Only these events will be sent to the chat + disable_notification=True, # Revoke the notification (sound/vibration) ), discord=Discord( webhook_api="https://discord.com/api/webhooks/0123456789/0a1B2c3D4e5F6g7H8i9J", # Discord Webhook URL - events=[ - Events.STREAMER_ONLINE, - Events.STREAMER_OFFLINE, - Events.BET_LOSE, - ], # Only these events will be sent to the chat - ), + events=[Events.STREAMER_ONLINE, Events.STREAMER_OFFLINE, Events.BET_LOSE], # Only these events will be sent to the chat + ) ), streamer_settings=StreamerSettings( - 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 - watch_streak=True, # If a streamer go online change the priority of streamers array and catch the watch streak. Issue #11 - join_chat=True, # Join irc chat to increase watch-time + 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 + watch_streak=True, # If a streamer go online change the priority of streamers array and catch the watch streak. Issue #11 + join_chat=True, # Join irc chat to increase watch-time bet=BetSettings( - strategy=Strategy.SMART, # Choose you strategy! - percentage=5, # Place the x% of your channel points - percentage_gap=20, # Gap difference between outcomesA and outcomesB (for SMART strategy) - max_points=50000, # If the x percentage of your channel points is gt bet_max_points set this value - stealth_mode=True, # If the calculated amount of channel points is GT the highest bet, place the highest value minus 1-2 points Issue #33 - delay_mode=DelayMode.FROM_END, # When placing a bet, we will wait until `delay` seconds before the end of the timer + strategy=Strategy.SMART, # Choose you strategy! + percentage=5, # Place the x% of your channel points + percentage_gap=20, # Gap difference between outcomesA and outcomesB (for SMART strategy) + max_points=50000, # If the x percentage of your channel points is gt bet_max_points set this value + stealth_mode=True, # If the calculated amount of channel points is GT the highest bet, place the highest value minus 1-2 points Issue #33 + delay_mode=DelayMode.FROM_END, # When placing a bet, we will wait until `delay` seconds before the end of the timer delay=6, - minimum_points=20000, # Place the bet only if we have at least 20k points. Issue #113 + minimum_points=20000, # Place the bet only if we have at least 20k points. Issue #113 filter_condition=FilterCondition( - by=OutcomeKeys.TOTAL_USERS, # Where apply the filter. Allowed [PERCENTAGE_USERS, ODDS_PERCENTAGE, ODDS, TOP_POINTS, TOTAL_USERS, TOTAL_POINTS] - where=Condition.LTE, # 'by' must be [GT, LT, GTE, LTE] than value - value=800, - ), - ), - ), + by=OutcomeKeys.TOTAL_USERS, # Where apply the filter. Allowed [PERCENTAGE_USERS, ODDS_PERCENTAGE, ODDS, TOP_POINTS, TOTAL_USERS, TOTAL_POINTS] + where=Condition.LTE, # 'by' must be [GT, LT, GTE, LTE] than value + value=800 + ) + ) + ) ) # You can customize the settings for each streamer. If not settings were provided, the script would use the streamer_settings from TwitchChannelPointsMiner. @@ -94,93 +76,18 @@ twitch_miner = TwitchChannelPointsMiner( twitch_miner.mine( [ - Streamer( - "streamer-username01", - settings=StreamerSettings( - make_predictions=True, - follow_raid=False, - claim_drops=True, - watch_streak=True, - bet=BetSettings( - strategy=Strategy.SMART, - percentage=5, - stealth_mode=True, - percentage_gap=20, - max_points=234, - filter_condition=FilterCondition( - by=OutcomeKeys.TOTAL_USERS, where=Condition.LTE, value=800 - ), - ), - ), - ), - Streamer( - "streamer-username02", - settings=StreamerSettings( - make_predictions=False, - follow_raid=True, - claim_drops=False, - bet=BetSettings( - strategy=Strategy.PERCENTAGE, - percentage=5, - stealth_mode=False, - percentage_gap=20, - max_points=1234, - filter_condition=FilterCondition( - by=OutcomeKeys.TOTAL_POINTS, where=Condition.GTE, value=250 - ), - ), - ), - ), - Streamer( - "streamer-username03", - settings=StreamerSettings( - make_predictions=True, - follow_raid=False, - watch_streak=True, - bet=BetSettings( - strategy=Strategy.SMART, - percentage=5, - stealth_mode=False, - percentage_gap=30, - max_points=50000, - filter_condition=FilterCondition( - by=OutcomeKeys.ODDS, where=Condition.LT, value=300 - ), - ), - ), - ), - Streamer( - "streamer-username04", - settings=StreamerSettings( - make_predictions=False, follow_raid=True, watch_streak=True - ), - ), - Streamer( - "streamer-username05", - settings=StreamerSettings( - make_predictions=True, - follow_raid=True, - claim_drops=True, - watch_streak=True, - bet=BetSettings( - strategy=Strategy.HIGH_ODDS, - percentage=7, - stealth_mode=True, - percentage_gap=20, - max_points=90, - filter_condition=FilterCondition( - by=OutcomeKeys.PERCENTAGE_USERS, where=Condition.GTE, value=300 - ), - ), - ), - ), + Streamer("streamer-username01", settings=StreamerSettings(make_predictions=True , follow_raid=False , claim_drops=True , watch_streak=True , bet=BetSettings(strategy=Strategy.SMART , percentage=5 , stealth_mode=True, percentage_gap=20 , max_points=234 , filter_condition=FilterCondition(by=OutcomeKeys.TOTAL_USERS, where=Condition.LTE, value=800 ) ) )), + Streamer("streamer-username02", settings=StreamerSettings(make_predictions=False , follow_raid=True , claim_drops=False , bet=BetSettings(strategy=Strategy.PERCENTAGE , percentage=5 , stealth_mode=False, percentage_gap=20 , max_points=1234 , filter_condition=FilterCondition(by=OutcomeKeys.TOTAL_POINTS, where=Condition.GTE, value=250 ) ) )), + Streamer("streamer-username03", settings=StreamerSettings(make_predictions=True , follow_raid=False , watch_streak=True , bet=BetSettings(strategy=Strategy.SMART , percentage=5 , stealth_mode=False, percentage_gap=30 , max_points=50000 , filter_condition=FilterCondition(by=OutcomeKeys.ODDS, where=Condition.LT, value=300 ) ) )), + Streamer("streamer-username04", settings=StreamerSettings(make_predictions=False , follow_raid=True , watch_streak=True )), + Streamer("streamer-username05", settings=StreamerSettings(make_predictions=True , follow_raid=True , claim_drops=True , watch_streak=True , bet=BetSettings(strategy=Strategy.HIGH_ODDS , percentage=7 , stealth_mode=True, percentage_gap=20 , max_points=90 , filter_condition=FilterCondition(by=OutcomeKeys.PERCENTAGE_USERS, where=Condition.GTE, value=300 ) ) )), Streamer("streamer-username06"), Streamer("streamer-username07"), Streamer("streamer-username08"), "streamer-username09", "streamer-username10", - "streamer-username11", - ], # Array of streamers (order = priority) - followers=False, # Automatic download the list of your followers - followers_order=FollowersOrder.ASC, # Sort the followers list by follow date. ASC or DESC + "streamer-username11" + ], # Array of streamers (order = priority) + followers=False, # Automatic download the list of your followers + followers_order=FollowersOrder.ASC # Sort the followers list by follow date. ASC or DESC ) From 379563e42f7f36a09833fb099a9eb29a7d6b4459 Mon Sep 17 00:00:00 2001 From: Alessandro Maggio Date: Sat, 5 Mar 2022 14:22:23 +0100 Subject: [PATCH 21/22] Update README.md --- README.md | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 8324567..571f701 100644 --- a/README.md +++ b/README.md @@ -188,8 +188,8 @@ import logging from colorama import Fore from TwitchChannelPointsMiner import TwitchChannelPointsMiner from TwitchChannelPointsMiner.logger import LoggerSettings, ColorPalette +from TwitchChannelPointsMiner.classes.Discord import Discord from TwitchChannelPointsMiner.classes.Telegram import Telegram -from TwitchChannelPointsMiner.classes.DiscordWebhook import Discord from TwitchChannelPointsMiner.classes.Settings import Priority, Events, FollowersOrder from TwitchChannelPointsMiner.classes.entities.Bet import Strategy, BetSettings, Condition, OutcomeKeys, FilterCondition, DelayMode from TwitchChannelPointsMiner.classes.entities.Streamer import Streamer, StreamerSettings @@ -221,11 +221,10 @@ twitch_miner = TwitchChannelPointsMiner( events=[Events.STREAMER_ONLINE, Events.STREAMER_OFFLINE, "BET_LOSE"], # Only these events will be sent to the chat disable_notification=True, # Revoke the notification (sound/vibration) ), - discord=Discord( - discord_webhook_api="https://discord.com/api/webhooks/0123456789/0a1B2c3D4e5F6g7H8i9J", #Discord Webhook URL - events=[Events.STREAMER_ONLINE, Events.STREAMER_OFFLINE, Events.BET_LOSE], # Only these events will be sent to the chat - ), + webhook_api="https://discord.com/api/webhooks/0123456789/0a1B2c3D4e5F6g7H8i9J", # Discord Webhook URL + events=[Events.STREAMER_ONLINE, Events.STREAMER_OFFLINE, Events.BET_LOSE], # Only these events will be sent to the chat + ) ), streamer_settings=StreamerSettings( make_predictions=True, # If you want to Bet / Make prediction @@ -396,6 +395,7 @@ You can combine all priority but keep in mind that use `ORDER` and `POINTS_ASCEN | `auto_clear` | bool | True | Create a file rotation handler with interval = 1D and backupCount = 7 [#215](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/issues/215) | | `color_palette` | ColorPalette | All messages are Fore.RESET except WIN and LOSE bet (GREEN and RED) | Create your custom color palette. Read more above. | | `telegram` | Telegram | None | (Optional) Receive Telegram updates for multiple events list [#233](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/issues/233) | +| `discord` | Discord | None | (Optional) Receive Discord updates for multiple events list [#320](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/issues/320) | #### 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. You can change the colors of all `Events` enum class. The colors allowed are all the Fore color from Colorama: `BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET.` @@ -426,7 +426,7 @@ If you want to receive logs update on Telegram initiate a new Telegram class, el | Key | Type | Default | Description | |----------------------- |----------------- |--------- |------------------------------------------------------------------- | | `chat_id` | int | | Chat ID to send messages @GiveChatId | -| `token` | string | | Telegram API token @BotFather | +| `token` | string | | Telegram API token @BotFather | | `events` | list | | Only these events will be sent to the chat. Array of Event. or str | | `disable_notification` | bool | false | Revoke the notification (sound/vibration) | @@ -441,7 +441,7 @@ Telegram( ``` #### Discord -If you want to receive log updates on Discord initiate a new Discord class, else leave omit this parameter or set as None +If you want to receive log updates on Discord initialize a new Discord class, else leave omit this parameter or set it as None [YT Video](https://www.youtube.com/watch?v=fKksxz2Gdnc) 1. Go to the Server you want to receive updates 2. Click "Edit Channel" 3. Click "Integrations" @@ -449,6 +449,13 @@ If you want to receive log updates on Discord initiate a new Discord class, else 5. Click "New Webhook" 6. Name it if you want 7. Click on "Copy Webhook URL" + + +| Key | Type | Default | Description | +|----------------------- |--------------------- |-------------- |------------------------------------------------------------------- | +| `webhook_api` | string | | Discord webhook URL | +| `events` | list | | Only these events will be sent to the chat. Array of Event. or str | + ```python Discord( webhook_api="https://discord.com/api/webhooks/0123456789/0a1B2c3D4e5F6g7H8i9J", From a37d1b9067db269d493ccf0e3e02123e4f2b43c0 Mon Sep 17 00:00:00 2001 From: Alessandro Maggio Date: Sat, 5 Mar 2022 14:26:02 +0100 Subject: [PATCH 22/22] Tag the version as 2.0.8 - After Discord integration --- TwitchChannelPointsMiner/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TwitchChannelPointsMiner/__init__.py b/TwitchChannelPointsMiner/__init__.py index bb78b13..01d5e0d 100644 --- a/TwitchChannelPointsMiner/__init__.py +++ b/TwitchChannelPointsMiner/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -__version__ = "2.0.7" +__version__ = "2.0.8" from .TwitchChannelPointsMiner import TwitchChannelPointsMiner __all__ = [