|
|
|
@ -1,9 +1,12 @@ |
|
|
|
import xmpp, os, sys, time |
|
|
|
import xmpp, os, sys, time, traceback |
|
|
|
|
|
|
|
|
|
|
|
from config import * |
|
|
|
from config import * |
|
|
|
|
|
|
|
|
|
|
|
VERSION = "0.2" |
|
|
|
VERSION = "0.2" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MIN_CONNECT_INTERVAL=300 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
last_connect = 0 |
|
|
|
commands = dict() |
|
|
|
commands = dict() |
|
|
|
commands_private = dict() |
|
|
|
commands_private = dict() |
|
|
|
group_listeners = [] |
|
|
|
group_listeners = [] |
|
|
|
@ -170,7 +173,7 @@ def __presenceCB(conn,msg): |
|
|
|
users[msg.getFrom()] = STATUS_ONLINE |
|
|
|
users[msg.getFrom()] = STATUS_ONLINE |
|
|
|
#Online |
|
|
|
#Online |
|
|
|
else: |
|
|
|
else: |
|
|
|
print msg.getFrom(),"is now",show |
|
|
|
#print msg.getFrom(),"is now",show |
|
|
|
if not msg.getFrom() in users: |
|
|
|
if not msg.getFrom() in users: |
|
|
|
for listener in status_listeners: |
|
|
|
for listener in status_listeners: |
|
|
|
listener(msg.getFrom(),msg,STATUS_JOIN) |
|
|
|
listener(msg.getFrom(),msg,STATUS_JOIN) |
|
|
|
@ -196,11 +199,13 @@ def connect_and_join(): |
|
|
|
"""Connect to the server and join the group chat room from the config.""" |
|
|
|
"""Connect to the server and join the group chat room from the config.""" |
|
|
|
global room_nick |
|
|
|
global room_nick |
|
|
|
global room_to |
|
|
|
global room_to |
|
|
|
|
|
|
|
global last_connect |
|
|
|
|
|
|
|
last_connect=time.time() |
|
|
|
#connect to server |
|
|
|
#connect to server |
|
|
|
con=cl.connect() |
|
|
|
con=cl.connect() |
|
|
|
if not con: |
|
|
|
if not con: |
|
|
|
print 'could not connect!' |
|
|
|
print 'could not connect!' |
|
|
|
sys.exit() |
|
|
|
raise 'could not connect!' |
|
|
|
print 'connected' |
|
|
|
print 'connected' |
|
|
|
|
|
|
|
|
|
|
|
cl.RegisterHandler('message',__messageCB) |
|
|
|
cl.RegisterHandler('message',__messageCB) |
|
|
|
@ -210,7 +215,7 @@ def connect_and_join(): |
|
|
|
auth=cl.auth(NAME,PWD,resource=jid.getResource()) |
|
|
|
auth=cl.auth(NAME,PWD,resource=jid.getResource()) |
|
|
|
if not auth: |
|
|
|
if not auth: |
|
|
|
print 'could not authenticate!' |
|
|
|
print 'could not authenticate!' |
|
|
|
sys.exit() |
|
|
|
raise 'could not authenticate!' |
|
|
|
print 'auth' |
|
|
|
print 'auth' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -229,7 +234,26 @@ def connect_and_join(): |
|
|
|
cl.send(xmpp.Presence(to=room_to,status=NAME+" --(brathuhn bot framework (v"+VERSION+"), type !help)")) |
|
|
|
cl.send(xmpp.Presence(to=room_to,status=NAME+" --(brathuhn bot framework (v"+VERSION+"), type !help)")) |
|
|
|
|
|
|
|
|
|
|
|
def loop(): |
|
|
|
def loop(): |
|
|
|
|
|
|
|
global last_connect |
|
|
|
"""Loop forever and handle the event-queue.""" |
|
|
|
"""Loop forever and handle the event-queue.""" |
|
|
|
while True: |
|
|
|
while True: |
|
|
|
|
|
|
|
try: |
|
|
|
cl.Process(1) |
|
|
|
cl.Process(1) |
|
|
|
|
|
|
|
except xmpp.protocol.Conflict: |
|
|
|
|
|
|
|
print "detected another connection, quitting..." |
|
|
|
|
|
|
|
sys.exit(0) |
|
|
|
|
|
|
|
except KeyboardInterrupt: |
|
|
|
|
|
|
|
print "keyboard interrupt, quitting..." |
|
|
|
|
|
|
|
sys.exit(0) |
|
|
|
|
|
|
|
except: |
|
|
|
|
|
|
|
print "-------ERROR OCCURED-------" |
|
|
|
|
|
|
|
exc_type, exc_value, exc_traceback = sys.exc_info() |
|
|
|
|
|
|
|
traceback.print_tb(exc_traceback, file=sys.stdout) |
|
|
|
|
|
|
|
if not cl.connected: |
|
|
|
|
|
|
|
s=MIN_CONNECT_INTERVAL-(time.time()-last_connect) |
|
|
|
|
|
|
|
if s>0: |
|
|
|
|
|
|
|
time.sleep(s) |
|
|
|
|
|
|
|
connect_and_join() |
|
|
|
|
|
|
|
print "---------------------------" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|