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.
from xbotlib import Bot
class EchoBot(Bot):
def react(self, message):
if message.type == "chat":
self.reply(message.body, to=message.sender)
MyBot()
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.
More Examples
- EchoBot: Sends back what you sent it
- WhisperBot: Pseudo-anonymous whispering in group chats
See the examples directoy for all listings.
API Reference
Your bot always sub-classes the Bot
class provided from xbotlib
. All
underling functions can be extended. For example, if you want to enable more
plugins or add different functionality. If something feels awkward then please
raise a ticket for that. Seamlessness is still a bitch but we're trying anyway.
Bot.react(message)
A function which you define in your bot implementation in order to respond to
chat messages. You can respond to both direct messages and group chat messages
in this function by checking the message.type
which can be either chat
or
groupchat
.
Arguments:
- message: sent message and metadata (see message reference below)
Bot.reply(body, to=None, room=None)
Send back a response to a direct chat message.
Arguments:
- body: the message to send
- to: which user account to reply to (direct chat)
- room: which room to reply to (group chat)
EasyMessage
A simple message format. This is the type that you work with when your function
accepts a message
argument.
Attributes:
- body: the body of the message
- sender: the sender of the message
- receive: the receive 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
- XBOT_PASSWORD
- XBOT_ROOM
- XBOT_NICK
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.3.2.tar.gz
.
File metadata
- Download URL: xbotlib-0.3.2.tar.gz
- Upload date:
- Size: 16.9 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 | 197d77c27a8b84696bfdcdc0cc276b80d3f3ae1965e363e480bfbaceef055f35 |
|
MD5 | 9f28eacb27878ea4a2ece049ce096120 |
|
BLAKE2b-256 | 68ecb2a0d68f1f4497f63824cbe896597b841cb5c3c6b56e6e37ed85e92706d2 |
File details
Details for the file xbotlib-0.3.2-py3-none-any.whl
.
File metadata
- Download URL: xbotlib-0.3.2-py3-none-any.whl
- Upload date:
- Size: 16.5 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 | cb8788beeb5d8333bdd2e2fef243ab9d8d2d0fb436fb6e0440f373b2a0727edd |
|
MD5 | 943db692d3664d68716f77db913754b5 |
|
BLAKE2b-256 | 4b2a0f8d49449f39f355420decc100ef21352ee81942657155410c8e5944491a |