summaryrefslogtreecommitdiffstats
path: root/irc_verify.py
diff options
context:
space:
mode:
authorGeorg2021-09-01 12:55:44 +0200
committerGeorg2021-09-01 12:55:44 +0200
commitd2e8fcd2b5949c7836feaf559cd65c5062a7748c (patch)
treea46305087626f5362e4719f255f296e77056b010 /irc_verify.py
downloadwebreg-d2e8fcd2b5949c7836feaf559cd65c5062a7748c.tar.gz
webreg-d2e8fcd2b5949c7836feaf559cd65c5062a7748c.tar.bz2
webreg-d2e8fcd2b5949c7836feaf559cd65c5062a7748c.zip
Init + SSO registration
Signed-off-by: Georg <georg@lysergic.dev>
Diffstat (limited to 'irc_verify.py')
-rw-r--r--irc_verify.py45
1 files changed, 45 insertions, 0 deletions
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"
+