Commit 5cfb0cbf authored by ge0rg's avatar ge0rg

plugins/contact: iterate all data forms, thx. mathieui

parent 12ab0a7e
Pipeline #3564 failed with stages
in 5 minutes
...@@ -32,25 +32,22 @@ class Plugin(BasePlugin): ...@@ -32,25 +32,22 @@ class Plugin(BasePlugin):
self.api.information(message, 'Error') self.api.information(message, 'Error')
return return
info = iq['disco_info'] info = iq['disco_info']
title = 'Contact Info'
contacts = [] contacts = []
for field in info['form']: # iterate all data forms, in case there are multiple
var = field['var'] for form in iq['disco_info']:
if field['type'] == 'hidden' and var == 'FORM_TYPE': values = form.get_values()
form_type = field['value'][0] if values['FORM_TYPE'][0] == 'http://jabber.org/network/serverinfo':
if form_type != 'http://jabber.org/network/serverinfo': for var in values:
self.api.information('Not a server: “%s”: %s' % (iq['from'], form_type), 'Error') if not var.endswith('-addresses'):
return continue
continue title = var[:-10] # strip '-addresses'
if not var.endswith('-addresses'): sep = '\n ' + len(title) * ' '
continue field_value = values[var]
var = var[:-10] # strip '-addresses' if field_value:
sep = '\n ' + len(var) * ' ' value = sep.join(field_value) if isinstance(field_value, list) else field_value
field_value = field.get_value(convert=False) contacts.append('%s: %s' % (title, value))
value = sep.join(field_value) if isinstance(field_value, list) else field_value
contacts.append('%s: %s' % (var, value))
if contacts: if contacts:
self.api.information('\n'.join(contacts), title) self.api.information('\n'.join(contacts), 'Contact Info')
else: else:
self.api.information('No Contact Addresses for %s' % iq['from'], 'Error') self.api.information('No Contact Addresses for %s' % iq['from'], 'Error')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment