Skip to content

Commit 54eac80

Browse files
committed
fix IRCClient's constructor
1 parent 9cee90a commit 54eac80

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

solution/Client.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
from secret_key import SECRET_KEY
77

88
class IRCClient:
9-
def __init__(self, host, port, nick):
9+
def __init__(self, host, port, nick, secret_key=None):
1010
self.host = host
1111
self.port = port
1212
self.nick = nick
1313
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
1414
self.connected = False
1515
self.buffer = ""
1616
self.cipher = Fernet(SECRET_KEY) # Usa la misma clave secreta que el servidor
17-
17+
self.secret_key = secret_key
1818
def connect(self):
1919
"""Se conecta al servidor IRC y envía el NICK y USER inicial."""
2020
self.sock.connect((self.host, self.port))
@@ -31,8 +31,11 @@ def send_command(self, command):
3131
# """Envía un mensaje al servidor IRC."""
3232
# self.sock.sendall((command + "\r\n").encode("utf-8"))
3333
"""Cifra y envía un mensaje al servidor IRC."""
34-
encrypted_command = self.cipher.encrypt((command + "\r\n").encode("utf-8"))
35-
self.sock.sendall(encrypted_command)
34+
if self.secret_key:
35+
encrypted_command = self.cipher.encrypt((command + "\r\n").encode("utf-8"))
36+
self.sock.sendall(encrypted_command)
37+
else:
38+
self.sock.sendall((command + "\r\n").encode("utf-8"))
3639

3740
def receive_response(self):
3841
"""Recibe y almacena todas las respuestas del servidor hasta que no haya más datos en el buffer."""

0 commit comments

Comments
 (0)