An IRCv3-compliant Python 3 IRC library.
Go to file
Tony Young 4eb83cfbb1 Add support for User and Channel models (closes #15).
This is a somewhat backwards-incompatible with v0.8 as it changes many interfaces for interacting with user and channel information, namely:

 - Instead of nicknames and channel names, User and Channel models are now passed to on_* hooks (BREAKING). Additionally, on_nick_change has been changed to take the arguments (user, original_nick).

 - All previous dictionary fields have been converted to attributes, e.g. user['username'] is now user.username. This extends to results from WHOIS (WHOISInfo) and WHOWAS (WHOWASInfo).

   __getitem__ and __setitem__ are implemented, for the time being, to maintain backwards compatibility.

 - _sync_user has been completely removed and replaced with _parse_and_process_user (and, to some extent, _get_user). Everything that made use of _parse_user now also synchronizes with the user database for consistency (may be breaking).

 - A new metaclass, ClientType, has been introduced to allow dynamic composition of the User and Channel classes on the feature classes (internal only).

 - User/Channel objects have the message() method when RFC1459 support is active (feature).

Oh, and now the contents parameter of ctcp() actually does something.
2015-06-07 19:20:10 -07:00
docs Update docs for IRCv3.2 changes. 2015-05-02 21:43:20 +02:00
pydle Add support for User and Channel models (closes #15). 2015-06-07 19:20:10 -07:00
tests Add support for User and Channel models (closes #15). 2015-06-07 19:20:10 -07:00
.coveragerc tests: Don't test pydle.utils for now. 2014-03-15 23:49:54 +01:00
.gitignore Add testing configuration. 2014-03-13 16:49:16 +01:00
LICENSE.md Fix misformatted license. 2014-01-23 02:51:08 +01:00
README.md Add IRCv3.2 metadata support. 2015-05-02 21:15:01 +02:00
requirements.txt Add Tornado to requirements.txt. 2014-07-31 01:03:48 +02:00
setup.py Reflect package merge in setup. 2015-05-08 14:25:16 +02:00
tox.ini tests: Add real life test marker. 2014-03-16 15:46:32 +01:00

README.md

pydle

Python IRC library.

pydle is a compact, flexible and standards-abiding IRC library for Python 3.

Features

  • Well-organized: Thanks to the modularized feature system, it's not hard to find what you're looking for in the well-organized source code.
  • Standards-abiding: Based on RFC1459 with some small extension tweaks, with full support of optional extension standards:
  • Callback-based: IRC is an asynchronous protocol and so should a library that implements it be. Callbacks are used to process events from the server.
  • Modularised and extensible: Features on top of RFC1459 are implemented as seperate modules for a user to pick and choose, and write their own. Broad features are written to be as extensible as possible.
  • Liberally licensed: The 3-clause BSD license ensures you can use it everywhere.

Basic Usage

python3 setup.py install

From there, you can import pydle and subclass pydle.Client for your own functionality.

Setting a nickname and starting a connection over TLS:

import pydle

# Simple echo bot.
class MyOwnBot(pydle.Client):
    def on_connect(self):
         self.join('#bottest')

    def on_message(self, source, target, message):
         self.message(target, message)

client = MyOwnBot('MyBot', realname='My Bot')
client.connect('irc.rizon.net', 6697, tls=True, tls_verify=False)
client.handle_forever()

But wait, I want to handle multiple clients!

No worries! Use pydle.ClientPool like such:

pool = pydle.ClientPool()
for i in range(10):
    client = MyOwnBot('MyBot' + str(i))
    pool.connect(client, 'irc.rizon.net', 6697, tls=True, tls_verify=False)

# This will make sure all clients are treated in a fair way priority-wise.
pool.handle_forever()

Customization

If you want to customize bot features, you can subclass pydle.BasicClient and one or more features from pydle.features or your own feature classes, like such:

# Only support RFC1459 (+small features), CTCP and our own ACME extension to IRC.
class MyFeaturedBot(pydle.features.ctcp.CTCPSupport, acme.ACMESupport, rfc1459.RFC1459Support):
    pass

To create your own features, just subclass from pydle.BasicClient and start adding callbacks for IRC messages:

# Support custom ACME extension.
class ACMESupport(pydle.BasicClient):
    def on_raw_999(self, source, params):
        """ ACME's custom 999 numeric tells us to change our nickname. """
        nickname = params[0]
        self.set_nickname(nickname)

FAQ

Q: When constructing my own client class from several base classes, I get the following error: TypeError: Cannot create a consistent method resolution order (MRO) for bases X, Y, Z. What causes this and how can I solve it?

Pydle's use of class inheritance as a feature model may cause method resolution order conflicts if a feature inherits from a different feature, while a class inherits from both the original feature and the inheriting feature. To solve such problem, pydle offers a featurize function that will automatically put all classes in the right order and create an appropriate base class:

# Purposely mis-ordered base classes, as SASLSupport inherits from CapabilityNegotiationSupport, but everything works fine.
MyBase = pydle.featurize(pydle.features.CapabilityNegotiationSupport, pydle.features.SASLSupport)
class Client(MyBase):
    pass

Q: How do I...?

Stop! Read the documentation first. If you're still in need of support, join us on IRC! We hang at #kochira on irc.freenode.net. If someone is around, they'll most likely gladly help you.

License

Pydle is licensed under the 3-clause BSD license. See LICENSE.md for details.