Skip to main content

asyncio-based rfc2812-compliant IRC Client

Project description

https://readthedocs.org/projects/bottom-docs/badge?style=flat-square https://img.shields.io/travis/numberoverzero/bottom/master.svg?style=flat-square https://img.shields.io/codecov/c/github/numberoverzero/bottom/master.svg?style=flat-square https://img.shields.io/pypi/v/bottom.svg?style=flat-square https://img.shields.io/github/issues-raw/numberoverzero/bottom.svg?style=flat-square https://img.shields.io/pypi/l/bottom.svg?style=flat-square

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

(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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bottom-2.1.3.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

bottom-2.1.3-py2.py3-none-any.whl (15.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file bottom-2.1.3.tar.gz.

File metadata

  • Download URL: bottom-2.1.3.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for bottom-2.1.3.tar.gz
Algorithm Hash digest
SHA256 0e9624110f28530581b98a9c231a9cafc61513addfa40f19b7e9de1abf7546c7
MD5 f9f8a729351f493bad21a30bf39d76d8
BLAKE2b-256 fe1ef78f35f6f24b1bff9455bca83548a02739f081e33710f74a134dfe7f6859

See more details on using hashes here.

File details

Details for the file bottom-2.1.3-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for bottom-2.1.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 78fbc51520d9c7c8c715db1603cfd9a3ce24b0a350b5f7b1a17ce7364100e3b7
MD5 416b4576b5a92be7bff67cba315ec8fd
BLAKE2b-256 ffcca2ed079e3ba09597f55b861808fcf25ce0a9e123cd4d252529928168cdb9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page