Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace join_chat boolean with chat: ChatPresence #253

Merged
merged 12 commits into from
Mar 7, 2022
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -188,6 +187,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
Expand Down Expand Up @@ -230,8 +230,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
Expand Down Expand Up @@ -491,6 +491,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 |
|-------------------- |----------------- |--------- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
Expand Down
9 changes: 6 additions & 3 deletions TwitchChannelPointsMiner/TwitchChannelPointsMiner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -203,7 +203,7 @@ def run(
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(),
Expand Down Expand Up @@ -321,7 +321,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()
Expand Down
11 changes: 11 additions & 0 deletions TwitchChannelPointsMiner/classes/Chat.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import time
from enum import Enum, auto
from threading import Thread

from irc.bot import SingleServerIRCBot
Expand All @@ -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
Expand Down
39 changes: 29 additions & 10 deletions TwitchChannelPointsMiner/classes/entities/Streamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 Events, Settings
Expand All @@ -22,7 +22,7 @@ class StreamerSettings(object):
"claim_drops",
"watch_streak",
"bet",
"join_chat",
"chat",
]

def __init__(
Expand All @@ -32,30 +32,31 @@ 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 [
"make_predictions",
"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):
Expand Down Expand Up @@ -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!",
Expand All @@ -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!",
Expand Down Expand Up @@ -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()
5 changes: 3 additions & 2 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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
Expand Down Expand Up @@ -46,8 +47,8 @@
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
Expand Down