diff --git a/.github/workflows/deploy-docker.yml b/.github/workflows/deploy-docker.yml index 689681b..cc137ea 100644 --- a/.github/workflows/deploy-docker.yml +++ b/.github/workflows/deploy-docker.yml @@ -27,7 +27,7 @@ jobs: - name: Build and push id: docker_build - uses: docker/build-push-action@v2.9.0 + uses: docker/build-push-action@v2.10.0 with: context: . push: true diff --git a/README.md b/README.md index ec95bad..7d0bee1 100644 --- a/README.md +++ b/README.md @@ -21,10 +21,8 @@ Read more about channels point [here](https://help.twitch.tv/s/article/channel-p ## 📢 Help wanted Currently, we have a lot of PRs requests opened, but the time to test and improve It's less and less. If you want to help the community and the project, please test the following PRs and give us feedback: - [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) +- [Add support for arbitrary filter functions #336](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/pull/336) # README Contents 1. 🤝 [Community](#community) @@ -188,6 +186,7 @@ import logging from colorama import Fore from TwitchChannelPointsMiner import TwitchChannelPointsMiner from TwitchChannelPointsMiner.logger import LoggerSettings, ColorPalette +from TwitchChannelPointsMiner.classes.Chat import ChatPresence from TwitchChannelPointsMiner.classes.Discord import Discord from TwitchChannelPointsMiner.classes.Telegram import Telegram from TwitchChannelPointsMiner.classes.Settings import Priority, Events, FollowersOrder @@ -230,8 +229,8 @@ twitch_miner = TwitchChannelPointsMiner( make_predictions=True, # If you want to Bet / Make prediction follow_raid=True, # Follow raid to obtain more points claim_drops=True, # We can't filter rewards base on stream. Set to False for skip viewing counter increase and you will never obtain a drop reward from this script. Issue #21 - 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 + watch_streak=True, # If a streamer go online change the priority of streamers array and catch the watch screak. Issue #11 + chat=ChatPresence.ONLINE, # Join irc chat to increase watch-time [ALWAYS, NEVER, ONLINE, OFFLINE] bet=BetSettings( strategy=Strategy.SMART, # Choose you strategy! percentage=5, # Place the x% of your channel points @@ -491,6 +490,14 @@ Discord( | `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) | | `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) | | `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 | |-------------------- |----------------- |--------- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | @@ -507,6 +514,7 @@ Discord( - **MOST_VOTED**: Select the option most voted based on users count - **HIGH_ODDS**: Select the option with the highest odds - **PERCENTAGE**: Select the option with the highest percentage based on odds (It's the same that show Twitch) - Should be the same as select LOWEST_ODDS +- **SMART_MONEY**: Select the option with the highest points placed. [#331](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/issues/331) - **SMART**: If the majority in percent chose an option, then follow the other users, otherwise select the option with the highest odds ![Screenshot](https://raw.githubusercontent.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/master/assets/prediction.png) diff --git a/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py b/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py index af616ca..3ef72ac 100644 --- a/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py +++ b/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py @@ -12,7 +12,7 @@ from datetime import datetime 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, @@ -211,7 +211,7 @@ class TwitchChannelPointsMiner: 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(), @@ -329,7 +329,10 @@ class TwitchChannelPointsMiner: 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/__init__.py b/TwitchChannelPointsMiner/__init__.py index 01d5e0d..5d423f8 100644 --- a/TwitchChannelPointsMiner/__init__.py +++ b/TwitchChannelPointsMiner/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -__version__ = "2.0.8" +__version__ = "2.0.9" from .TwitchChannelPointsMiner import TwitchChannelPointsMiner __all__ = [ diff --git a/TwitchChannelPointsMiner/classes/Chat.py b/TwitchChannelPointsMiner/classes/Chat.py index 5e0272d..e120148 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 @@ from TwitchChannelPointsMiner.constants import IRC, IRC_PORT 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/Bet.py b/TwitchChannelPointsMiner/classes/entities/Bet.py index d3d750a..b2d9c59 100644 --- a/TwitchChannelPointsMiner/classes/entities/Bet.py +++ b/TwitchChannelPointsMiner/classes/entities/Bet.py @@ -11,6 +11,7 @@ class Strategy(Enum): MOST_VOTED = auto() HIGH_ODDS = auto() PERCENTAGE = auto() + SMART_MONEY = auto() SMART = auto() def __str__(self): @@ -268,6 +269,8 @@ class Bet(object): self.decision["choice"] = self.__return_choice(OutcomeKeys.ODDS) elif self.settings.strategy == Strategy.PERCENTAGE: self.decision["choice"] = self.__return_choice(OutcomeKeys.ODDS_PERCENTAGE) + elif self.settings.strategy == Strategy.SMART_MONEY: + self.decision["choice"] = self.__return_choice(OutcomeKeys.TOP_POINTS) elif self.settings.strategy == Strategy.SMART: difference = abs( self.outcomes[0][OutcomeKeys.PERCENTAGE_USERS] diff --git a/TwitchChannelPointsMiner/classes/entities/Streamer.py b/TwitchChannelPointsMiner/classes/entities/Streamer.py index 3c94a19..20a3577 100644 --- a/TwitchChannelPointsMiner/classes/entities/Streamer.py +++ b/TwitchChannelPointsMiner/classes/entities/Streamer.py @@ -5,7 +5,7 @@ import time 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 Events, Settings @@ -22,7 +22,7 @@ class StreamerSettings(object): "claim_drops", "watch_streak", "bet", - "join_chat", + "chat", ] def __init__( @@ -32,14 +32,14 @@ class StreamerSettings(object): 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 @@ class StreamerSettings(object): "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 @@ class Streamer(object): 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 @@ class Streamer(object): 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!", @@ -249,6 +252,22 @@ class Streamer(object): 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/TwitchChannelPointsMiner/logger.py b/TwitchChannelPointsMiner/logger.py index bf30e0c..ff40fca 100644 --- a/TwitchChannelPointsMiner/logger.py +++ b/TwitchChannelPointsMiner/logger.py @@ -123,29 +123,8 @@ 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 - - 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: - record.msg = ( - f"{self.settings.color_palette.get(record.event)}{record.msg}" - ) - - skip_discord = False if hasattr(record, "skip_discord") is False else True - - 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) + self.telegram(record) + self.discord(record) if self.settings.colored is True: record.msg = ( @@ -154,6 +133,27 @@ class GlobalFormatter(logging.Formatter): return super().format(record) + def telegram(self, record): + skip_telegram = False if hasattr(record, "skip_telegram") is False else True + + 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) + + def discord(self, record): + skip_discord = False if hasattr(record, "skip_discord") is False else True + + 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) + def configure_loggers(username, settings): if settings.colored is True: diff --git a/example.py b/example.py index c17d66b..9e4393a 100644 --- a/example.py +++ b/example.py @@ -4,6 +4,7 @@ import logging from colorama import Fore from TwitchChannelPointsMiner import TwitchChannelPointsMiner from TwitchChannelPointsMiner.logger import LoggerSettings, ColorPalette +from TwitchChannelPointsMiner.classes.Chat import ChatPresence from TwitchChannelPointsMiner.classes.Discord import Discord from TwitchChannelPointsMiner.classes.Telegram import Telegram from TwitchChannelPointsMiner.classes.Settings import Priority, Events, FollowersOrder @@ -46,8 +47,8 @@ twitch_miner = TwitchChannelPointsMiner( make_predictions=True, # If you want to Bet / Make prediction follow_raid=True, # Follow raid to obtain more points claim_drops=True, # We can't filter rewards base on stream. Set to False for skip viewing counter increase and you will never obtain a drop reward from this script. Issue #21 - 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 + watch_streak=True, # If a streamer go online change the priority of streamers array and catch the watch screak. Issue #11 + chat=ChatPresence.ONLINE, # Join irc chat to increase watch-time [ALWAYS, NEVER, ONLINE, OFFLINE] bet=BetSettings( strategy=Strategy.SMART, # Choose you strategy! percentage=5, # Place the x% of your channel points diff --git a/requirements.txt b/requirements.txt index 8249fc3..415deaf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ requests==2.25.1 websocket-client==1.0.1 browser_cookie3==0.12.1 -pillow==9.0.0 +pillow==9.0.1 python-dateutil==2.8.1 emoji==1.2.0 millify==0.1.1 diff --git a/setup.py b/setup.py index bb1e009..c9eff06 100644 --- a/setup.py +++ b/setup.py @@ -29,7 +29,7 @@ setuptools.setup( "requests==2.25.1", "websocket-client==1.0.1", "browser_cookie3==0.12.1", - "pillow==9.0.0", + "pillow==9.0.1", "python-dateutil==2.8.1", "emoji==1.2.0", "millify==0.1.1",