I do not think that this is possible the way you want it, because the presence of contacts (which contains information about their availability) is received by the bot asynchronously.
You will need to write a presence handler function and register it when connected. This function will be called whenever a presence is received from the contact. The call parameter will tell you whether the contact is online or not. Depending on this, you can send a message to the contact.
Using xmpppy you do something like this:
def connect(jid, password, res, server, proxy, use_srv): conn = xmpp.Client(jid.getDomain()) if not conn.connect(server=server, proxy=proxy, use_srv=use_srv): log( 'unable to connect to server.') return None if not conn.auth(jid.getNode(), password, res): log( 'unable to authorize with server.') return None conn.RegisterHandler( 'presence', callback_presence) return conn conn = connect(...) def callback_presence(sess, pres): if pres.getStatus() == "online": msg = xmpp.Message(pres.getFrom(), "Hi!") conn.send(msg)
PS: I have not tested the code, but it should be something very similar to this.
source share