For my pr3s3nce bot at the AfRA channel I needed a Python IRC library that does not suck. The usual suspects like irc3 are outdated and relatively hard to program. After a while I stumbled accross pydle, which I currently regard as the superior IRC library.

Pydle uses Python’s async and await features, which makes programming the asynchronous message funtions rather easy. To make the code run on Python 3.5, I had to replace async and await keywords with @asyncio.coroutine and yield from.

import pydle

class MyOwnBot(pydle.Client):
    def on_connect(self):
         yield from self.join('#channel')

    def on_message(self, target, source, message):
        # Executed on message in a public channel

    def on_private_message(self, target, source, message):
    	# Executed on message in a query

client = MyOwnBot("botname", realname="This is a bot")'', tls=True, tls_verify=True)

Simple as that! Pydle does not handle reconnects very well, so the whole programm should be put into a simple Restart=Always systemd unit.