#!/usr/bin/python # -*- coding: utf-8 -*- from asyncio import TimeoutError from slixmpp.exceptions import IqError, IqTimeout, PresenceError class XmppXep0030: async def get_jid_items(self, jid_bare): try: condition = text = '' error = False iq = await self['xep_0030'].get_items(jid=jid_bare) except (IqError, IqTimeout) as e: #logger.warning('Chat type could not be determined for {}'.format(jid_bare)) #logger.error(e) iq = '' error = True condition = e.iq['error']['condition'] text = e.iq['error']['text'] or 'Error' #if not text: # # NOTE We might want to set a specific photo for condition remote-server-not-found # if condition: # text = 'Could not determine JID type' # else: # text = 'Unknown Error' result = { 'condition' : condition, 'error' : error, 'iq' : iq, 'text' : text} return result # NOTE # Feature "urn:xmpp:mucsub:0" is present in both, MUC local and MUC hostname # Feature "urn:xmpp:serverinfo:0" is present in both, MUC hostname and main hostname async def get_jid_info(self, jid_bare): jid_kind = None try: error = False condition = text = '' iq = await self['xep_0030'].get_info(jid=jid_bare) iq_disco_info = iq['disco_info'] if iq_disco_info: features = iq_disco_info['features'] if 'http://jabber.org/protocol/muc#unique' in features: jid_kind = 'conference' elif 'urn:xmpp:mix:core:1' in features: jid_kind = 'mix' elif ('muc_moderated' in features or 'muc_open' in features or 'muc_persistent' in features or 'muc_public' in features or 'muc_semianonymous' in features or 'muc_unmoderated' in features or 'muc_unsecured' in features): jid_kind = 'muc' elif '@' in jid_bare: for identity in iq_disco_info['identities']: #if identity[0] == 'pubsub' and identity[1] == 'pep': if identity[0] == 'account': #if 'urn:xmpp:bookmarks:1#compat-pep' in features: #if 'urn:xmpp:bookmarks:1#compat' in features: #if 'urn:xmpp:push:0' in features: #if 'urn:xmpp:pep-vcard-conversion:0' in features: #if 'urn:xmpp:sid:0' in features: # Also in MIX #if 'urn:xmpp:mam:2' in features: #if 'urn:xmpp:mam:2#extended' in features: jid_kind = 'account' break if identity[0] == 'client' and identity[1] == 'bot': jid_kind = 'bot' else: for identity in iq_disco_info['identities']: if identity[0] == 'pubsub' and identity[1] == 'service': #if 'http://jabber.org/protocol/pubsub' in features: #if 'http://jabber.org/protocol/pubsub#access-authorize' in features: #if 'http://jabber.org/protocol/rsm' in features: jid_kind = 'pubsub' break if identity[0] == 'server' and identity[1] == 'im': jid_kind = 'server' break #logger.info('Jabber ID: {}\n' # 'Chat Type: {}'.format(jid_bare, result)) else: iq = condition = text = '' except (IqError, IqTimeout) as e: #logger.warning('Chat type could not be determined for {}'.format(jid_bare)) #logger.error(e) iq = '' error = True condition = e.iq['error']['condition'] text = e.iq['error']['text'] or 'Error' #if not text: # # NOTE We might want to set a specific photo for condition remote-server-not-found # if condition: # text = 'Could not determine JID type' # else: # text = 'Unknown Error' result = { 'condition' : condition, 'error' : error, 'iq' : iq, 'text' : text, 'kind' : jid_kind} return result