2024-01-02 12:42:41 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2024-02-07 01:26:42 +01:00
|
|
|
from slixmpp.exceptions import IqError, IqTimeout
|
2024-01-02 12:42:41 +01:00
|
|
|
import logging
|
|
|
|
|
2024-02-07 01:26:42 +01:00
|
|
|
# class XmppChat
|
|
|
|
# class XmppUtility:
|
2024-01-17 15:36:28 +01:00
|
|
|
|
2024-03-12 18:13:01 +01:00
|
|
|
|
2024-02-25 02:52:24 +01:00
|
|
|
# TODO Rename to get_jid_type
|
2024-01-27 18:15:28 +01:00
|
|
|
async def get_chat_type(self, jid):
|
2024-01-02 12:42:41 +01:00
|
|
|
"""
|
2024-02-25 02:52:24 +01:00
|
|
|
Check chat (i.e. JID) type.
|
2024-01-02 12:42:41 +01:00
|
|
|
|
2024-01-27 18:15:28 +01:00
|
|
|
If iqresult["disco_info"]["features"] contains XML namespace
|
2024-02-11 22:31:31 +01:00
|
|
|
of 'http://jabber.org/protocol/muc', then it is a 'groupchat'.
|
2024-01-27 18:15:28 +01:00
|
|
|
|
|
|
|
Unless it has forward slash, which would indicate that it is
|
|
|
|
a chat which is conducted through a groupchat.
|
|
|
|
|
2024-02-11 22:31:31 +01:00
|
|
|
Otherwise, determine type 'chat'.
|
2024-01-27 18:15:28 +01:00
|
|
|
|
2024-01-02 12:42:41 +01:00
|
|
|
Parameters
|
|
|
|
----------
|
|
|
|
jid : str
|
|
|
|
Jabber ID.
|
|
|
|
|
|
|
|
Returns
|
|
|
|
-------
|
2024-05-14 21:39:58 +02:00
|
|
|
result : str
|
|
|
|
'chat' or 'groupchat' or 'error'.
|
2024-01-02 12:42:41 +01:00
|
|
|
"""
|
|
|
|
try:
|
|
|
|
iqresult = await self["xep_0030"].get_info(jid=jid)
|
|
|
|
features = iqresult["disco_info"]["features"]
|
|
|
|
# identity = iqresult['disco_info']['identities']
|
|
|
|
# if 'account' in indentity:
|
|
|
|
# if 'conference' in indentity:
|
2024-01-27 18:15:28 +01:00
|
|
|
if ('http://jabber.org/protocol/muc' in features) and not ('/' in jid):
|
2024-05-14 21:39:58 +02:00
|
|
|
result = "groupchat"
|
2024-01-02 12:42:41 +01:00
|
|
|
# TODO elif <feature var='jabber:iq:gateway'/>
|
|
|
|
# NOTE Is it needed? We do not interact with gateways or services
|
|
|
|
else:
|
2024-05-14 21:39:58 +02:00
|
|
|
result = "chat"
|
2024-02-04 18:08:12 +01:00
|
|
|
logging.info('Jabber ID: {}\n'
|
2024-05-14 21:39:58 +02:00
|
|
|
'Chat Type: {}'.format(jid, result))
|
|
|
|
except (IqError, IqTimeout) as e:
|
|
|
|
logging.error(str(e))
|
|
|
|
logging.error(jid)
|
|
|
|
result = 'error'
|
2024-02-11 00:25:05 +01:00
|
|
|
# except BaseException as e:
|
|
|
|
# logging.error('BaseException', str(e))
|
|
|
|
# finally:
|
|
|
|
# logging.info('Chat type is:', chat_type)
|
2024-05-14 21:39:58 +02:00
|
|
|
return result
|