January 2002
Beginner
480 pages
13h 15m
English
The script, as it stands in Section 8.1.3, is what we want to extend and make sensitive to presence. Example 8-7 looks at the extended script, cvsmsg-s, and then walks through the additions.
import jabber import sys from string import split Server = 'gnu.pipetree.com' Username = 'cvsmsg' Password = 'secret' Resource = 'cvsmsg' cvsuser = sys.argv[1] message = '' 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': ...
Read now
Unlock full access