Add error handling upon failure to to join to a groupchat (Thanks f_ from postmarketOS)
This commit is contained in:
parent
06002be363
commit
57e0425c13
5 changed files with 83 additions and 33 deletions
|
@ -127,7 +127,13 @@ async def xmpp_muc_autojoin(self, bookmarks):
|
|||
'bookmark {}'.format(bookmark['name']))
|
||||
alias = bookmark["nick"]
|
||||
muc_jid = bookmark["jid"]
|
||||
await XmppGroupchat.join(self, muc_jid, alias)
|
||||
result = await XmppGroupchat.join(self, muc_jid, alias)
|
||||
if result == 'ban':
|
||||
await XmppBookmark.remove(self, muc_jid)
|
||||
logger.warning('{} is banned from {}'.format(self.alias, muc_jid))
|
||||
logger.warning('Groupchat {} has been removed from bookmarks'
|
||||
.format(muc_jid))
|
||||
else:
|
||||
logger.info('Autojoin groupchat\n'
|
||||
'Name : {}\n'
|
||||
'JID : {}\n'
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
__version__ = '0.1.60'
|
||||
__version_info__ = (0, 1, 60)
|
||||
__version__ = '0.1.61'
|
||||
__version_info__ = (0, 1, 61)
|
||||
|
|
|
@ -940,8 +940,13 @@ class Chat:
|
|||
muc_jid = uri.check_xmpp_uri(message_text[5:])
|
||||
if muc_jid:
|
||||
# TODO probe JID and confirm it's a groupchat
|
||||
XmppGroupchat.join(self, muc_jid)
|
||||
result = await XmppGroupchat.join(self, muc_jid)
|
||||
# await XmppBookmark.add(self, jid=muc_jid)
|
||||
if result == 'ban':
|
||||
response = ('{} is banned from {}'
|
||||
.format(self.alias, muc_jid))
|
||||
else:
|
||||
await XmppBookmark.add(self, muc_jid)
|
||||
response = ('Joined groupchat {}'
|
||||
.format(message_text))
|
||||
else:
|
||||
|
|
|
@ -215,8 +215,24 @@ class Slixfeed(slixmpp.ClientXMPP):
|
|||
message_log = '{}: jid_full: {}'
|
||||
logger.debug(message_log.format(function_name, jid_full))
|
||||
muc_jid = message['groupchat_invite']['jid']
|
||||
result = await XmppGroupchat.join(self, muc_jid)
|
||||
if result == 'ban':
|
||||
message_body = '{} is banned from {}'.format(self.alias, muc_jid)
|
||||
jid_bare = message['from'].bare
|
||||
# This might not be necessary because JID might not be of the inviter, but rather of the MUC
|
||||
XmppMessage.send(self, jid_bare, message_body, 'chat')
|
||||
logger.warning(message_body)
|
||||
print("on_groupchat_invite")
|
||||
print("on_groupchat_invite")
|
||||
print("on_groupchat_invite")
|
||||
print(jid_full)
|
||||
print(jid_full)
|
||||
print(jid_full)
|
||||
print("on_groupchat_invite")
|
||||
print("on_groupchat_invite")
|
||||
print("on_groupchat_invite")
|
||||
else:
|
||||
await XmppBookmark.add(self, muc_jid)
|
||||
await XmppGroupchat.join(self, muc_jid)
|
||||
message_body = ('Greetings! I am {}, the news anchor.\n'
|
||||
'My job is to bring you the latest '
|
||||
'news from sources you provide me with.\n'
|
||||
|
@ -237,8 +253,14 @@ class Slixfeed(slixmpp.ClientXMPP):
|
|||
message_log = '{}: jid_full: {}'
|
||||
logger.debug(message_log.format(function_name, jid_full))
|
||||
muc_jid = message['groupchat_invite']['jid']
|
||||
result = await XmppGroupchat.join(self, muc_jid)
|
||||
if result == 'ban':
|
||||
message_body = '{} is banned from {}'.format(self.alias, muc_jid)
|
||||
jid_bare = message['from'].bare
|
||||
XmppMessage.send(self, jid_bare, message_body, 'chat')
|
||||
logger.warning(message_body)
|
||||
else:
|
||||
await XmppBookmark.add(self, muc_jid)
|
||||
await XmppGroupchat.join(self, muc_jid)
|
||||
message_body = ('Greetings! I am {}, the news anchor.\n'
|
||||
'My job is to bring you the latest '
|
||||
'news from sources you provide me with.\n'
|
||||
|
|
|
@ -17,6 +17,7 @@ FIXME
|
|||
|
||||
"""
|
||||
import logging
|
||||
from slixmpp.exceptions import IqError, IqTimeout, PresenceError
|
||||
|
||||
class XmppGroupchat:
|
||||
|
||||
|
@ -45,10 +46,26 @@ class XmppGroupchat:
|
|||
.format(jid))
|
||||
jid_from = str(self.boundjid) if self.is_component else None
|
||||
if alias == None: self.alias
|
||||
try:
|
||||
await self.plugin['xep_0045'].join_muc_wait(jid,
|
||||
alias,
|
||||
presence_options = {"pfrom" : jid_from},
|
||||
password=password)
|
||||
except IqError as e:
|
||||
logging.error('Error XmppIQ')
|
||||
logging.error(str(e))
|
||||
logging.error(jid)
|
||||
except IqTimeout as e:
|
||||
logging.error('Timeout XmppIQ')
|
||||
logging.error(str(e))
|
||||
logging.error(jid)
|
||||
except PresenceError as e:
|
||||
logging.error('Error Presence')
|
||||
logging.error(str(e))
|
||||
if (e.condition == 'forbidden' and
|
||||
e.presence['error']['code'] == '403'):
|
||||
logging.warning('{} is banned from {}'.format(self.alias, jid))
|
||||
return 'ban'
|
||||
|
||||
|
||||
def leave(self, jid):
|
||||
|
|
Loading…
Reference in a new issue