add irc chat client
list user as viewer in selected chat viewtime increases while connected
This commit is contained in:
@@ -260,6 +260,10 @@ class TwitchChannelPointsMiner:
|
||||
if self.twitch_browser is not None:
|
||||
self.twitch_browser.browser.quit()
|
||||
|
||||
for streamer in self.streamers:
|
||||
if(streamer is not None):
|
||||
streamer.leave_chat()
|
||||
|
||||
self.running = self.twitch.running = False
|
||||
self.ws_pool.end()
|
||||
|
||||
|
||||
34
TwitchChannelPointsMiner/classes/TwitchChat.py
Normal file
34
TwitchChannelPointsMiner/classes/TwitchChat.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from TwitchChannelPointsMiner.classes.entities.Chat import Chat
|
||||
|
||||
import requests
|
||||
from multiprocessing import Process
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class ChatSettings(object):
|
||||
def __init__(
|
||||
self,
|
||||
username: str = None,
|
||||
token: str = None,
|
||||
):
|
||||
self.username = username
|
||||
self.token = token
|
||||
|
||||
class TwitchChat(Process):
|
||||
def __deepcopy__(self, memo):
|
||||
return None
|
||||
|
||||
def __init__(self, username, token, channel):
|
||||
super(TwitchChat, self).__init__()
|
||||
self.token = token
|
||||
self.username = username
|
||||
self.channel = channel
|
||||
|
||||
def run(self):
|
||||
# Create IRC bot connection
|
||||
try:
|
||||
IRC = Chat( self.username, self.token, self.channel )
|
||||
IRC.start()
|
||||
except KeyboardInterrupt:
|
||||
None # dont handle KeyboardInterruption here
|
||||
18
TwitchChannelPointsMiner/classes/entities/Chat.py
Normal file
18
TwitchChannelPointsMiner/classes/entities/Chat.py
Normal file
@@ -0,0 +1,18 @@
|
||||
|
||||
import irc.bot
|
||||
import requests
|
||||
|
||||
class Chat(irc.bot.SingleServerIRCBot):
|
||||
def __init__(self, username, token, channel):
|
||||
self.token = token
|
||||
self.channel = '#' + channel
|
||||
|
||||
# Create IRC bot connection
|
||||
server = 'irc.chat.twitch.tv'
|
||||
port = 6667
|
||||
irc.bot.SingleServerIRCBot.__init__(self, [(server, port, 'oauth:'+token)], username, username)
|
||||
|
||||
|
||||
def on_welcome(self, c, e):
|
||||
# You must request specific capabilities before you can use them
|
||||
c.join(self.channel)
|
||||
@@ -1,6 +1,7 @@
|
||||
import logging
|
||||
import time
|
||||
|
||||
from TwitchChannelPointsMiner.classes.TwitchChat import TwitchChat, ChatSettings
|
||||
from TwitchChannelPointsMiner.classes.entities.Bet import BetSettings
|
||||
from TwitchChannelPointsMiner.classes.entities.Stream import Stream
|
||||
from TwitchChannelPointsMiner.classes.Settings import Settings
|
||||
@@ -9,7 +10,6 @@ from TwitchChannelPointsMiner.utils import _millify
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class StreamerSettings(object):
|
||||
def __init__(
|
||||
self,
|
||||
@@ -18,12 +18,14 @@ class StreamerSettings(object):
|
||||
claim_drops: bool = None,
|
||||
watch_streak: bool = None,
|
||||
bet: BetSettings = None,
|
||||
chat_client: ChatSettings = 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.chat_client = chat_client
|
||||
|
||||
def default(self):
|
||||
for name in ["make_predictions", "follow_raid", "claim_drops", "watch_streak"]:
|
||||
@@ -48,6 +50,7 @@ class Streamer(object):
|
||||
self.channel_points = 0
|
||||
self.minute_watched_requests = None
|
||||
self.viewer_is_mod = False
|
||||
self.chat = None
|
||||
|
||||
self.stream = Stream()
|
||||
|
||||
@@ -71,6 +74,7 @@ class Streamer(object):
|
||||
if self.is_online is True:
|
||||
self.offline_at = time.time()
|
||||
self.is_online = False
|
||||
self.leave_chat()
|
||||
|
||||
logger.info(f"{self} is Offline!", extra={"emoji": ":sleeping:"})
|
||||
|
||||
@@ -81,6 +85,7 @@ class Streamer(object):
|
||||
self.stream.init_watch_streak()
|
||||
|
||||
logger.info(f"{self} is Online!", extra={"emoji": ":partying_face:"})
|
||||
self.join_chat()
|
||||
|
||||
def print_history(self):
|
||||
return ", ".join(
|
||||
@@ -101,3 +106,13 @@ class Streamer(object):
|
||||
|
||||
def stream_up_elapsed(self):
|
||||
return self.stream_up == 0 or ((time.time() - self.stream_up) > 120)
|
||||
|
||||
def leave_chat(self):
|
||||
if(self.chat is not None):
|
||||
self.chat.terminate()
|
||||
|
||||
def join_chat(self):
|
||||
if(self.settings.chat_client is not None):
|
||||
self.chat = TwitchChat(self.settings.chat_client.username, self.settings.chat_client.token, self.username)
|
||||
logger.info(f"Connecting to {self.username}'s chat!")
|
||||
self.chat.start()
|
||||
|
||||
105
example.py
105
example.py
@@ -6,57 +6,66 @@ from TwitchChannelPointsMiner.logger import LoggerSettings
|
||||
from TwitchChannelPointsMiner.classes.entities.Bet import Strategy, BetSettings
|
||||
from TwitchChannelPointsMiner.classes.entities.Streamer import Streamer, StreamerSettings
|
||||
from TwitchChannelPointsMiner.classes.TwitchBrowser import Browser, BrowserSettings
|
||||
from TwitchChannelPointsMiner.classes.TwitchChat import TwitchChat, ChatSettings
|
||||
|
||||
twitch_miner = TwitchChannelPointsMiner(
|
||||
username="your-twitch-username",
|
||||
claim_drops_startup=False, # If you want to auto claim all drops from Twitch inventory on startup
|
||||
logger_settings=LoggerSettings(
|
||||
save=True, # If you want to save logs in 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 to print emoji. Set to false if you have a problem
|
||||
less=False # If you think that the logs are too much verborse set this to True
|
||||
),
|
||||
browser_settings=BrowserSettings(
|
||||
browser=Browser.FIREFOX, # Choose if you want to use Chrome or Firefox as browser
|
||||
show=False, # Show the browser during bet else headless mode
|
||||
do_screenshot=False, # Do screenshot during the bet
|
||||
),
|
||||
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 priotiry of streamers array and catch the watch screak. Issue #11
|
||||
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
|
||||
def main():
|
||||
twitch_miner = TwitchChannelPointsMiner(
|
||||
username="your-twitch-username",
|
||||
claim_drops_startup=False, # If you want to auto claim all drops from Twitch inventory on startup
|
||||
logger_settings=LoggerSettings(
|
||||
save=True, # If you want to save logs in 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 to print emoji. Set to false if you have a problem
|
||||
less=False # If you think that the logs are too much verborse set this to True
|
||||
),
|
||||
browser_settings=BrowserSettings(
|
||||
browser=Browser.FIREFOX, # Choose if you want to use Chrome or Firefox as browser
|
||||
show=False, # Show the browser during bet else headless mode
|
||||
do_screenshot=False, # Do screenshot during the bet
|
||||
),
|
||||
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 priotiry of streamers array and catch the watch screak. Issue #11
|
||||
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
|
||||
),
|
||||
chat_client=ChatSettings( # Can be removed for mining channelpoints only
|
||||
username="your-twitch-username",
|
||||
token="oauth-token-without-prefix", # generate on https://twitchapps.com/tmi/ - without "oauth:" prefix!
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
# You can customize the settings for each streamer. If not settings was provided the script will use the streamer_settings from TwitchChannelPointsMiner.
|
||||
# If no streamer_settings provided in TwitchChannelPointsMiner the script will use default settings.
|
||||
# The streamers array can be a String -> username or Streamer instance.
|
||||
# You can customize the settings for each streamer. If not settings was provided the script will use the streamer_settings from TwitchChannelPointsMiner.
|
||||
# If no streamer_settings provided in TwitchChannelPointsMiner the script will use default settings.
|
||||
# The streamers array can be a String -> username or Streamer instance.
|
||||
|
||||
# The settings priority are: settings in mine function, settings in TwitchChannelPointsMiner instance, default settings.
|
||||
# For example if in the mine function you don't provide any value for 'make_prediction' but you have set it on TwitchChannelPointsMiner instance the script will take the value from here.
|
||||
# If you haven't set any value even in the instance the default one will be used
|
||||
# The settings priority are: settings in mine function, settings in TwitchChannelPointsMiner instance, default settings.
|
||||
# For example if in the mine function you don't provide any value for 'make_prediction' but you have set it on TwitchChannelPointsMiner instance the script will take the value from here.
|
||||
# If you haven't set any value even in the instance the default one will be used
|
||||
|
||||
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 , percentage_gap=20 , max_points=234 ) )),
|
||||
Streamer("streamer-username02", settings=StreamerSettings(make_predictions=False , follow_raid=True , claim_drops=False , bet=BetSettings(strategy=Strategy.PERCENTAGE , percentage=5 , percentage_gap=20 , max_points=1234 ) )),
|
||||
Streamer("streamer-username03", settings=StreamerSettings(make_predictions=True , follow_raid=False , watch_streak=True , bet=BetSettings(strategy=Strategy.SMART , percentage=5 , percentage_gap=30 , max_points=50000 ) )),
|
||||
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 , percentage_gap=20 , max_points=90 ) )),
|
||||
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 (unable to set custom settings for you followers list)
|
||||
)
|
||||
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 , percentage_gap=20 , max_points=234 ) )),
|
||||
Streamer("streamer-username02", settings=StreamerSettings(make_predictions=False , follow_raid=True , claim_drops=False , bet=BetSettings(strategy=Strategy.PERCENTAGE , percentage=5 , percentage_gap=20 , max_points=1234 ) )),
|
||||
Streamer("streamer-username03", settings=StreamerSettings(make_predictions=True , follow_raid=False , watch_streak=True , bet=BetSettings(strategy=Strategy.SMART , percentage=5 , percentage_gap=30 , max_points=50000 ) )),
|
||||
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 , percentage_gap=20 , max_points=90 ) )),
|
||||
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 (unable to set custom settings for you followers list)
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -7,3 +7,4 @@ python-dateutil
|
||||
emoji
|
||||
millify
|
||||
pre-commit
|
||||
irc
|
||||
|
||||
Reference in New Issue
Block a user