2007 / python-jabberbot: A simple Jabber
Bot for Python
jabberbot 0.4: A simple Jabber Bot for Python
Programming your own Jabber bot can be fun and helpful. This
is python-jabberbot, a Jabber bot framework for Python
that enables you to easily write simple Jabber bots. You can use your
Jabber bots to provide information about your running systems, to make
your website interact with your visitors or notify you about updates or
changes you monitor with your Python scripts.
[...] now I have the
'bot bug' and I want to write bots for all kinds of things, since it's
so easy to do. Thanks again!
This Jabber bot is partly inspired by the xmpppy example
bot.py, but designed to be re-usable and to make it easy to write
small Jabber bots that do one thing and do it well.
Update 2008-11-13:
Vicent Tamarit
has used this jabberbot and modified it to work with natural language,
so the user has a conversation with the bot and the bot schedules a TV
recording for the user. Vicent plans to improve his ideas further and
will send us some code after he finished his changes (TVBot,
programming the TV with Jabber)
License: GNU General Public License, Version 3 or
later (GPLv3)
Freshmeat.net
project page
Python Package
Index / CheeseShop
Dependencies
Documentation
Download
ChangeLog
- 2007-07-28: Initial release
- 2007-09-17: Merged patch from John Martinez
- 2007-10-19: Merged patch from Dan
Sanders
- 2008-07-12: Add setup.py, prepare for CheeseShop, tarball
The detailed ChangeLog can be found here: ChangeLog
Usage
- Import the class:
from jabberbot import JabberBot
- Subclass the
JabberBot class
- Add methods starting with
bot_, these will be
exported as commands (e.g. def bot_display_id( self, mess, args));
the methods should return the message sent back to the user as string
(or None if the command gives no reply)
- Create an instance of your bot, supplying username and
password
- Call the
serve_forever() method of your
instance
- You can call the
send() method on your bot to
send messages to specific users
Example code
A more advanced example implementing a broadcasting bot with
user management and threading can be found here: jabberbot-example.py.
from jabberbot import JabberBot
import datetime
class SystemInfoJabberBot(JabberBot):
def bot_serverinfo( self, mess, args):
"""Displays information about the server"""
version = open('/proc/version').read().strip()
loadavg = open('/proc/loadavg').read().strip()
return '%s\n\n%s' % ( version, loadavg, )
def bot_time( self, mess, args):
"""Displays current server time"""
return str(datetime.datetime.now())
def bot_rot13( self, mess, args):
"""Returns passed arguments rot13'ed"""
return args.encode('rot13')
def bot_whoami( self, mess, args):
"""Tells you your username"""
return mess.getFrom()
username = 'my-jabberid@jabberserver.example.org'
password = 'my-password'
bot = SystemInfoJabberBot(username,password)
bot.serve_forever()
Screenshot
Related projects
Yoan Blanc has done a
similiar project using Python and the Twisted framework: A IM bot as an user
interface (kind of).
Projects using python-jabberbot
Saturday, July 12th 2008