def handle_message_normal(self, stanza):
		"""Messsage handler function for pyxmpp."""
		jid = stanza.get_from()
		try:
			self.contacts[jid.bare()][jid]  # raises KeyError
		except KeyError:
			return  # only accept messages from known clients
		body = stanza.get_body()
		if body == u"help":
			helpmessage = u"""Valid commands:
- "ignore": Further messages are pretended to be delivered without being delivered.
- "disable": This resource will not receive further messages. Other ways of contacting the user are tried.
- "normal": Reset configuration to normal delivery.
- "help": Print this help text.
"""
			self.stream.send(pyxmpp.message.Message(to_jid=jid, body=helpmessage))
			return
		if body not in (u"normal", u"ignore", u"disable"):
			return
		try:
			inner = self.contacts[jid.bare()]  # raises KeyError
			if inner[jid][0] == body:  # raises KeyError
				raise KeyError("no change needed")
			inner[jid] = (body, inner[jid][1])
		except KeyError:
			pass
		else:
			statusmap = {u"normal": None, u"ignore": u"away", u"disable": u"dnd"}
			self.stream.send(pyxmpp.presence.Presence(to_jid=jid, show=statusmap[body]))
	def handle_contact_unavailable(self, jid):
		logger.debug("contact %s went offline", astr(jid))
		try:
			inner = self.contacts[jid.bare()]  # raises KeyError
			del inner[jid]  # raises KeyError
			if not inner:
				del self.contacts[jid.bare()]
		except KeyError:
			logger.info("could not find jid %s in my online list", astr(jid))
Esempio n. 3
0
	def handle_contact_available(self, jid, state):
		if jid.bare() != self.target.bare():
			return
		if self.exclude_resources(jid.resource):
			return
		if not self.include_states(state):
			return
		self.stream.send(self.message)
		self.failure = None
		self.disconnect_once()
	def handle_contact_available(self, jid, state):
		logger.debug("contact %s went online with state %r", astr(jid), state)
		inner = self.contacts.setdefault(jid.bare(), dict())
		inner[jid] = (u"normal", state)