Add example of accessing plugins to the README.

This commit is contained in:
Lance Stout 2012-01-18 15:22:19 -08:00
parent 4f4c121d9b
commit fd515d807c

View file

@ -118,8 +118,12 @@ SleekXMPP projects::
self.add_event_handler("session_start", self.session_start) self.add_event_handler("session_start", self.session_start)
self.add_event_handler("message", self.message) self.add_event_handler("message", self.message)
self.register_plugin('xep_0030') # Service Discovery # If you wanted more functionality, here's how to register plugins:
self.register_plugin('xep_0199') # XMPP Ping # 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('echo_demo')
# If you are working with an OpenFire server, you will # If you are working with an OpenFire server, you will
# need to use a different SSL version: # need to use a different SSL version:
@ -128,18 +132,20 @@ SleekXMPP projects::
def session_start(self, event): def session_start(self, event):
self.send_presence() self.send_presence()
self.get_roster()
# Most get_*/set_* methods from plugins use Iq stanzas, which # Most get_*/set_* methods from plugins use Iq stanzas, which
# can generate IqError and IqTimeout exceptions # can generate IqError and IqTimeout exceptions
try: #
self.get_roster() # try:
except IqError as err: # self.get_roster()
logging.error('There was an error getting the roster') # except IqError as err:
logging.error(err.iq['error']['condition']) # logging.error('There was an error getting the roster')
self.disconnect() # logging.error(err.iq['error']['condition'])
except IqTimeout: # self.disconnect()
logging.error('Server is taking too long to respond') # except IqTimeout:
self.disconnect() # logging.error('Server is taking too long to respond')
# self.disconnect()
def message(self, msg): def message(self, msg):
if msg['type'] in ('chat', 'normal'): if msg['type'] in ('chat', 'normal'):