# Path: constants/exceptions.py
# class loginFailedException(Exception):
# class loginBannedException(Exception):
# class tokenNotFoundException(Exception):
# class channelNoPermissionsException(Exception):
# class channelUnknownException(Exception):
# class channelModeratedException(Exception):
# class noAdminException(Exception):
# class commandSyntaxException(Exception):
# class banchoConfigErrorException(Exception):
# class banchoMaintenanceException(Exception):
# class moderatedPMException(Exception):
# class userNotFoundException(Exception):
# class alreadyConnectedException(Exception):
# class stopSpectating(Exception):
# class matchWrongPasswordException(Exception):
# class matchNotFoundException(Exception):
# class matchJoinErrorException(Exception):
# class matchCreateError(Exception):
# class banchoRestartingException(Exception):
# class apiException(Exception):
# class invalidArgumentsException(Exception):
# class messageTooLongWarnException(Exception):
# class messageTooLongException(Exception):
# class userSilencedException(Exception):
# class need2FAException(Exception):
# class userRestrictedException(Exception):
# class haxException(Exception):
# class forceUpdateException(Exception):
# class loginLockedException(Exception):
# class unknownStreamException(Exception):
# class userTournamentException(Exception):
# class userAlreadyInChannelException(Exception):
# class userNotInChannelException(Exception):
# class missingReportInfoException(Exception):
# class invalidUserException(Exception):
# class wrongChannelException(Exception):
# class periodicLoopException(Exception):
# 
# Path: constants/serverPackets.py
# def loginFailed():
# def forceUpdate():
# def loginBanned():
# def loginLocked():
# def loginError():
# def needSupporter():
# def needVerification():
# def userID(uid):
# def silenceEndTime(seconds):
# def protocolVersion(version = 19):
# def mainMenuIcon(icon):
# def userSupporterGMT(supporter, GMT, tournamentStaff):
# def friendList(userID):
# def onlineUsers():
# def userLogout(userID):
# def userPanel(userID, force = False):
# def userStats(userID, force = False):
# def sendMessage(fro, to, message):
# def channelJoinSuccess(userID, chan):
# def channelInfo(chan):
# def channelInfoEnd():
# def channelKicked(chan):
# def userSilenced(userID):
# def addSpectator(userID):
# def removeSpectator(userID):
# def spectatorFrames(data):
# def noSongSpectator(userID):
# def fellowSpectatorJoined(userID):
# def fellowSpectatorLeft(userID):
# def createMatch(matchID):
# def updateMatch(matchID, censored = False):
# def matchStart(matchID):
# def disposeMatch(matchID):
# def matchJoinSuccess(matchID):
# def matchJoinFail():
# def changeMatchPassword(newPassword):
# def allPlayersLoaded():
# def playerSkipped(userID):
# def allPlayersSkipped():
# def matchFrames(slotID, data):
# def matchComplete():
# def playerFailed(slotID):
# def matchTransferHost():
# def matchAbort():
# def switchServer(address):
# def notification(message):
# def banchoRestart(msUntilReconnection):
# def rtx(message):
# 
# Path: events/logoutEvent.py
# def handle(userToken, _=None, deleteToken=True):
# 
# Path: helpers/chatHelper.py
# def joinChannel(userID = 0, channel = "", token = None, toIRC = True, force=False):
# def partChannel(userID = 0, channel = "", token = None, toIRC = True, kick = False, force=False):
# def sendMessage(fro = "", to = "", message = "", token = None, toIRC = True):
# def fixUsernameForBancho(username):
# def fixUsernameForIRC(username):
# def IRCConnect(username):
# def IRCDisconnect(username):
# def IRCJoinChannel(username, channel):
# def IRCPartChannel(username, channel):
# def IRCAway(username, message):
# 
# Path: objects/glob.py
# 		VERSION = f.read().strip()
# 	VERSION = "Unknown"
# DATADOG_PREFIX = "peppy"


import threading
import time
import uuid
from common.constants import gameModes, actions
from common.log import logUtils as log
from common.ripple import userUtils
from constants import exceptions
from constants import serverPackets
from events import logoutEvent
from helpers import chatHelper as chat
from objects import glob
		"""
		Set the spectating user to userID, join spectator stream and chat channel
		and send required packets to host

		:param host: host osuToken object
		"""
		try:
			self._spectLock.acquire()

			# Stop spectating old client
			self.stopSpectating()

			# Set new spectator host
			self.spectating = host.token
			self.spectatingUserID = host.userID

			# Add us to host's spectator list
			host.spectators.append(self.token)

			# Create and join spectator stream
			streamName = "spect/{}".format(host.userID)
			glob.streams.add(streamName)
			self.joinStream(streamName)
			host.joinStream(streamName)

			# Send spectator join packet to host
			host.enqueue(serverPackets.addSpectator(self.userID))

			# Create and join #spectator (#spect_userid) channel
			glob.channels.addTempChannel("#spect_{}".format(host.userID))

# Path: constants/exceptions.py
# class loginFailedException(Exception):
# class loginBannedException(Exception):
# class tokenNotFoundException(Exception):
# class channelNoPermissionsException(Exception):
# class channelUnknownException(Exception):
# class channelModeratedException(Exception):
# class noAdminException(Exception):
# class commandSyntaxException(Exception):
# class banchoConfigErrorException(Exception):
# class banchoMaintenanceException(Exception):
# class moderatedPMException(Exception):
# class userNotFoundException(Exception):
# class alreadyConnectedException(Exception):
# class stopSpectating(Exception):
# class matchWrongPasswordException(Exception):
# class matchNotFoundException(Exception):
# class matchJoinErrorException(Exception):
# class matchCreateError(Exception):
# class banchoRestartingException(Exception):
# class apiException(Exception):
# class invalidArgumentsException(Exception):
# class messageTooLongWarnException(Exception):
# class messageTooLongException(Exception):
# class userSilencedException(Exception):
# class need2FAException(Exception):
# class userRestrictedException(Exception):
# class haxException(Exception):
# class forceUpdateException(Exception):
# class loginLockedException(Exception):
# class unknownStreamException(Exception):
# class userTournamentException(Exception):
# class userAlreadyInChannelException(Exception):
# class userNotInChannelException(Exception):
# class missingReportInfoException(Exception):
# class invalidUserException(Exception):
# class wrongChannelException(Exception):
# class periodicLoopException(Exception):
# 
# Path: constants/serverPackets.py
# def loginFailed():
# def forceUpdate():
# def loginBanned():
# def loginLocked():
# def loginError():
# def needSupporter():
# def needVerification():
# def userID(uid):
# def silenceEndTime(seconds):
# def protocolVersion(version = 19):
# def mainMenuIcon(icon):
# def userSupporterGMT(supporter, GMT, tournamentStaff):
# def friendList(userID):
# def onlineUsers():
# def userLogout(userID):
# def userPanel(userID, force = False):
# def userStats(userID, force = False):
# def sendMessage(fro, to, message):
# def channelJoinSuccess(userID, chan):
# def channelInfo(chan):
# def channelInfoEnd():
# def channelKicked(chan):
# def userSilenced(userID):
# def addSpectator(userID):
# def removeSpectator(userID):
# def spectatorFrames(data):
# def noSongSpectator(userID):
# def fellowSpectatorJoined(userID):
# def fellowSpectatorLeft(userID):
# def createMatch(matchID):
# def updateMatch(matchID, censored = False):
# def matchStart(matchID):
# def disposeMatch(matchID):
# def matchJoinSuccess(matchID):
# def matchJoinFail():
# def changeMatchPassword(newPassword):
# def allPlayersLoaded():
# def playerSkipped(userID):
# def allPlayersSkipped():
# def matchFrames(slotID, data):
# def matchComplete():
# def playerFailed(slotID):
# def matchTransferHost():
# def matchAbort():
# def switchServer(address):
# def notification(message):
# def banchoRestart(msUntilReconnection):
# def rtx(message):
# 
# Path: events/logoutEvent.py
# def handle(userToken, _=None, deleteToken=True):
# 
# Path: helpers/chatHelper.py
# def joinChannel(userID = 0, channel = "", token = None, toIRC = True, force=False):
# def partChannel(userID = 0, channel = "", token = None, toIRC = True, kick = False, force=False):
# def sendMessage(fro = "", to = "", message = "", token = None, toIRC = True):
# def fixUsernameForBancho(username):
# def fixUsernameForIRC(username):
# def IRCConnect(username):
# def IRCDisconnect(username):
# def IRCJoinChannel(username, channel):
# def IRCPartChannel(username, channel):
# def IRCAway(username, message):
# 
# Path: objects/glob.py
# 		VERSION = f.read().strip()
# 	VERSION = "Unknown"
# DATADOG_PREFIX = "peppy"


# Path: objects/osuToken.py
import threading
import time
import uuid
from common.constants import gameModes, actions
from common.log import logUtils as log
from common.ripple import userUtils
from constants import exceptions
from constants import serverPackets
from events import logoutEvent
from helpers import chatHelper as chat
from objects import glob

		"""
		Set the spectating user to userID, join spectator stream and chat channel
		and send required packets to host

		:param host: host osuToken object
		"""
		try:
			self._spectLock.acquire()

			# Stop spectating old client
			self.stopSpectating()

			# Set new spectator host
			self.spectating = host.token
			self.spectatingUserID = host.userID

			# Add us to host's spectator list
			host.spectators.append(self.token)

			# Create and join spectator stream
			streamName = "spect/{}".format(host.userID)
			glob.streams.add(streamName)
			self.joinStream(streamName)
			host.joinStream(streamName)

			# Send spectator join packet to host
			host.enqueue(serverPackets.addSpectator(self.userID))

			# Create and join #spectator (#spect_userid) channel
			glob.channels.addTempChannel("#spect_{}".format(host.userID))

			chat.joinChannel(token=self, channel="#spect_{}".format(host.userID), force=True)