import socket

class IRCClient:
	def __init__(self, server, port):
		self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
		self.server = server
		self.port = port
		print("Connecting to : " + server + ":" + str(port))
		self.socket.connect((server, port))

	def _send(self, msg):
		self.socket.send(bytes(msg + "\n", "UTF-8"))

	def send(self, dest, msg):
		self._send("PRIVMSG " + dest + " " + msg)
	
	def auth(self, login):	
		self._send("USER " + login + " " + self.server + " " + login + " :" + login)
		self._send("NICK " + login)

	def join(self, channel):
		self._send("JOIN " + channel)
	
	def recv(self):
		return self.socket.recv(8192).decode("UTF-8")
