ChatPresence enum. Ability to manage the presence in chat (irc) with ALWAYS, NEVER, ONLINE (ONLY), OFFLINE (ONLY)

This commit is contained in:
Alessandro Maggio
2021-08-16 22:36:28 +02:00
parent 809c4c9e7e
commit 0bb0876f74
5 changed files with 57 additions and 20 deletions

View File

@@ -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 |

View File

@@ -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,
@@ -180,7 +180,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(),

View File

@@ -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

View File

@@ -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 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!",
@@ -238,7 +241,7 @@ class Streamer(object):
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 @@ 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()

View File

@@ -5,6 +5,7 @@ from colorama import Fore
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 @@ 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