use Thread instead of Process. Get username and token from main classes. Rename some variables - See the PR #47 Reviews
This commit is contained in:
@@ -19,6 +19,7 @@ from TwitchChannelPointsMiner.classes.entities.Streamer import (
|
||||
from TwitchChannelPointsMiner.classes.Exceptions import StreamerDoesNotExistException
|
||||
from TwitchChannelPointsMiner.classes.Settings import Priority, Settings
|
||||
from TwitchChannelPointsMiner.classes.Twitch import Twitch
|
||||
from TwitchChannelPointsMiner.classes.TwitchChat import TwitchChat
|
||||
from TwitchChannelPointsMiner.classes.WebSocketsPool import WebSocketsPool
|
||||
from TwitchChannelPointsMiner.logger import LoggerSettings, configure_loggers
|
||||
from TwitchChannelPointsMiner.utils import (
|
||||
@@ -184,6 +185,12 @@ class TwitchChannelPointsMiner:
|
||||
self.twitch.viewer_is_mod(streamer)
|
||||
if streamer.viewer_is_mod is True:
|
||||
streamer.settings.make_predictions = False
|
||||
if streamer.settings.join_chat is True:
|
||||
streamer.irc_chat = TwitchChat(
|
||||
self.username,
|
||||
self.twitch.twitch_login.get_auth_token(),
|
||||
streamer.username,
|
||||
)
|
||||
|
||||
self.original_streamers = copy.deepcopy(self.streamers)
|
||||
|
||||
@@ -268,7 +275,7 @@ class TwitchChannelPointsMiner:
|
||||
logger.info("CTRL+C Detected! Please wait just a moment!")
|
||||
|
||||
for streamer in self.streamers:
|
||||
if streamer is not None:
|
||||
if streamer.irc_chat is not None:
|
||||
streamer.leave_chat()
|
||||
|
||||
self.running = self.twitch.running = False
|
||||
|
||||
@@ -1,22 +1,12 @@
|
||||
import logging
|
||||
from multiprocessing import Process
|
||||
from threading import Thread
|
||||
|
||||
from TwitchChannelPointsMiner.classes.entities.Chat import Chat
|
||||
|
||||
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):
|
||||
class TwitchChat(Thread):
|
||||
def __deepcopy__(self, memo):
|
||||
return None
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import json
|
||||
import logging
|
||||
import random
|
||||
import threading
|
||||
import time
|
||||
from threading import Thread, Timer
|
||||
|
||||
from dateutil import parser
|
||||
|
||||
@@ -67,7 +67,7 @@ class WebSocketsPool:
|
||||
)
|
||||
|
||||
def __start(self, index):
|
||||
thread_ws = threading.Thread(target=lambda: self.ws[index].run_forever())
|
||||
thread_ws = Thread(target=lambda: self.ws[index].run_forever())
|
||||
thread_ws.daemon = True
|
||||
thread_ws.name = f"WebSocket #{self.ws[index].index}"
|
||||
thread_ws.start()
|
||||
@@ -99,7 +99,7 @@ class WebSocketsPool:
|
||||
)
|
||||
WebSocketsPool.handle_reconnection(ws)
|
||||
|
||||
thread_ws = threading.Thread(target=run)
|
||||
thread_ws = Thread(target=run)
|
||||
thread_ws.daemon = True
|
||||
thread_ws.start()
|
||||
|
||||
@@ -261,7 +261,7 @@ class WebSocketsPool:
|
||||
current_tmsp
|
||||
)
|
||||
|
||||
place_bet_thread = threading.Timer(
|
||||
place_bet_thread = Timer(
|
||||
start_after,
|
||||
ws.twitch.make_predictions,
|
||||
(ws.events_predictions[event_id],),
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import irc.bot
|
||||
|
||||
from TwitchChannelPointsMiner.constants import IRC, IRC_PORT
|
||||
|
||||
|
||||
class Chat(irc.bot.SingleServerIRCBot):
|
||||
def __init__(self, username, token, channel):
|
||||
@@ -7,10 +9,8 @@ class Chat(irc.bot.SingleServerIRCBot):
|
||||
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
|
||||
self, [(IRC, IRC_PORT, "oauth:" + token)], username, username
|
||||
)
|
||||
|
||||
def on_welcome(self, c, e):
|
||||
|
||||
@@ -4,7 +4,6 @@ import time
|
||||
from TwitchChannelPointsMiner.classes.entities.Bet import BetSettings
|
||||
from TwitchChannelPointsMiner.classes.entities.Stream import Stream
|
||||
from TwitchChannelPointsMiner.classes.Settings import Settings
|
||||
from TwitchChannelPointsMiner.classes.TwitchChat import TwitchChat
|
||||
from TwitchChannelPointsMiner.constants import URL
|
||||
from TwitchChannelPointsMiner.utils import _millify
|
||||
|
||||
@@ -121,7 +120,6 @@ class Streamer(object):
|
||||
self.online_at = time.time()
|
||||
self.is_online = True
|
||||
self.stream.init_watch_streak()
|
||||
|
||||
self.join_chat()
|
||||
|
||||
logger.info(
|
||||
@@ -153,20 +151,6 @@ 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.irc_chat is not None:
|
||||
self.irc_chat.terminate()
|
||||
|
||||
def join_chat(self):
|
||||
if self.settings.chat_client is not None:
|
||||
self.irc_chat = TwitchChat(
|
||||
self.settings.chat_client.username,
|
||||
self.settings.chat_client.token,
|
||||
self.username,
|
||||
)
|
||||
logger.info(f"Connecting to {self.username}'s chat!")
|
||||
self.irc_chat.start()
|
||||
|
||||
def drops_condition(self):
|
||||
return (
|
||||
self.settings.claim_drops is True
|
||||
@@ -174,3 +158,12 @@ class Streamer(object):
|
||||
and self.stream.drops_tags is True
|
||||
and self.stream.campaigns_ids != []
|
||||
)
|
||||
|
||||
def leave_chat(self):
|
||||
if self.settings.join_chat is True and self.irc_chat is not None:
|
||||
self.irc_chat.terminate()
|
||||
|
||||
def join_chat(self):
|
||||
if self.settings.join_chat is True and self.irc_chat is not None:
|
||||
logger.info(f"Connecting to {self.username}'s chat!")
|
||||
self.irc_chat.start()
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# Twitch endpoints
|
||||
URL = "https://www.twitch.tv"
|
||||
API = "https://api.twitch.tv"
|
||||
IRC = "irc.chat.twitch.tv"
|
||||
IRC_PORT = 6667
|
||||
WEBSOCKET = "wss://pubsub-edge.twitch.tv/v1"
|
||||
CLIENT_ID = "kimne78kx3ncx6brgo4mv6wki5h1ko"
|
||||
DROP_ID = "c2542d6d-cd10-4532-919b-3d19f30a768b"
|
||||
|
||||
Reference in New Issue
Block a user