# Path: constants/clientPackets.py
# def userActionChange(stream):
# def userStatsRequest(stream):
# def userPanelRequest(stream):
# def sendPublicMessage(stream):
# def sendPrivateMessage(stream):
# def setAwayMessage(stream):
# def channelJoin(stream):
# def channelPart(stream):
# def addRemoveFriend(stream):
# def startSpectating(stream):
# def matchSettings(stream):
# def createMatch(stream):
# def changeMatchSettings(stream):
# def changeSlot(stream):
# def joinMatch(stream):
# def changeMods(stream):
# def lockSlot(stream):
# def transferHost(stream):
# def matchInvite(stream):
# def matchFrames(stream):
# def tournamentMatchInfoRequest(stream):
# def tournamentJoinMatchChannel(stream):
# def tournamentLeaveMatchChannel(stream):
# 
# 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: objects/glob.py
# 		VERSION = f.read().strip()
# 	VERSION = "Unknown"
# DATADOG_PREFIX = "peppy"


from common.log import logUtils as log
from constants import clientPackets
from constants import exceptions
from objects import glob

def handle(userToken, packetData):
	try:
		# Start spectating packet
		packetData = clientPackets.startSpectating(packetData)

		# If the user id is less than 0, treat this as a stop spectating packet
		if packetData["userID"] < 0:
			userToken.stopSpectating()
			return

		# Get host token
		targetToken = glob.tokens.getTokenFromUserID(packetData["userID"])
		if targetToken is None:

# Path: constants/clientPackets.py
# def userActionChange(stream):
# def userStatsRequest(stream):
# def userPanelRequest(stream):
# def sendPublicMessage(stream):
# def sendPrivateMessage(stream):
# def setAwayMessage(stream):
# def channelJoin(stream):
# def channelPart(stream):
# def addRemoveFriend(stream):
# def startSpectating(stream):
# def matchSettings(stream):
# def createMatch(stream):
# def changeMatchSettings(stream):
# def changeSlot(stream):
# def joinMatch(stream):
# def changeMods(stream):
# def lockSlot(stream):
# def transferHost(stream):
# def matchInvite(stream):
# def matchFrames(stream):
# def tournamentMatchInfoRequest(stream):
# def tournamentJoinMatchChannel(stream):
# def tournamentLeaveMatchChannel(stream):
# 
# 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: objects/glob.py
# 		VERSION = f.read().strip()
# 	VERSION = "Unknown"
# DATADOG_PREFIX = "peppy"


# Path: events/startSpectatingEvent.py
from common.log import logUtils as log
from constants import clientPackets
from constants import exceptions
from objects import glob


def handle(userToken, packetData):
	try:
		# Start spectating packet
		packetData = clientPackets.startSpectating(packetData)

		# If the user id is less than 0, treat this as a stop spectating packet
		if packetData["userID"] < 0:
			userToken.stopSpectating()
			return

		# Get host token
		targetToken = glob.tokens.getTokenFromUserID(packetData["userID"])
		if targetToken is None:

			raise exceptions.tokenNotFoundException