January 2002
Beginner
480 pages
13h 15m
English
The next addition to the script is a callback to handle
<presence/> elements. The callback in
this script takes the form of a subroutine called
presenceCB() (“presence callback”).
Callbacks, in relation to programming with Jabber, are explained
in Section 8.3.4.
This is what the callback for handling
<presence/> elements looks like:
def presenceCB(con, prs):
type = prs.getType()
parts = split(prs.getFrom(), '/')
who = parts[0]
if type == None: type = 'available'
# Subscription request:
# - Accept their subscription
# - Send request for subscription to their presence
if type == 'subscribe':
print "subscribe request from %s" % (who)
con.send(jabber.Presence(to=who, type='subscribed'))
con.send(jabber.Presence(to=who, type='subscribe'))
# Unsubscription request:
# - Accept their unsubscription
# - Send request for unsubscription to their presence
elif type == 'unsubscribe':
print "unsubscribe request from %s" % (who)
con.send(jabber.Presence(to=who, type='unsubscribed'))
con.send(jabber.Presence(to=who, type='unsubscribe'))
elif type == 'subscribed':
print "we are now subscribed to %s" % (who)
elif type == 'unsubscribed':
print "we are now unsubscribed to %s" % (who)
elif type == 'available':
print "%s is available (%s/%s)" % (who, prs.getShow(), prs.getStatus())
if prs.getShow() != 'dnd' and who == cvsuser:
con.send(jabber.Message(cvsuser, message, subject="CVS Watch Alarm"))
elif type == 'unavailable':
print "%s is unavailable" % (who)
Phew! Let’s take it a ...
Read now
Unlock full access