# Path: objects/channel.py
# class channel:
# 	def __init__(self, name, description, publicRead, publicWrite, temp, hidden):
# 		"""
# 		Create a new chat channel object
# 
# 		:param name: channel name
# 		:param description: channel description
# 		:param publicRead: if True, this channel can be read by everyone. If False, it can be read only by mods/admins
# 		:param publicWrite: same as public read, but regards writing permissions
# 		:param temp: if True, this channel will be deleted when there's no one in this channel
# 		:param hidden: if True, thic channel won't be shown in channels list
# 		"""
# 		self.name = name
# 		self.description = description
# 		self.publicRead = publicRead
# 		self.publicWrite = publicWrite
# 		self.moderated = False
# 		self.temp = temp
# 		self.hidden = hidden
# 
# 		# Make Foka join the channel
# 		fokaToken = glob.tokens.getTokenFromUserID(999)
# 		if fokaToken is not None:
# 			try:
# 				fokaToken.joinChannel(self)
# 			except exceptions.userAlreadyInChannelException:
# 				logging.warning("FokaBot has already joined channel {}".format(self.name))
# 
# 	@property
# 	def isSpecial(self):
# 		return any(self.name.startswith(x) for x in ("#spect_", "#multi_"))
# 
# 	@property
# 	def clientName(self):
# 		if self.name.startswith("#spect_"):
# 			return "#spectator"
# 		elif self.name.startswith("#multi_"):
# 			return "#multiplayer"
# 		return self.name
# 
# Path: objects/glob.py
# 		VERSION = f.read().strip()
# 	VERSION = "Unknown"
# DATADOG_PREFIX = "peppy"
# 
# 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):


from common.log import logUtils as log
from objects import channel
from objects import glob
from helpers import chatHelper as chat
		self.channels = {}

	def loadChannels(self):
		"""
		Load chat channels from db and add them to channels list
		:return:
		"""
		# Get channels from DB
		channels = glob.db.fetchAll("SELECT * FROM bancho_channels")

		# Add each channel if needed
		for i in channels:
			if i["name"] not in self.channels:
				publicRead = True if i["public_read"] == 1 else False
				publicWrite = True if i["public_write"] == 1 else False
				self.addChannel(i["name"], i["description"], publicRead, publicWrite)

	def addChannel(self, name, description, publicRead, publicWrite, temp = False, hidden = False):
		"""
		Add a channel to channels list

		:param name: channel name
		:param description: channel description
		:param publicRead: if True, this channel can be read by everyone. If False, it can be read only by mods/admins
		:param publicWrite: same as public read, but regards writing permissions
		:param temp: if True, this channel will be deleted when there's no one in this channel
		:param hidden: if True, thic channel won't be shown in channels list
		:return:
		"""
		glob.streams.add("chat/{}".format(name))

# Path: objects/channel.py
# class channel:
# 	def __init__(self, name, description, publicRead, publicWrite, temp, hidden):
# 		"""
# 		Create a new chat channel object
# 
# 		:param name: channel name
# 		:param description: channel description
# 		:param publicRead: if True, this channel can be read by everyone. If False, it can be read only by mods/admins
# 		:param publicWrite: same as public read, but regards writing permissions
# 		:param temp: if True, this channel will be deleted when there's no one in this channel
# 		:param hidden: if True, thic channel won't be shown in channels list
# 		"""
# 		self.name = name
# 		self.description = description
# 		self.publicRead = publicRead
# 		self.publicWrite = publicWrite
# 		self.moderated = False
# 		self.temp = temp
# 		self.hidden = hidden
# 
# 		# Make Foka join the channel
# 		fokaToken = glob.tokens.getTokenFromUserID(999)
# 		if fokaToken is not None:
# 			try:
# 				fokaToken.joinChannel(self)
# 			except exceptions.userAlreadyInChannelException:
# 				logging.warning("FokaBot has already joined channel {}".format(self.name))
# 
# 	@property
# 	def isSpecial(self):
# 		return any(self.name.startswith(x) for x in ("#spect_", "#multi_"))
# 
# 	@property
# 	def clientName(self):
# 		if self.name.startswith("#spect_"):
# 			return "#spectator"
# 		elif self.name.startswith("#multi_"):
# 			return "#multiplayer"
# 		return self.name
# 
# Path: objects/glob.py
# 		VERSION = f.read().strip()
# 	VERSION = "Unknown"
# DATADOG_PREFIX = "peppy"
# 
# 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/channelList.py
from common.log import logUtils as log
from objects import channel
from objects import glob
from helpers import chatHelper as chat

		self.channels = {}

	def loadChannels(self):
		"""
		Load chat channels from db and add them to channels list
		:return:
		"""
		# Get channels from DB
		channels = glob.db.fetchAll("SELECT * FROM bancho_channels")

		# Add each channel if needed
		for i in channels:
			if i["name"] not in self.channels:
				publicRead = True if i["public_read"] == 1 else False
				publicWrite = True if i["public_write"] == 1 else False
				self.addChannel(i["name"], i["description"], publicRead, publicWrite)

	def addChannel(self, name, description, publicRead, publicWrite, temp = False, hidden = False):
		"""
		Add a channel to channels list

		:param name: channel name
		:param description: channel description
		:param publicRead: if True, this channel can be read by everyone. If False, it can be read only by mods/admins
		:param publicWrite: same as public read, but regards writing permissions
		:param temp: if True, this channel will be deleted when there's no one in this channel
		:param hidden: if True, thic channel won't be shown in channels list
		:return:
		"""
		glob.streams.add("chat/{}".format(name))

		self.channels[name] = channel.channel(name, description, publicRead, publicWrite, temp, hidden)