summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorGeorg Lukas <georg@op-co.de>2021-01-22 15:37:32 +0100
committerGeorg Lukas <georg@op-co.de>2021-01-22 16:06:59 +0100
commit5cfb0cbf43ec8e496b2fb58e948d2a234909015e (patch)
treeb442322356bcbdcf4bdb59d613a5cc836467854d /plugins
parent12ab0a7e80e9168ae627ce386a3af6bd84d79fd8 (diff)
downloadpoezio-5cfb0cbf43ec8e496b2fb58e948d2a234909015e.tar.gz
poezio-5cfb0cbf43ec8e496b2fb58e948d2a234909015e.tar.bz2
poezio-5cfb0cbf43ec8e496b2fb58e948d2a234909015e.tar.xz
poezio-5cfb0cbf43ec8e496b2fb58e948d2a234909015e.zip
plugins/contact: iterate all data forms, thx. mathieui
Diffstat (limited to 'plugins')
-rw-r--r--plugins/contact.py31
1 files changed, 14 insertions, 17 deletions
diff --git a/plugins/contact.py b/plugins/contact.py
index ebe4dcc4..461a1875 100644
--- a/plugins/contact.py
+++ b/plugins/contact.py
@@ -32,25 +32,22 @@ class Plugin(BasePlugin):
self.api.information(message, 'Error')
return
info = iq['disco_info']
- title = 'Contact Info'
contacts = []
- for field in info['form']:
- var = field['var']
- if field['type'] == 'hidden' and var == 'FORM_TYPE':
- form_type = field['value'][0]
- if form_type != 'http://jabber.org/network/serverinfo':
- self.api.information('Not a server: ā€œ%sā€: %s' % (iq['from'], form_type), 'Error')
- return
- continue
- if not var.endswith('-addresses'):
- continue
- var = var[:-10] # strip '-addresses'
- sep = '\n ' + len(var) * ' '
- field_value = field.get_value(convert=False)
- value = sep.join(field_value) if isinstance(field_value, list) else field_value
- contacts.append('%s: %s' % (var, value))
+ # iterate all data forms, in case there are multiple
+ for form in iq['disco_info']:
+ values = form.get_values()
+ if values['FORM_TYPE'][0] == 'http://jabber.org/network/serverinfo':
+ for var in values:
+ if not var.endswith('-addresses'):
+ continue
+ title = var[:-10] # strip '-addresses'
+ sep = '\n ' + len(title) * ' '
+ field_value = values[var]
+ if field_value:
+ value = sep.join(field_value) if isinstance(field_value, list) else field_value
+ contacts.append('%s: %s' % (title, value))
if contacts:
- self.api.information('\n'.join(contacts), title)
+ self.api.information('\n'.join(contacts), 'Contact Info')
else:
self.api.information('No Contact Addresses for %s' % iq['from'], 'Error')