# 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 hashlib
import re
import select
import socket
import sys
import time
import traceback
import raven
from common.log import logUtils as log
from common.ripple import userUtils
from helpers import chatHelper as chat
from objects import glob
		except socket.error as x:
			self.disconnect(str(x))

	def checkAlive(self):
		"""
		Check if this client is still connected.
		If the client is dead, disconnect it.

		:return:
		"""
		now = time.time()
		if self.__timestamp + 180 < now:
			self.disconnect("ping timeout")
			return
		if not self.__sentPing and self.__timestamp + 90 < now:
			if self.__handleCommand == self.mainHandler:
				# Registered.
				self.message("PING :{}".format(self.server.host))
				self.__sentPing = True
			else:
				# Not registered.
				self.disconnect("ping timeout")


	def sendLusers(self):
		"""
		Send lusers response to this client

		:return:
		"""

# 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: irc/ircserver.py
import hashlib
import re
import select
import socket
import sys
import time
import traceback
import raven
from common.log import logUtils as log
from common.ripple import userUtils
from helpers import chatHelper as chat
from objects import glob

		except socket.error as x:
			self.disconnect(str(x))

	def checkAlive(self):
		"""
		Check if this client is still connected.
		If the client is dead, disconnect it.

		:return:
		"""
		now = time.time()
		if self.__timestamp + 180 < now:
			self.disconnect("ping timeout")
			return
		if not self.__sentPing and self.__timestamp + 90 < now:
			if self.__handleCommand == self.mainHandler:
				# Registered.
				self.message("PING :{}".format(self.server.host))
				self.__sentPing = True
			else:
				# Not registered.
				self.disconnect("ping timeout")


	def sendLusers(self):
		"""
		Send lusers response to this client

		:return:
		"""

		self.replyCode(251, "There are {} users and 0 services on 1 server".format(len(glob.tokens.tokens)))