From d2e8fcd2b5949c7836feaf559cd65c5062a7748c Mon Sep 17 00:00:00 2001 From: Georg Date: Wed, 1 Sep 2021 12:55:44 +0200 Subject: Init + SSO registration Signed-off-by: Georg --- irc_verify.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 irc_verify.py (limited to 'irc_verify.py') diff --git a/irc_verify.py b/irc_verify.py new file mode 100644 index 0000000..ff15818 --- /dev/null +++ b/irc_verify.py @@ -0,0 +1,45 @@ +import socket, irctokens + + +def ircverify(username, verif_code): + # define the variables + d = irctokens.StatefulDecoder() + e = irctokens.StatefulEncoder() + s = socket.socket() + + #connecting to the server + s.connect(("127.0.0.1", 6667)) + + #defining the send function with proper formatting + def _send(line): + print(f"> {line.format()}") + e.push(line) + while e.pending(): + e.pop(s.send(e.pending())) + # registering the connection to the server + + _send(irctokens.build("USER", [username, "0", "*", username])) + _send(irctokens.build("NICK", [username])) + + # go through the cases + + while True: + lines = d.push(s.recv(1024)) + + if lines == None: #if nothing is received from server + return "server error" + break + + for line in lines: + print(f"< {line.format()}") + + if line.command == "433": # if nickname already in use + return "433" + + elif line.command == "005": # when 005 is received pass the nickserv register command command + _send(irctokens.build("PRIVMSG", ["NickServ", f"VERIFY {username} {verif_code}"])) + + if line.command == "NOTICE" and line.params == [username, "Account created"]: # if Services respond with appropriate notice NOTICE + _send(irctokens.build("QUIT")) + return "success" + -- cgit v1.2.3