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

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 6 methods:

async Client.connect()

async Client.disconnect()

Client.send(command, **kwargs)

@Client.on(event)

async Client.wait(event)

Client.trigger(event, **kwargs)

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.2.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bottom-2.1.2-py2.py3-none-any.whl (15.0 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

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

File hashes

Hashes for bottom-2.1.2.tar.gz
Algorithm Hash digest
SHA256 f7ea72da7c5da3cfe4065ceb12cfa84705ac6a7ada7f59c228dcf5e82eb0dfca
MD5 3dfa17a4ba3dcea34c37b665a265a236
BLAKE2b-256 2653f521e39b2e6110ff4b3fdd94bfec02c7a7d056b29b43f0b307b5af782da8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bottom-2.1.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e734bfd6a5711565754da31e9f2615ebcdc41d52db9c27f0ebf0bb0cd24dba3c
MD5 919e3395b3a89f7ec2d47e2d0c5172e9
BLAKE2b-256 543f22181e17c57aa89c05d48d57a265b0d21f640d4b9a4058c03ebc8ca6b09b

See more details on using hashes here.

Supported by

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