Go to file
jesopo a389c6f3cb remove python3.6; add python3.9 2022-01-07 11:39:30 +00:00
ircstates put a cachetools LRUCache on casefold() 2022-01-07 11:27:01 +00:00
test record when we first saw a user in a channel and optionally when they JOINed 2021-09-06 03:10:25 +00:00
.gitignore first commit 2020-03-12 14:00:26 +00:00
.travis.yml remove python3.6; add python3.9 2022-01-07 11:39:30 +00:00
LICENSE switch LICENCE from GPL-3.0 to MIT 2020-04-01 01:58:20 +01:00
README.md freenode is dead long live libera.chat 2021-05-24 17:27:10 +00:00
VERSION v0.11.10 release 2021-09-18 17:10:37 +00:00
requirements.txt put a cachetools LRUCache on casefold() 2022-01-07 11:27:01 +00:00
setup.py remove python3.6; add python3.9 2022-01-07 11:39:30 +00:00

README.md

ircstates

Build Status

rationale

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.

usage

simple

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:
    server.parse_tokens(line)

chan = server.channels["#chan"]

socket to state

import ircstates, irctokens, socket

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

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

sock.connect((HOST, PORT))
def _send(raw: str):
    sock.sendall(f"{raw}\r\n".encode("utf8"))

_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:
        server.parse_tokens(line)
        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(nickname='nickname')
>>> user.channels
{'#chan'}

get a channel's users

>>> server.channels
{'#chan': Channel(name='#chan')}
>>> channel = server.channels["#chan"]
>>> channel
Channel(name='#chan')
>>> 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'}

contact

Come say hi at #irctokens on irc.libera.chat