Beispiel #1
0
def incomingChatMessageHandler(msg):
	"""
	Handles incoming (xmpp) messages and sends them to VK
	"""
	if msg.getType() == "groupchat":
		body = msg.getBody()
		destination = msg.getTo().getStripped()
		nick = msg.getFrom().getResource()
		source = msg.getFrom().getStripped()
		if mod_xhtml:
			html = msg.getTag("html")
		else:
			html = None

		x = msg.getTag("x", {"xmlns": xmpp.NS_MUC_USER})
		if x and x.getTagAttr("status", "code") == "100":
			raise xmpp.NodeProcessed()

		if not msg.getTimestamp() and body and destination == TransportID:
			user = Chat.getUserObject(source)
			creator, id, domain = Chat.getParts(source)
			send = False
			owner_nickname = None
			if user: 
				if source in getattr(user, "chats", {}):
					owner_nickname = user.chats[source].owner_nickname
				if not owner_nickname:
					owner_nickname = runDatabaseQuery("select nick from groupchats where jid=?",
						(source,), many=False)[0]
				# None of “normal” clients will send messages with timestamp
				# If we do (as we set in force_vk_date_group), then the message received from a user
				# If we don't and nick (as in settings) is tied to the chat, then we can determine who sent the message
				send = ((nick == owner_nickname and user.settings.tie_chat_to_nickname)
					or user.settings.force_vk_date_group)

				if html and html.getTag("body"): ## XHTML-IM!
					logger.debug("groupchats: fetched xhtml image (jid: %s)" % source)
					try:
						mod_xhtml.parseXHTML(user, html, source, source, "chat_id")
					except Exception:
						pass
					else:
						# Don't send a message if there's an image
						raise xmpp.NodeProcessed()
				if send:
					with user.sync:
						user.vk.sendMessage(body, id, "chat_id")
					runDatabaseQuery("update groupchats set last_used=? where jid=?", (time.time(), source), set=True)
					raise xmpp.NodeProcessed()
Beispiel #2
0
def incomingChatMessageHandler(msg):
	if msg.getType() == "groupchat":
		body = msg.getBody()
		destination = msg.getTo().getStripped()
		source = msg.getFrom().getStripped()
		if mod_xhtml:
			html = msg.getTag("html")
		else:
			html = None

		x = msg.getTag("x", {"xmlns": "http://jabber.org/protocol/muc#user"})
		if x and x.getTagAttr("status", "code") == "100":
			raise xmpp.NodeProcessed()

		if not msg.getTimestamp() and body and destination == TransportID:
			user = Chat.getUserObject(source)
			creator, id, domain = Chat.getParts(source)
			if user:
				if html and html.getTag("body"): ## XHTML-IM!
					logger.debug("groupchats: fetched xhtml image (jid: %s)" % source)
					try:
						xhtml = mod_xhtml.parseXHTML(user, html, source, source, "chat_id")
					except Exception:
						xhtml = False
					if xhtml:
						raise xmpp.NodeProcessed()
				user.vk.sendMessage(body, id, "chat_id")
Beispiel #3
0
def xhtml_handler(cl, msg):
    destination = msg.getTo().getStripped()
    source = msg.getFrom().getStripped()
    if source in Users and msg.getType() == "chat":
        user = Users[source]
        html = msg.getTag("html")
        if html and html.getTag("body"):  # XHTML-IM!
            logger.debug("fetched xhtml image from %s", source)
            try:
                xhtml = mod_xhtml.parseXHTML(user, html, source, destination)
            except Exception:
                xhtml = False
            if xhtml:
                raise xmpp.NodeProcessed()
Beispiel #4
0
def xhtml_handler(cl, msg):
	destination = msg.getTo().getStripped()
	source = msg.getFrom().getStripped()
	if source in Transport and msg.getType() == "chat":
		user = Transport[source]
		html = msg.getTag("html")
		if html and html.getTag("body"):  # XHTML-IM!
			logger.debug("fetched xhtml image from %s", source)
			try:
				xhtml = mod_xhtml.parseXHTML(user, html, source, destination)
			except Exception:
				xhtml = False
			if xhtml:
				raise xmpp.NodeProcessed()
Beispiel #5
0
def xhtml_handler(cl, msg):
    destination = msg.getTo().getStripped()
    source = msg.getFrom()
    if isinstance(source, (str, unicode)):
        logger.warning("Received message did not contain a valid jid: %s", msg)
        raise xmpp.NodeProcessed()
    source = source.getStripped()
    if source in Users and msg.getType() == "chat":
        user = Users[source]
        html = msg.getTag("html")
        if html and html.getTag("body"):  # XHTML-IM!
            logger.debug("fetched xhtml image from %s", source)
            try:
                xhtml = mod_xhtml.parseXHTML(user, html, source, destination)
            except Exception:
                xhtml = False
            if xhtml:
                raise xmpp.NodeProcessed()