blob: ff15818ae3edc2cf85fd211825b7b9b620aa6334 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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"
|