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.
AAAAAAA 29b02a766f uwu 4 months ago
ircbridge uwu 4 months ago
sample_app uwu 4 months ago
README.md uwu 4 months ago
pyproject.toml uwu 4 months ago

README.md

IRCbridge

IRCbridge is a python library for easily creating bridges to IRC from arbitrary web hooks

Installation

IRCbridge manages dependencies with poetry. Installing dependencies for the main git branch can be done with:

# install poetry <https://python-poetry.org/docs/>
pip install poetry
# or, if you like to live dangerously
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -

poetry install --no-dev

If a git tag is ever made, it’ll have a requirements.txt file generated from poetry, and you can install from that with pip install -r requirements.txt.

Usage

A sample application is provided in the sample_app directory, it looks like this:

from ircbridge import IrcBridge

app = IrcBridge("sample_pap")

class Thing:
    foo: str 

def thing_to_irc(thing: thing) -> tuple[bool, str]:
    return True, f"Thing said: {thing.foo}!"

app.make_route("/", thing_to_irc, Thing)

The basic idea is to create an IrcBridge application, a JSON dataclass (the dataclass decorator is applied automatically by IRCbridge) modeling the webhook payload, a callback function for the class, and a webhook route.

When IRCbridge receives a POST request to the route, it creates an instance of dataclass using the webhook payload, and passes that to the callback function.

The callback function returns a tuple where the first element is a bool, and the second is a string. If the first element is true, IRCbridge will send the second element to an IRC channel. You’ll usually want to return True, "message", but returning False, "" is useful for side-effects without messaging the channel.

How it works, at a more technical level

The IrcBridge class actually subclasses Quart, and runs as a Quart application. Before serving requests, it starts an asynchronous Pydle client; irc messages and webhook requests are all handled in the same thread through Python’s async.

Contributing

Install dev dependencies with poetry:

poetry install

Then have fun hacking!

License

Who cares, do whatever.