From 0bb0876f74d152f1d37ed7d4763f4d933c158a7a Mon Sep 17 00:00:00 2001 From: Alessandro Maggio Date: Mon, 16 Aug 2021 22:36:28 +0200 Subject: [PATCH 1/4] ChatPresence enum. Ability to manage the presence in chat (irc) with ALWAYS, NEVER, ONLINE (ONLY), OFFLINE (ONLY) --- README.md | 18 +++++--- .../TwitchChannelPointsMiner.py | 4 +- TwitchChannelPointsMiner/classes/Chat.py | 11 +++++ .../classes/entities/Streamer.py | 41 ++++++++++++++----- example.py | 3 +- 5 files changed, 57 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 4ba7c931..c7761952 100644 --- a/README.md +++ b/README.md @@ -180,7 +180,8 @@ from colorama import Fore from TwitchChannelPointsMiner import TwitchChannelPointsMiner from TwitchChannelPointsMiner.logger import LoggerSettings, ColorPalette from TwitchChannelPointsMiner.classes.Settings import Priority -from TwitchChannelPointsMiner.classes.entities.Bet import Strategy, BetSettings, Condition, OutcomeKeys, FilterCondition, DelayMode +from TwitchChannelPointsMiner.classes.Chat import ChatPresence +from TwitchChannelPointsMiner.classes.entities.Bet import Strategy, BetSettings, Condition, OutcomeKeys, FilterCondition from TwitchChannelPointsMiner.classes.entities.Streamer import Streamer, StreamerSettings twitch_miner = TwitchChannelPointsMiner( @@ -210,16 +211,14 @@ twitch_miner = TwitchChannelPointsMiner( 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 priotiry of streamers array and catch the watch screak. Issue #11 - join_chat=True, # Join irc chat to increase watch-time + chat=ChatPresence.ONLINE, # Join irc chat to increase watch-time [ALWAYS, NEVER, ONLINE, OFFLINE] 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 stragegy) 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 #33 - delay_mode=DelayMode.FROM_END, # When placing a bet, we will wait until `delay` seconds before the end of the timer - delay=6, - filter_condition=FilterCondition( + 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 @@ -342,6 +341,14 @@ ColorPalette( | `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) | | `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) | + +Allowed values for `chat` are: +- `ALWAYS` Join in IRC chat and never leave +- `NEVER` Never join IRC chat +- `ONLINE` Partecipate to IRC chat if the streamer is online (leave if offline) +- `OFFLINE` Partecipate to IRC chat if the streamer is offline (leave if online) + ### BetSettings | Key | Type | Default | Description | |-------------------- |----------------- |--------- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | @@ -350,7 +357,6 @@ ColorPalette( | `percentage_gap` | int | 20 | Gap difference between outcomesA and outcomesB (for SMART stragegy) | | `max_points` | int | 50000 | If the x percentage of your channel points is GT bet_max_points set this value | | `stealth_mode` | bool | False | If the calculated amount of channel points is GT the highest bet, place the highest value minus 1-2 points [#33](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/issues/33) | -| `join_chat` | bool | True | 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) | | `delay_mode` | DelayMode | FROM_END | Define how is calculating the waiting time before placing a bet | | `delay` | float | 6 | Value to be used to calculate bet delay depending on `delay_mode` value | diff --git a/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py b/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py index 7b44c892..8b269fb0 100644 --- a/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py +++ b/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py @@ -12,7 +12,7 @@ from pathlib import Path from TwitchChannelPointsMiner.classes.AnalyticsServer import AnalyticsServer -from TwitchChannelPointsMiner.classes.Chat import ThreadChat +from TwitchChannelPointsMiner.classes.Chat import ChatPresence, ThreadChat from TwitchChannelPointsMiner.classes.entities.PubsubTopic import PubsubTopic from TwitchChannelPointsMiner.classes.entities.Streamer import ( Streamer, @@ -180,7 +180,7 @@ def run(self, streamers: list = [], blacklist: list = [], followers=False): streamer.settings.bet = set_default_settings( streamer.settings.bet, Settings.streamer_settings.bet ) - if streamer.settings.join_chat is True: + if streamer.settings.chat != ChatPresence.NEVER: streamer.irc_chat = ThreadChat( self.username, self.twitch.twitch_login.get_auth_token(), diff --git a/TwitchChannelPointsMiner/classes/Chat.py b/TwitchChannelPointsMiner/classes/Chat.py index 5e0272da..e120148f 100644 --- a/TwitchChannelPointsMiner/classes/Chat.py +++ b/TwitchChannelPointsMiner/classes/Chat.py @@ -1,5 +1,6 @@ import logging import time +from enum import Enum, auto from threading import Thread from irc.bot import SingleServerIRCBot @@ -9,6 +10,16 @@ logger = logging.getLogger(__name__) +class ChatPresence(Enum): + ALWAYS = auto() + NEVER = auto() + ONLINE = auto() + OFFLINE = auto() + + def __str__(self): + return self.name + + class ClientIRC(SingleServerIRCBot): def __init__(self, username, token, channel): self.token = token diff --git a/TwitchChannelPointsMiner/classes/entities/Streamer.py b/TwitchChannelPointsMiner/classes/entities/Streamer.py index c01cd791..c1731c36 100644 --- a/TwitchChannelPointsMiner/classes/entities/Streamer.py +++ b/TwitchChannelPointsMiner/classes/entities/Streamer.py @@ -5,7 +5,7 @@ from datetime import datetime from threading import Lock -from TwitchChannelPointsMiner.classes.Chat import ThreadChat +from TwitchChannelPointsMiner.classes.Chat import ChatPresence, ThreadChat from TwitchChannelPointsMiner.classes.entities.Bet import BetSettings, DelayMode from TwitchChannelPointsMiner.classes.entities.Stream import Stream from TwitchChannelPointsMiner.classes.Settings import Settings @@ -22,7 +22,7 @@ class StreamerSettings(object): "claim_drops", "watch_streak", "bet", - "join_chat", + "chat", ] def __init__( @@ -32,14 +32,14 @@ def __init__( claim_drops: bool = None, watch_streak: bool = None, bet: BetSettings = None, - join_chat: bool = True, + chat: ChatPresence = None, ): self.make_predictions = make_predictions self.follow_raid = follow_raid self.claim_drops = claim_drops self.watch_streak = watch_streak self.bet = bet - self.join_chat = join_chat + self.chat = chat def default(self): for name in [ @@ -47,15 +47,16 @@ def default(self): "follow_raid", "claim_drops", "watch_streak", - "join_chat", ]: if getattr(self, name) is None: setattr(self, name, True) if self.bet is None: self.bet = BetSettings() + if self.chat is None: + 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}, join_chat={self.join_chat})" + 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})" class Streamer(object): @@ -116,7 +117,8 @@ def set_offline(self): if self.is_online is True: self.offline_at = time.time() self.is_online = False - self.leave_chat() + + self.toggle_chat() logger.info( f"{self} is Offline!", @@ -131,7 +133,8 @@ def set_online(self): self.online_at = time.time() self.is_online = True self.stream.init_watch_streak() - self.join_chat() + + self.toggle_chat() logger.info( f"{self} is Online!", @@ -238,7 +241,7 @@ def __save_json(self, key, data={}, event_type="Watch"): json_data[key].append(data) json.dump(json_data, open(fname, "w"), indent=4) - def leave_chat(self): + def __leave_chat(self): if self.irc_chat is not None: self.irc_chat.stop() @@ -250,6 +253,22 @@ def leave_chat(self): self.username, ) - def join_chat(self): + def __join_chat(self): if self.irc_chat is not None: - self.irc_chat.start() + if self.irc_chat.is_alive() is False: + self.irc_chat.start() + + def toggle_chat(self): + if self.settings.chat == ChatPresence.ALWAYS: + self.__join_chat() + elif self.settings.chat != ChatPresence.NEVER: + if self.is_online is True: + if self.settings.chat == ChatPresence.ONLINE: + self.__join_chat() + elif self.settings.chat == ChatPresence.OFFLINE: + self.__leave_chat() + else: + if self.settings.chat == ChatPresence.ONLINE: + self.__leave_chat() + elif self.settings.chat == ChatPresence.OFFLINE: + self.__join_chat() diff --git a/example.py b/example.py index a8eb20f3..123829fd 100644 --- a/example.py +++ b/example.py @@ -5,6 +5,7 @@ from TwitchChannelPointsMiner import TwitchChannelPointsMiner from TwitchChannelPointsMiner.logger import LoggerSettings, ColorPalette from TwitchChannelPointsMiner.classes.Settings import Priority +from TwitchChannelPointsMiner.classes.Chat import ChatPresence from TwitchChannelPointsMiner.classes.entities.Bet import Strategy, BetSettings, Condition, OutcomeKeys, FilterCondition from TwitchChannelPointsMiner.classes.entities.Streamer import Streamer, StreamerSettings @@ -35,7 +36,7 @@ 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 priotiry of streamers array and catch the watch screak. Issue #11 - join_chat=True, # Join irc chat to increase watch-time + chat=ChatPresence.ONLINE, # Join irc chat to increase watch-time [ALWAYS, NEVER, ONLINE, OFFLINE] bet=BetSettings( strategy=Strategy.SMART, # Choose you strategy! percentage=5, # Place the x% of your channel points From 73cf4f2b35528c42595fba91977f1c81e8d3732f Mon Sep 17 00:00:00 2001 From: Alessandro Maggio Date: Wed, 18 Aug 2021 16:14:03 +0200 Subject: [PATCH 2/4] Make leave chat pub --- TwitchChannelPointsMiner/TwitchChannelPointsMiner.py | 5 ++++- TwitchChannelPointsMiner/classes/entities/Streamer.py | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py b/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py index 8b269fb0..d71572ed 100644 --- a/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py +++ b/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py @@ -297,7 +297,10 @@ def end(self, signum, frame): logger.info("CTRL+C Detected! Please wait just a moment!") for streamer in self.streamers: - if streamer.irc_chat is not None: + if ( + streamer.irc_chat is not None + and streamer.settings.chat != ChatPresence.NEVER + ): streamer.leave_chat() if streamer.irc_chat.is_alive() is True: streamer.irc_chat.join() diff --git a/TwitchChannelPointsMiner/classes/entities/Streamer.py b/TwitchChannelPointsMiner/classes/entities/Streamer.py index c1731c36..97d2104f 100644 --- a/TwitchChannelPointsMiner/classes/entities/Streamer.py +++ b/TwitchChannelPointsMiner/classes/entities/Streamer.py @@ -241,7 +241,7 @@ def __save_json(self, key, data={}, event_type="Watch"): json_data[key].append(data) json.dump(json_data, open(fname, "w"), indent=4) - def __leave_chat(self): + def leave_chat(self): if self.irc_chat is not None: self.irc_chat.stop() @@ -266,9 +266,9 @@ def toggle_chat(self): if self.settings.chat == ChatPresence.ONLINE: self.__join_chat() elif self.settings.chat == ChatPresence.OFFLINE: - self.__leave_chat() + self.leave_chat() else: if self.settings.chat == ChatPresence.ONLINE: - self.__leave_chat() + self.leave_chat() elif self.settings.chat == ChatPresence.OFFLINE: self.__join_chat() From 385361fe37271bc2eaa96d14c7144d7a66652d6d Mon Sep 17 00:00:00 2001 From: Alessandro Maggio Date: Sat, 26 Feb 2022 12:53:18 +0100 Subject: [PATCH 3/4] update version and readme --- README.md | 1 - TwitchChannelPointsMiner/__init__.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 83436635..1cb25f3b 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,6 @@ Currently, we have a lot of PRs requests opened, but the time to test and improv - [Features/improvements to analytics #131](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/pull/131) - [Betting strategy: Smart money #348](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/pull/348) - [Add SMART_HIGH_ODDS strategy #172](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/pull/172) -- [Replace join_chat boolean with chat: ChatPresence #253](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/pull/253) - [Add stats #318](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/pull/318) # README Contents diff --git a/TwitchChannelPointsMiner/__init__.py b/TwitchChannelPointsMiner/__init__.py index bb78b13e..01d5e0d5 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__ = [ From 581f513c52d7feb1236d6a0c968f981ade931648 Mon Sep 17 00:00:00 2001 From: Alessandro Maggio Date: Sat, 5 Mar 2022 14:41:48 +0100 Subject: [PATCH 4/4] Manual merge, fix conflicts - Sync with master --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index 6f347e8f..7833c744 100644 --- a/README.md +++ b/README.md @@ -187,11 +187,8 @@ import logging from colorama import Fore from TwitchChannelPointsMiner import TwitchChannelPointsMiner from TwitchChannelPointsMiner.logger import LoggerSettings, ColorPalette -<<<<<<< HEAD from TwitchChannelPointsMiner.classes.Chat import ChatPresence -======= from TwitchChannelPointsMiner.classes.Discord import Discord ->>>>>>> master 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