Go to file
jesopo 87f85ba57c update README.md contact section to point to freenode 2020-07-10 12:09:11 +01:00
ircstates pull server from WHO and WHOX 2020-07-09 11:04:44 +01:00
test pull server from WHO and WHOX 2020-07-09 11:04:44 +01:00
.gitignore first commit 2020-03-12 14:00:26 +00:00
.travis.yml now that pypi irctokens supports typehints, remove --ignore-missing-imports 2020-03-12 15:34:36 +00:00
LICENSE switch LICENCE from GPL-3.0 to MIT 2020-04-01 01:58:20 +01:00
README.md update README.md contact section to point to freenode 2020-07-10 12:09:11 +01:00
VERSION v0.10.2 release 2020-07-08 23:19:50 +01:00
requirements.txt update irctokens to v1.1.0 2020-07-03 23:13:20 +01:00
setup.py update license in setup.py 2020-04-01 01:59:20 +01: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

socket to state

import ircstates, irctokens, socket

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

server  = ircstates.Server("freenode")
sock    = socket.socket()
encoder = irctokens.StatefulEncoder()

sock.connect((HOST, POST))

def _send(raw):
    tokens = irctokens.tokenise(raw)
    encoder.push(tokens)

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

while True:
    while encoder.pending():
        sent_lines = encoder.pop(sock.send(encoder.pending()))
        for line in sent_lines:
            print(f"> {line.format()}")

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

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

        if line.command == "001" and not CHAN in server.channels:
            _send(f"JOIN {CHAN}")

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 freenode