xmpp bot accept new friend?

I have a simple jabber bot in python.. this use xmpppy (import xmpp), this read command and return the output to who exec the command, fine.

I need accept automatically (by bot) the new friends requests, contacts..

any suggestions??

pd: this is a fragment of code:

self.cl = xmpp.Client(self.jid.getDomain(),debug=[])
    syslog.syslog("Conectando...")
    if not self.cl.connect(("jabber.org",5222)):
        raise IOError("No se pudo conectar con el server")
    syslog.syslog("Autenticando...")
    if not self.cl.auth(self.jid.getNode(),self.password):
        raise IOError("No se pudo autenticar el usuario")
    syslog.syslog("Registrando handler...")
    self.cl.RegisterHandler("message",self.messageHandler)
    self.cl.sendInitPresence()
def messageHandler(self,conn,mess):
    user = mess.getFrom().getStripped()
    text = mess.getBody()
    if text=="time":
        self.send(user,"Aqui son las " + datetime.datetime.now().strftime('%H:%M:%S'))
    elif text=="date":
        self.send(user,"Hoy es " + datetime.datetime.now().strftime("%d/%m/%Y"))
    elif text=="help":
        self.send(user,"Ayuda:\n - Para obtener la hora escribe: 'time'\n - Para obtener la fecha escribe: 'date'")

Upvotes: 1

Views: 584

Answers (1)

snim2
snim2

Reputation: 4079

There's a very helpful example project using xmpp by efcjoe on GitHub. The method you want is called add_friend (starts line 99):

def add_friend(self, user):
    self._send(xmpp.Presence(to=user, typ='subscribed'))
    self._send(xmpp.Presence(to=user, typ='subscribe'))
    return True

Upvotes: 2

Related Questions