+
+def formatAndDistributePresence(presence):
+ if presence == "yes":
+ distributeXmppMsg("Somebody is present right now")
+ else:
+ distributeXmppMsg("Nobody is here, everybody left")
+
+current_status = (None, None, None)
+def filterAndFormatMessage(new_status):
+ global current_status
+ if new_status in [current_status, (current_status[0], None, None)] :
+ distributeXmppMsg("Status recieved but filtered: (%s,%s,%s)" % new_status ,debug=True)
+ elif current_status == (None, None, None):
+ current_status=new_status
+ distributeXmppMsg("Initial Status: (%s,%s,%s)" % new_status ,debug=True)
+ else:
+ (status,req,req_comment) = new_status
+ high_priority_msg = False
+ req_msg=""
+ status_msg=""
+ comment_msg=""
+ if status == "error":
+ status_msg = uwscfg.msg_status_error_msg
+ high_priority_msg=True
+ else:
+ if current_status[0] == status:
+ if status == "opened":
+ status_msg = uwscfg.msg_status_still_opened_msg
+ elif status == "closed":
+ status_msg = uwscfg.msg_status_still_closed_msg
+ else:
+ logging.error("Unknown Status recieved: (%s,%s,%s)" % new_status)
+ distributeXmppMsg("Unknown Status: (%s,%s,%s)" % new_status ,debug=True)
+ return
+ else:
+ if status == "opened":
+ status_msg = uwscfg.msg_status_opened_msg
+ elif status == "closed":
+ status_msg = uwscfg.msg_status_closed_msg
+ else:
+ logging.error("Unknown Status recieved: (%s,%s,%s)" % new_status)
+ distributeXmppMsg("Unknown Status: (%s,%s,%s)" % new_status ,debug=True)
+ return
+ if req:
+ req_msg = uwscfg.msg_request_msg.replace("${request}",req)
+ if req_comment:
+ comment_msg = uwscfg.msg_comment_msg.replace("${comment}",req_comment)
+ msg = uwscfg.msg_format.replace("${status_msg}", status_msg).replace("${request_msg}",req_msg).replace("${comment_msg}",comment_msg)
+ distributeXmppMsg(msg, high_priority=high_priority_msg)
+ current_status=new_status
+