asyncio-based rfc2812-compliant IRC Client
Project description
asyncio-based rfc2812-compliant IRC Client (3.5+)
bottom isn’t a kitchen-sink library. Instead, it provides a consistent API with a small surface area, tuned for performance and ease of extension. Similar to the routing style of bottle.py, hooking into events is one line.
Installation
pip install bottom
Getting Started
Create an instance:
import asyncio
import bottom
host = 'chat.freenode.net'
port = 6697
ssl = True
NICK = "bottom-bot"
CHANNEL = "#bottom-dev"
bot = bottom.Client(host=host, port=port, ssl=ssl)
Send nick/user/join when connection is established:
@bot.on('CLIENT_CONNECT')
async def connect(**kwargs):
bot.send('NICK', nick=NICK)
bot.send('USER', user=NICK,
realname='https://github.com/numberoverzero/bottom')
# Don't try to join channels until the server has
# sent the MOTD, or signaled that there's no MOTD.
done, pending = await asyncio.wait(
[bot.wait("RPL_ENDOFMOTD"),
bot.wait("ERR_NOMOTD")],
loop=bot.loop,
return_when=asyncio.FIRST_COMPLETED
)
# Cancel whichever waiter's event didn't come in.
for future in pending:
future.cancel()
bot.send('JOIN', channel=CHANNEL)
Respond to ping:
@bot.on('PING')
def keepalive(message, **kwargs):
bot.send('PONG', message=message)
Echo messages (channel and direct):
@bot.on('PRIVMSG')
def message(nick, target, message, **kwargs):
""" Echo all messages """
# Don't echo ourselves
if nick == NICK:
return
# Respond directly to direct messages
if target == NICK:
bot.send("PRIVMSG", target=nick, message=message)
# Channel message
else:
bot.send("PRIVMSG", target=target, message=message)
Connect and run the bot forever:
bot.loop.create_task(bot.connect())
bot.loop.run_forever()
API
The full API consists of 1 class, with 6 methods:
async Client.connect()
async Client.disconnect()
Client.send(command, **kwargs)
@Client.on(event)
async Client.wait(event)
Client.trigger(event, **kwargs)
Visit the docs for more details and examples.
Contributors
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file bottom-1.0.4.tar.gz
.
File metadata
- Download URL: bottom-1.0.4.tar.gz
- Upload date:
- Size: 13.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ad30410cda21533e33e62e67829060c36b6125e7a0d3c74000f6c32f72225ba |
|
MD5 | 0d475da1cb510504de43261af009d2a7 |
|
BLAKE2b-256 | 8256fa6600617ff27046dc8cd4bd2c997d6242252166b61ae2677306e6d1ac32 |
File details
Details for the file bottom-1.0.4-py3-none-any.whl
.
File metadata
- Download URL: bottom-1.0.4-py3-none-any.whl
- Upload date:
- Size: 14.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b40a289c1ecaf04a29dbe5b86720eb07c9d3b5a8f11dd69e24f9f77a5d233af |
|
MD5 | 02b8e9894e9e5d38bb5bc0fe87b2edbc |
|
BLAKE2b-256 | b15537943706280a35896768d3cd9510a5d62775a308e0951c4325c1d063305a |