|
|
|
|
@ -1,14 +1,14 @@ |
|
|
|
|
import xmpp, os, sys, time, traceback, stream_ft |
|
|
|
|
import threading, errno, select |
|
|
|
|
import util |
|
|
|
|
import util, datetime |
|
|
|
|
|
|
|
|
|
from config import * |
|
|
|
|
|
|
|
|
|
VERSION = "0.2" |
|
|
|
|
MIN_CONNECT_INTERVAL = 300 |
|
|
|
|
IGNORE_FIRST = 3 |
|
|
|
|
IGNORE_FIRST = 10 |
|
|
|
|
|
|
|
|
|
last_connect = 0 |
|
|
|
|
reconnect = False |
|
|
|
|
commands = dict() |
|
|
|
|
commands_private = dict() |
|
|
|
|
group_listeners = [] |
|
|
|
|
@ -162,8 +162,10 @@ def __messageCB(conn,msg): |
|
|
|
|
raise xmpp.NodeProcessed |
|
|
|
|
|
|
|
|
|
def __presenceCB(conn,msg): |
|
|
|
|
global reconnect |
|
|
|
|
if msg.getType()=='unavailable': |
|
|
|
|
nick=msg.getNick() |
|
|
|
|
print room_nick |
|
|
|
|
if nick==None: |
|
|
|
|
if msg.getFrom() in users: |
|
|
|
|
del users[msg.getFrom()] |
|
|
|
|
@ -171,6 +173,9 @@ def __presenceCB(conn,msg): |
|
|
|
|
if not msg.getFrom() in users: |
|
|
|
|
for listener in status_listeners: |
|
|
|
|
listener(msg.getFrom(),msg,STATUS_OFFLINE) |
|
|
|
|
elif nick==NAME: |
|
|
|
|
print "--got kicked" |
|
|
|
|
reconnect = True |
|
|
|
|
else: |
|
|
|
|
if msg.getFrom() in users: |
|
|
|
|
del users[msg.getFrom()] |
|
|
|
|
@ -216,8 +221,6 @@ def __ignore_first(conn,msg): |
|
|
|
|
__messageCB(conn,msg) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
jid=xmpp.protocol.JID(node=NAME,domain=SRV,resource=RESOURCE) |
|
|
|
|
cl=xmpp.Client(jid.getDomain(),debug=[]) |
|
|
|
|
|
|
|
|
|
def connect_and_join(): |
|
|
|
|
"""Connect to the server and join the group chat room from the config.""" |
|
|
|
|
@ -227,6 +230,9 @@ def connect_and_join(): |
|
|
|
|
global cl |
|
|
|
|
global join_time |
|
|
|
|
last_connect=time.time() |
|
|
|
|
|
|
|
|
|
jid=xmpp.protocol.JID(node=NAME,domain=SRV,resource=RESOURCE) |
|
|
|
|
cl=xmpp.Client(jid.getDomain(),debug=[]) |
|
|
|
|
#connect to server |
|
|
|
|
con=cl.connect() |
|
|
|
|
if not con: |
|
|
|
|
@ -266,8 +272,19 @@ def loop(): |
|
|
|
|
"""Loop forever and handle the event-queue.""" |
|
|
|
|
global last_connect |
|
|
|
|
global call_ats |
|
|
|
|
global reconnect |
|
|
|
|
while True: |
|
|
|
|
try: |
|
|
|
|
|
|
|
|
|
if reconnect or cl.connected: #TODO check if it works |
|
|
|
|
print "--reconnect--" |
|
|
|
|
s=RECONNECT_INTERVAL-(time.time()-last_connect) |
|
|
|
|
if s>0: |
|
|
|
|
print "--reconnect interval not met (%dsek), sleeping[sek] %d" % (RECONNECT_INTERVAL,s) |
|
|
|
|
time.sleep(s) |
|
|
|
|
reconnect = False |
|
|
|
|
print "--wake--" |
|
|
|
|
connect_and_join() |
|
|
|
|
cl.Process(1) |
|
|
|
|
to_remove = [] |
|
|
|
|
for cid in call_ats: |
|
|
|
|
@ -291,13 +308,9 @@ def loop(): |
|
|
|
|
print_error() |
|
|
|
|
|
|
|
|
|
def print_error(): |
|
|
|
|
print "-------ERROR OCCURED-------" |
|
|
|
|
print "-------ERROR OCCURED-------", datetime.datetime.now.strftime("%Y-%h-%d, %H:%M:%S") |
|
|
|
|
print"--time: ", |
|
|
|
|
traceback.print_exc(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 "---------------------------" |
|
|
|
|
|
|
|
|
|
def callAt(func,_time,*args): |
|
|
|
|
|