Skip to content

Pirssi is a Python client for using IRC as a message broker.

License

Notifications You must be signed in to change notification settings

wonkybream/pirssi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

95 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pirssi

Ruff Tests

Pirssi is a Python client for using IRC as a message broker.

Code itself does not require any external libraries, only static analysis require installation of requirements.txt.

How this plays out

A publisher sends messages to an IRC channel which is a sort of message broker in this case. Every message is by default prefixed with :pirssi:, that's the message queue information.

A consumer connects to the given IRC channel and starts consuming messages. The consumer filters out every message except ones with the prefix. Messages are then forwarded to a handler.

Handler is simple implementation of a list of callable objects. The handler works by calling every object inside it with received argument.

from pirssi.handler import Handler

def handler_function(message: str):
    print(f"Handling message: {message}")

handler = Handler()

# Append handler function
handler.append(handler_function)

# Call handler
handler("Some information")

Output: Handling message: Some information

Running example

Both consumer and publisher need to be run separately.

If you want to see how this all plays out. https://webchat.quakenet.org/ is excellent for monitoring channel communications. The default channel is #pirssi-queue.

At first start the consumer.

python example.py consumer

And wait for the consumer to connect into channel. the consumer produces a log line something like this.

2021-10-03 10:46:59+0300 INFO pirssi.connection Connected to #pirssi-queue as pirssi-475e019b9354

Then start the publisher.

python example.py publisher

The publisher publishes few messages and then quits, the consumer receives those messages and forwards them to a handler which prints them out.

Looking from https://webchat.quakenet.org/, communication looks closely following.

[10:46] == pirssi-475e019b [~pirssi-47@xxxx] has joined #pirssi-queue
[10:47] == pirssi-81a725a2 [~pirssi-81@xxxx] has joined #pirssi-queue
[10:47] <pirssi-81a725a2> :pirssi:{"message": "I command you to do something"}
[10:47] <pirssi-81a725a2> :pirssi:{"message": "I would like to query some information"}
[10:47] <pirssi-81a725a2> :pirssi:{"message": "Something weird happened and you should know about it"}
[10:47] == pirssi-81a725a2 [~pirssi-81@xxxx] has quit [Quit]
[10:47] == pirssi-475e019b [~pirssi-47@xxxx] has quit [Quit]

Running tests

Project uses Python unittest as a testing framework, flake8 as style checker and mypy as a type checker.

Install test requirements.

pip install -r requirements.txt

Run tests using following command in the project path.

python -m unittest -v

Or run everything at once.

./scripts/precommit.sh

About

Pirssi is a Python client for using IRC as a message broker.

Topics

Resources

License

Stars

Watchers

Forks