try before connect logic

This commit is contained in:
Pratyush Desai 2022-08-31 17:34:32 +05:30
parent 1525887c9d
commit 6ad857ed29
Signed by: pratyush
GPG Key ID: DBA5BB7505946FAD

View File

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