diff --git a/irc_register.py b/irc_register.py index 072d851..3fbef61 100644 --- a/irc_register.py +++ b/irc_register.py @@ -37,40 +37,39 @@ def ircregister(userip, username, password, email="*"): # Inform the server that we support # CAP 3.2 _send(irctokens.build("CAP", ["LS", "302"])) - - # REGISTER can be attempted before-connect if server supports - # but if the server responds with the corresponding FAIL we - # need to try again. We can also handle email-required using - # the same keys. How to access these key-value pairs? - # reference: https://github.com/ProgVal/ircv3-specifications/blob/register/extensions/account-registration.md#commands + # lines = d.push(s.recv(1024)) + if 'draft/account-registration=before-connnect' in lines.params: + # add extra conditional for custom account and email-required + _send(irctokens.build("REGISTER" ["*", password])) + else: # NICK and USER - _send(irctokens.build("USER", ["u", "0", "*", username])) - _send(irctokens.build("NICK", [username])) + _send(irctokens.build("USER", ["u", "0", "*", username])) + _send(irctokens.build("NICK", [username])) - # go through all cases + # go through all cases - while True: - for line in lines: - print(f"< {line.format()}") - if line.command == "432": - return "ERR_ERRONEUSNICKNAME" - elif line.command == "433": - return "ERR_NICKNAMEINUSE" - _send(irctokens.build("CAP", ["REQ", "draft/account-registration"])) - if line.command == "CAP" and ("NAK" in line.params): - return "cap refused" - elif line.command == "CAP" and ("ACK" in line.params): - to_send = irctokens.build("CAP", ["END"]) - _send(to_send) - if line.command == "PING": - to_send = irctokens.build("PONG", [line.params[0]]) - _send(to_send) - if line.command == "001": - # assuming no verif reqd. - to_send = irctokens.build("REGISTER", ["*", email, password]) - _send(to_send) - if line.command == "REGISTER" and ("SUCCESS" in line.params): - to_send = irctokens.build("QUIT") - _send(to_send) - return "SUCCESS" \ No newline at end of file + while True: + for line in lines: + print(f"< {line.format()}") + if line.command == "432": + return "ERR_ERRONEUSNICKNAME" + elif line.command == "433": + return "ERR_NICKNAMEINUSE" + _send(irctokens.build("CAP", ["REQ", "draft/account-registration"])) + if line.command == "CAP" and ("NAK" in line.params): + return "cap refused" + elif line.command == "CAP" and ("ACK" in line.params): + to_send = irctokens.build("CAP", ["END"]) + _send(to_send) + if line.command == "PING": + to_send = irctokens.build("PONG", [line.params[0]]) + _send(to_send) + if line.command == "001": + # assuming no verif reqd. + to_send = irctokens.build("REGISTER", ["*", email, password]) + _send(to_send) + if line.command == "REGISTER" and ("SUCCESS" in line.params): + to_send = irctokens.build("QUIT") + _send(to_send) + return "SUCCESS" \ No newline at end of file