lightweight asyncio IRC clientο
bottom is a small no-dependency library for running simple or complex IRC clients.
Itβs easy to get started with built-in support for common commands, and extensible enough to support any capabilities, including custom encryption, local events, bridging, replication, and more.
Explicit is better than implicit: no magic importing or naming to remember for plugins. Extend
the client with the same @Client.on decorator.
Quickstartο
Create an instance:
import asyncio
import bottom
host = "irc.libera.chat"
port = 6697
ssl = True
NICK = "bottom-bot"
CHANNEL = "#bottom-dev"
bot = bottom.Client(host=host, port=port, ssl=ssl)
@bot.on('CLIENT_CONNECT')
async def connect(**kwargs):
await bot.send('nick', nick=NICK)
await bot.send('user', user=NICK,
realname='https://github.com/numberoverzero/bottom')
# Don't try to join channels until we're past the MOTD
await bottom.wait_for(bot, ["RPL_ENDOFMOTD", "ERR_NOMOTD"])
await bot.send('join', channel=CHANNEL)
@bot.on('PING')
async def keepalive(message: str, **kwargs):
await bot.send('pong', message=message)
@bot.on('PRIVMSG')
async def message(nick: str, target: str, message: str, **kwargs):
if nick == NICK:
return # bot sent this message, ignore
if target == NICK:
target = nick # direct message, respond directly
# else: respond in channel
await bot.send("privmsg", target=target, message=f"echo: {message}")
async def main():
await bot.connect()
try:
# serve until the connection drops...
await bot.wait("client_disconnect")
print("\ndisconnected by remote")
except asyncio.CancelledError:
# ...or we hit ctrl+c
await bot.disconnect()
print("\ndisconnected after ctrl+c")
if __name__ == "__main__":
asyncio.run(main())
Next Stepsο
Check out some extensions that add routing or full message encryption
Review the list of supported rfc2812 commands and supported rfc2812 responses
Learn how to
decorate a handler,manually trigger an event, orwait for an eventin the api documentation.Something missing? Contributions welcome! The development section will get you set up to
make dev && make pr-check