2014-08-10 12:14:03 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
|
|
import xmpp
|
|
|
|
|
from local_config import conf
|
|
|
|
|
|
2014-12-01 11:44:10 +01:00
|
|
|
import time
|
|
|
|
|
t = -time.time()
|
|
|
|
|
|
2014-08-10 12:14:03 +02:00
|
|
|
def message_handler(connect_object, message_node):
|
2014-12-01 11:44:10 +01:00
|
|
|
# hopefully the backlog is processed in this time
|
|
|
|
|
# FIXME: find a better way.
|
|
|
|
|
if (t + time.time() < 1):
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
msg_from = message_node.getFrom().getResource()
|
|
|
|
|
msg_body = message_node.getBody()
|
|
|
|
|
|
|
|
|
|
if not type(msg_body) in [str, unicode]:
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
if msg_body.startswith(conf('nick')):
|
|
|
|
|
connect_object.send(
|
|
|
|
|
xmpp.protocol.Message(
|
|
|
|
|
to=conf('room'),
|
|
|
|
|
body='hello %s!' % msg_from,
|
|
|
|
|
typ='groupchat'
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
print '%20s: %s' %(msg_from, msg_body)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print e
|
|
|
|
|
|
2014-08-10 12:14:03 +02:00
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
jid = xmpp.protocol.JID(conf('jid'))
|
|
|
|
|
|
2014-12-01 11:44:10 +01:00
|
|
|
client = xmpp.Client(jid.getDomain(), debug=[])
|
2014-08-10 12:14:03 +02:00
|
|
|
client.connect()
|
|
|
|
|
client.auth(jid.getNode(), conf('password'))
|
|
|
|
|
client.RegisterHandler('message', message_handler)
|
|
|
|
|
|
|
|
|
|
client.send(xmpp.Presence(to=(conf('room') + '/' + conf('nick'))))
|
|
|
|
|
|
2014-12-01 11:44:10 +01:00
|
|
|
while (t + time.time()) < 30:
|
|
|
|
|
client.Process(1)
|
2014-08-10 12:14:03 +02:00
|
|
|
|
|
|
|
|
client.disconnect()
|