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 9166d82359 v0.12.0 release 2 weeks ago
ircstates str.maketrans is a much faster casefold; make casemaps an Enum 2 weeks ago
test str.maketrans is a much faster casefold; make casemaps an Enum 2 weeks ago
.gitignore first commit 2 years ago
.travis.yml remove python3.6; add python3.9 2 weeks ago
LICENSE switch LICENCE from GPL-3.0 to MIT 2 years ago freenode is dead long live 8 months ago
VERSION v0.12.0 release 2 weeks ago
requirements.txt put a cachetools LRUCache on casefold() 2 weeks ago remove python3.6; add python3.9 2 weeks ago


Build Status


I wanted a bare-bones reference implementation of taking byte input, parsing it into tokens and then managing an IRC client session state from it.

with this library, you can have client session state managed for you and put additional arbitrary functionality on top of it.



import ircstates

server = ircstates.Server("freenode")
lines  = server.recv(b":server 001 nick :hello world!\r\n")
lines += server.recv(b":nick JOIN #chan\r\n")
for line in lines:

chan = server.channels["#chan"]

socket to state

import ircstates, irctokens, socket

NICK = "nickname"
CHAN = "#chan"
HOST = ""
PORT = 6667

server  = ircstates.Server("freenode")
sock    = socket.socket()

sock.connect((HOST, PORT))
def _send(raw: str):

_send("USER test 0 * test")
_send(f"NICK {NICK}")

while True:
    recv_data  = sock.recv(1024)
    recv_lines = server.recv(recv_data)
    for line in recv_lines:
        print(f"< {line.format()}")

        # user defined behaviors...
        if line.command == "PING":
            _send(f"PONG :{line.params[0]}")

get a user's channels

>>> server.users
{'nickname': User(nickname='nickname')}
>>> user = server.users["nickname"]
>>> user
>>> user.channels

get a channel's users

>>> server.channels
{'#chan': Channel(name='#chan')}
>>> channel = server.channels["#chan"]
>>> channel
>>> channel.users
{'jess': ChannelUser(#chan jess)}

get a user's modes in channel

>>> channel = server.channels["#chan"]
>>> channel_user = channel.users["nickname"]
>>> channel_user
ChannelUser(#chan jess +ov)
>>> channel_user.modes
{'o', 'v'}


Come say hi at #irctokens on