You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jesopo 93f1079ae7 v2.0.1 release 2 weeks ago
irctokens unnecessary truthiness check 3 weeks ago
test merge tokenise() and tokenise_b() - using Union[str,bytes] 1 year ago
.gitignore Initial commit 2 years ago
.travis.yml remove pyyaml from requirements.txt - just make it a travis thing 2 years ago
LICENSE change LICENSE from GPL-3.0 to MIT 2 years ago freenode is dead long live 8 months ago
VERSION v2.0.1 release 2 weeks ago remove pyyaml from requirements.txt - just make it a travis thing 2 years ago


Build Status


there's far too many IRC client implementations out in the world that do not tokenise data correctly and thus fall victim to things like colons either being where you don't expect them or not being where you expect them.



$ pip3 install irctokens


>>> import irctokens
>>> line = irctokens.tokenise(
...     "@id=123 :jess!~jess@hostname PRIVMSG #chat :hello there!")
>>> line.tags
{'id': '123'}
>>> line.source
>>> line.hostmask
Hostmask(nickname='jess', username='~jess', hostname='hostname')
>>> line.command
>>> line.params
['#chat', 'hello there!']


>>>"USER", ["user", "0", "*", "real name"]).format()
'USER user 0 * :real name'


below is an example of a fully socket-wise safe IRC client connection that will connect and join a channel. both protocol sending and receiving are handled by irctokens.

import irctokens, socket

NICK = "nickname"
CHAN = "#channel"

d = irctokens.StatefulDecoder()
e = irctokens.StatefulEncoder()
s = socket.socket()
s.connect(("", 6667))

def _send(line):
    print(f"> {line.format()}")
    while e.pending():

_send("USER", ["username", "0", "*", "real name"]))
_send("NICK", [NICK]))

while True:
    lines = d.push(s.recv(1024))
    if lines == None:
        print("! disconnected")

    for line in lines:
        print(f"< {line.format()}")
        if line.command == "PING":
            to_send ="PONG", [line.params[0]])

        elif line.command == "001":
            to_send ="JOIN", [CHAN])


Come say hi at #irctokens on