the Xtensible XMPP Chat Bot
Project description
The Xtensible XMPP Chat Bot
requirements
- python 3
- python3-gi
- python3-nbxmpp
optionally
- pipenv
run
with pipenv
$ pipenv --site-packages --python 3
$ pipenv install
$ pipenv run ./xchatbot.py
on osx:
$ brew install python3 pygobject3 pipenv
on Arch
# pacman -S python-gobject python-nbxmpp
$ ./xchatbot.py
on Debian:
# apt install python3-gi python3-nbxmpp
$ ./xchatbot.py
configuration
The script loads a configuration file called after the bot class name.
For a bot class EchoBot
the script will look for './echobot.rc',
'~/.echobot.rc' and '/etc/echobot.rc' in this order, and will load the first it
find.
An example config file is provided as echobot.rc.dist
, with comments.
extend
Subclass XChatBot
class in xchatbot
module and implement your commands
as method of your class.
Methods must be named cmd_yourcommand
and must get a peer
parameter and a
number of args.
A docstring should be provided that is used by help
command to build the help
message.
The bot is started calling the classmethod start()
In this example a simple echo bot.
The bot has one command, echo
and will send back all arguments back to the peer
from xchatbot import XChatBot
class MyEchoBot(XChatBot):
def cmd_echo(self, peer, *args):
"""Echo back what you typed"""
msg = "You said: "
msg = msg + " ".join(args)
peer.send(msg)
if __name__ == "__main__":
MyEchoBot.start()
create a myechobot.rc
config file and run the bot:
$ python echobot.py
private commands
A command can be marked as private using the @private
decorator.
A private command is list in help and is executed only if the message comes from
the admin JID setted in config file
from xchatbot import XChatBot, private
class MyEchoBot(XChatBot):
def cmd_echo(self, peer, *args):
"""Echo back what you typed"""
msg = "You said: "
msg = msg + " ".join(args)
peer.send(msg)
@private
dev cmd_admin(self, peer, *args):
"""Bot administration"""
peer.send("The admin was succesfull")
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
Built Distribution
File details
Details for the file xchatbot-0.1.0.tar.gz
.
File metadata
- Download URL: xchatbot-0.1.0.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e97ea2976e9e8abdf8a4d3e0f9d0eb3f0d94e4c2379b3b44a4d1324ddd073742 |
|
MD5 | d17f67ff0a1193646833d82539296b2e |
|
BLAKE2b-256 | 18a0e6d4ca83d1a2b6c28a9e39d507717ee4e63494a458a42cf658a690f59060 |
File details
Details for the file xchatbot-0.1.0-py2.py3-none-any.whl
.
File metadata
- Download URL: xchatbot-0.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1544c55730815ebaa6a9fee36a3a295cd0e97a42a2b10561646291071ea2cfe |
|
MD5 | e37c14afc06bfed7c58bf1927e2b5846 |
|
BLAKE2b-256 | 8ad53fbdf407f37646904f2c02bbf8cb6896d3c6e39ad53a56a054fd4bbcd735 |