Skip to content
pinhook 2.0

IRC bots in plain Python.

Write a plugin as a function or a class, type its arguments, and pinhook handles the network, the rate limits and the permissions. Works on any IRC network, and on Twitch.

Read the docs $ pip install pinhook
#games
22:40 <ana> who's in for friday 22:41 <mal> !roll 2 20 22:41 <pinhook> mal rolled 31 [14, 17] 22:41 <mal> !gamenight 22:41 <pinhook> Tonight: Blades in the Dark. ana goes first

What's in 2.0

Everything a bot needs, nothing it doesn't.

Typed commands

Arguments come from the handler's signature. Bad input gets a usage line built from it, and !help writes itself.

Typed commands →

An async core

An output queue sends within each network's rate limits, so a slow plugin or a long reply never freezes the bot.

The context →

Recipes

Custom commands written as YAML, combining existing commands, replies, loops and conditions. No Python needed.

Writing recipes →

Access levels

Open, restricted or ops-only, per plugin or per command. Grant and deny from chat with !allow and !deny.

Access levels →

IRCv3 and Twitch

SASL, account tags, server time, threaded replies and more, each with a fallback. Twitch runs from the same config, with badges as access groups.

IRCv3 support →

TestBot

Run plugins in pytest without a server. Stores live in memory, and a plugin error fails the test.

TestBot →

A plugin

A class, a decorator, a reply.

Plugins get a ctx with everything they need: who spoke, where, how to reply, a store that survives restarts, and their own settings.

Typed commands in the docs →
import random

from pinhook import Plugin, command


class Dice(Plugin):
    @command('roll', help='roll dice, like roll 2 20')
    async def roll(self, ctx, count: int = 1, sides: int = 6):
        rolls = [random.randint(1, sides) for _ in range(count)]
        await ctx.reply(f'{ctx.nick} rolled {sum(rolls)} {rolls}')
# recipes/gamenight.yaml
version: 1
name: gamenight
help: pick tonight's game and who goes first
steps:
  - command: 'quote random games'
    save: game
  - reply: 'Tonight: {game}. {members|random} goes first'

A recipe

Custom commands, no code.

Recipes run existing commands as the person who asked, so a recipe can never do more than its user could. Ops add one-line recipes from chat with !recipe add.

Writing recipes →

Quick start

pip install pinhook
pinhook new bot gamebot

Edit gamebot/config.yaml with your server and channel, then run the bot:

pinhook run gamebot/config.yaml

Say !hello in the channel and the bot answers.

Where to next

pinhook is made with love on tilde.town. Bots using it include pinhook-tilde and adminbot.