1
0
mirror of http://aero2k.de/t/repos/urlbot-native.git synced 2017-09-06 15:25:38 +02:00
Files
urlbot-native-trex/bot-xmppy.py

50 lines
1023 B
Python
Raw Normal View History

#!/usr/bin/python
import xmpp
from local_config import conf
2014-12-01 11:44:10 +01:00
import time
t = -time.time()
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('bot_user')):
2014-12-01 11:44:10 +01:00
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
return None
jid = xmpp.protocol.JID(conf('jid'))
2014-12-01 11:44:10 +01:00
client = xmpp.Client(jid.getDomain(), debug=[])
client.connect()
client.auth(jid.getNode(), conf('password'))
client.RegisterHandler('message', message_handler)
client.send(xmpp.Presence(to=(conf('room') + '/' + conf('bot_user'))))
2014-12-01 11:44:10 +01:00
while (t + time.time()) < 30:
client.Process(1)
client.disconnect()