예제 #1
0
 def test_returned(self):
     e = irctokens.StatefulEncoder()
     line = irctokens.tokenise("PRIVMSG #channel hello")
     e.push(line)
     e.push(line)
     lines = e.pop(len(b"PRIVMSG #channel hello\r\nPRIVMSG"))
     self.assertEqual(len(lines), 1)
     self.assertEqual(lines[0], line)
예제 #2
0
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"
예제 #3
0
 def test(self):
     e = irctokens.StatefulEncoder(encoding="iso-8859-2")
     e.push(irctokens.tokenise("PRIVMSG #channel :hello Č"))
     self.assertEqual(e.pending(),
         "PRIVMSG #channel :hello Č\r\n".encode("iso-8859-2"))
예제 #4
0
 def test(self):
     e = irctokens.StatefulEncoder()
     line = irctokens.tokenise("PRIVMSG #channel hello")
     e.push(line)
     self.assertEqual(e.pending(), b"PRIVMSG #channel hello\r\n")
예제 #5
0
 def test(self):
     e = irctokens.StatefulEncoder()
     e.push(irctokens.tokenise("PRIVMSG #channel hello"))
     e.clear()
     self.assertEqual(e.pending(), b"")
예제 #6
0
 def test_none_returned(self):
     e = irctokens.StatefulEncoder()
     line = irctokens.tokenise("PRIVMSG #channel hello")
     e.push(line)
     lines = e.pop(1)
     self.assertEqual(len(lines), 0)