summaryrefslogtreecommitdiff
path: root/docs/index.rst
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2012-01-18 15:04:33 -0800
committerLance Stout <lancestout@gmail.com>2012-01-18 15:04:33 -0800
commit72e1ab47fc393176cb99ddaeaad1098e88472417 (patch)
tree6c94fde4f91e6668ab713c5d6200f07bc110690a /docs/index.rst
parent1e01903072927917cf5c64ceb7bb1aac3770ea5c (diff)
parent3575084640fb5f17d70d6d691faf6fdd2f090ee7 (diff)
downloadslixmpp-72e1ab47fc393176cb99ddaeaad1098e88472417.tar.gz
slixmpp-72e1ab47fc393176cb99ddaeaad1098e88472417.tar.bz2
slixmpp-72e1ab47fc393176cb99ddaeaad1098e88472417.tar.xz
slixmpp-72e1ab47fc393176cb99ddaeaad1098e88472417.zip
Merge branch 'docs' into develop
Conflicts: docs/_static/haiku.css docs/_static/header.png docs/conf.py docs/getting_started/muc.rst docs/index.rst examples/muc.py
Diffstat (limited to 'docs/index.rst')
-rw-r--r--docs/index.rst66
1 files changed, 66 insertions, 0 deletions
diff --git a/docs/index.rst b/docs/index.rst
index fc6541d6..fe7df7f9 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -59,6 +59,72 @@ SleekXMPP's design goals and philosphy are:
sensible defaults and appropriate abstractions. XML can be ugly to work
with, but it doesn't have to be that way.
+Here's your first SleekXMPP Bot:
+--------------------------------
+
+.. code-block:: python
+
+ import logging
+
+ from sleekxmpp import ClientXMPP
+ from sleekxmpp.exceptions import IqError, IqTimeout
+
+
+ class EchoBot(ClientXMPP):
+
+ def __init__(self, jid, password):
+ ClientXMPP.__init__(self, jid, password)
+
+ self.add_event_handler("session_start", self.session_start)
+ self.add_event_handler("message", self.message)
+
+ self.register_plugin('xep_0030') # Service Discovery
+ self.register_plugin('xep_0199') # XMPP Ping
+
+ # Here's how to access plugins once you've registered them:
+ # self['xep_0030'].add_feature('echodemo')
+ # You can also use self.plugin['xep_0030']
+
+ # If you are working with an OpenFire server, you will
+ # need to use a different SSL version:
+ # import ssl
+ # self.ssl_version = ssl.PROTOCOL_SSLv3
+
+ def session_start(self, event):
+ self.send_presence()
+ self.get_roster()
+
+ # Most get_*/set_* methods from plugins use Iq stanzas, which
+ # can generate IqError and IqTimeout exceptions
+ #
+ # try:
+ # self.get_roster()
+ # except IqError as err:
+ # logging.error('There was an error getting the roster')
+ # logging.error(err.iq['error']['condition'])
+ # self.disconnect()
+ # except IqTimeout:
+ # logging.error('Server is taking too long to respond')
+ # self.disconnect()
+
+ def message(self, msg):
+ if msg['type'] in ('chat', 'normal'):
+ msg.reply("Thanks for sending\n%(body)s" % msg).send()
+
+
+ if __name__ == '__main__':
+ # Ideally use optparse or argparse to get JID,
+ # password, and log level.
+
+ logging.basicConfig(level=logging.DEBUG,
+ format='%(levelname)-8s %(message)s')
+
+ xmpp = EchoBot('somejid@example.com', 'use_getpass')
+ xmpp.connect()
+ xmpp.process(block=True)
+
+
+
Getting Started (with Examples)
-------------------------------
.. toctree::