asyncio-based rfc2812-compliant IRC Client
Project description
asyncio-based rfc2812-compliant IRC Client (3.8+)
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
(the full documentation is available here: http://bottom-docs.readthedocs.io/)
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 self
if nick == NICK: return
# respond directly
if target == NICK: target = nick
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 8 methods:
# manage connections
async Client.connect()
async Client.disconnect()
# send, receive, and wait for rfc-2812 messages
Client.send(command, **kwargs)
@Client.on(event)
Client.trigger(event, **kwargs)
async Client.wait(event)
# send and receive anything newline-terminated,
# provided for eg. IRCv3 extensions
Client.send_raw(message)
Client.handle_raw(message)
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bottom-2.2.0.tar.gz.
File metadata
- Download URL: bottom-2.2.0.tar.gz
- Upload date:
- Size: 14.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de1616f89bfb964284abe7e93a62fdf4ec065e06356c1fea5e946ad4a93d8e97
|
|
| MD5 |
4cb0d722e83943b4a085740a52b3b5bd
|
|
| BLAKE2b-256 |
8fba29cef03dd7f8c86c632d27051ecf2826b6b7c2c5f891f9031d75b19ca596
|
File details
Details for the file bottom-2.2.0-py2.py3-none-any.whl.
File metadata
- Download URL: bottom-2.2.0-py2.py3-none-any.whl
- Upload date:
- Size: 13.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
582c670d857dfc6653616683eadb7c137b9aa537f228e66e9e8658d101f1d067
|
|
| MD5 |
7d72273fb487e33c312b6674e35a47a4
|
|
| BLAKE2b-256 |
7260bccee7c2f0287fe22dfc4018d9e903401510e92ec0afbc8f971dfd773115
|