This Python framework simplifies the process of creating basic Jabber bots by offering a user-friendly solution. With its easy-to-use features, it enables users to write uncomplicated Jabber bots with ease.
One of the best things about using Jabber bots is that they can be used for many different things. For example, you can use these bots to provide information about running systems, make websites interact with visitors, or notify the bot owner about updates or changes that are being monitored with custom Python scripts.
Python-Jabberbot is partly inspired by xmpppy example bot.py. However, it's designed to be reusable and to make it easy to write small Jabber bots that do one thing and do it well. The framework is straightforward to use. Here are the steps:
1. Import the class from jabberbot import JabberBot
2. Subclass the JabberBot class
3. Add methods starting with bot_, which 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 a string (or None if the command gives no reply)
4. Create an instance of your bot, supplying the username and password
5. Call the serve_forever() method of your instance
6. You can call the send() method on your bot to send messages to specific users
Here is an example code:
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 '%snn%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 = '[email protected]'
password = 'my-password'
bot = SystemInfoJabberBot(username,password)
bot.serve_forever()
In conclusion, if you want to create your own Jabber bot, then Python-Jabberbot is an excellent framework for you. It's easy to use and very flexible. With this software, you can build powerful and unique bots that can help you with anything you need.
Version 0.8: N/A