XMPP bots for humans
Project description
xbotlib
XMPP bots for humans
status: experimental
A friendly lightweight wrapper around
slixmpp for writing XMPP bots in Python. The
goal is to make writing and running XMPP bots easy and fun. xbotlib
is a
single file implementation which can easily be understood and
extended. It provides a small API surface which reflects the slixmpp
way of
doing things.
Install
$ pip install xbotlib
Example
Put the following in a echo.py
file. xbotlib
provides a number of example
bots which you can use to get moving fast and try things out.
from xbotlib import EchoBot
EchotBot()
And then python echo.py
. You will be asked a few questions like which account
details your bot will be using.
This will generate a bot.conf
file in the same working directory for further use.
Here's the code for the EchoBot
.
class EchoBot(Bot):
def direct(self, message):
self.reply(message.body, to=message.sender)
def group(self, message):
if "echobot" in message.body:
self.reply(message.body.split(":")[-1], room=message.room)
Read more in the API reference for how to write your own bots.
All examples
- EchoBot: Sends back what you sent it
- WhisperBot: Pseudo-anonymous whispering in group chats
See xbotlib.py for all example bots.
API Reference
When writing your own bot, you always sub-class the Bot
class provided from
xbotlib
. Then if you want to respond to a direct message, you write a
direct function. If you want to respond to a group chat
message, you write a group function.
Bot.direct(message)
Respond to direct messages.
Arguments:
- message: received message (see SimpleMessage below for available attributes)
Bot.group(message)
Respond to a message in a group chat.
Arguments:
- message: received message (see SimpleMessage below for available attributes)
SimpleMessage
A simple message interface.
Attributes:
- body: the body of the message
- sender: the user the message came from
- room: the room the message came from
- receiver: the receiver of the message
- nickname: the nickname of the sender
- type: the type of message (
chat
orgroupchat
)
Configure your bot
Using the environment
You can pass the --no-input
option to your script invocation (e.g. python bot.py --no-input
).
xbotlib
will try to read the following configuration values from the environment.
- XBOT_JID: The username of the bot account
- XBOT_PASSWORD: The password of the bot account
- XBOT_ROOM: The room that the bot can join
- XBOT_NICK: The nickname that the bot uses
Roadmap
See the issue tracker.
Changes
See the CHANGELOG.md.
License
See the LICENSE.
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 xbotlib-0.6.0.tar.gz
.
File metadata
- Download URL: xbotlib-0.6.0.tar.gz
- Upload date:
- Size: 17.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.9.0 Linux/4.19.0-13-amd64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0ca6f6de1d9e2e247d277e0b2fba1fbe75485bd609b9285e7dcb748dc267734 |
|
MD5 | 90a04436c346fd6ad21316917a3e8ba4 |
|
BLAKE2b-256 | 9e581855d59635dbe52ba700e3b451d9ef7398d4f1b6e0ce8c29ef18a1538056 |
File details
Details for the file xbotlib-0.6.0-py3-none-any.whl
.
File metadata
- Download URL: xbotlib-0.6.0-py3-none-any.whl
- Upload date:
- Size: 16.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.9.0 Linux/4.19.0-13-amd64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5dccf1b1003be5147bcf9f1a6cf8db99ba30a63d11553235c6b59fa1f6996ee0 |
|
MD5 | e12da4ca9c3c2ac1488f1ce8fcb32f02 |
|
BLAKE2b-256 | 935e7c0b6fd1bc63bfd4b31f68507573c9bd8284155dc360dbc093d8f786b630 |