[Buildbot-devel] XMPP notifications (was: Desktop Notifications)
W. Martin Borgert
debacle at debian.org
Tue Dec 2 01:14:33 UTC 2014
On 2014-12-01 14:25, Stephen Davis wrote:
> Can you post that script? I've been waiting for a Jabber/XMPP client for a while now...
Yes, but please do not look at line 24. The time.sleep() is an
ugly hack, because I was too lazy to implement the proper event
handler for receive before disconnect. The script has been
tested with Prosody conference rooms, nothing else. I use it
with Buildbots MasterShellCommand(doStepIf=...), so that only
failed builds are reported.
-------------- next part --------------
#!/usr/bin/python
# -*- coding: utf-8 -*-
import optparse
import sys
import time
import sleekxmpp
class MUCBot(sleekxmpp.ClientXMPP):
def __init__(self, jid, password, room, nick, message):
sleekxmpp.ClientXMPP.__init__(self, jid, password)
self.room = room
self.nick = nick
self.add_event_handler("session_start", self.start)
self.message = message
def start(self, event):
self.getRoster()
self.sendPresence()
self.plugin['xep_0045'].joinMUC(self.room, self.nick, wait=True)
self.send_message(mto=self.room, mbody=self.message, mtype='groupchat')
time.sleep(10)
self.disconnect()
if __name__ == '__main__':
op = optparse.OptionParser(usage='%prog [options] your message text')
op.add_option("-j", "--jid", help="JID to use")
op.add_option("-n", "--nick", help="MUC nickname")
op.add_option("-p", "--password", help="password to use")
op.add_option("-r", "--room", help="MUC room to join")
opts, args = op.parse_args()
if None in [opts.jid, opts.nick, opts.password, opts.room] \
or len(args) < 1:
op.print_help()
sys.exit(1)
xmpp = MUCBot(opts.jid, opts.password, opts.room, opts.nick,
" ".join(args))
xmpp.register_plugin('xep_0030') # Service Discovery
xmpp.register_plugin('xep_0045') # Multi-User Chat
xmpp.register_plugin('xep_0199') # XMPP Ping
if xmpp.connect():
xmpp.process(threaded=False)
else:
print "connect() failed"
More information about the devel
mailing list