def make_set_role_request(room_jid, nick, role, reason): iq = Iq(typ='set', to=room_jid, queryNS=Namespace.MUC_ADMIN) item = iq.setQuery().setTag('item') item.setAttr('nick', nick) item.setAttr('role', role) if reason: item.addChild(name='reason', payload=reason) return iq
def _make_block_request(jids, report): iq = Iq('set', Namespace.BLOCKING) query = iq.setQuery(name='block') for jid in jids: item = query.addChild(name='item', attrs={'jid': jid}) if report in ('spam', 'abuse'): action = item.addChild(name='report', namespace=Namespace.REPORTING) action.setTag(report) return iq
def make_destroy_request(room_jid, reason, jid): iq = Iq(typ='set', queryNS=Namespace.MUC_OWNER, to=room_jid) destroy = iq.setQuery().setTag('destroy') if reason: destroy.setTagData('reason', reason) if jid: destroy.setAttr('jid', jid) return iq
def _make_set(jid, name, groups=None): if groups is None: groups = [] infos = {'jid': jid} if name: infos['name'] = name iq = Iq('set', Namespace.ROSTER) query = iq.setQuery() item = query.addChild('item', attrs=infos) for group in groups: item.addChild('group').setData(group) return iq
def make_set_affiliation_request(room_jid, users_dict): iq = Iq(typ='set', to=room_jid, queryNS=Namespace.MUC_ADMIN) item = iq.setQuery() for jid in users_dict: affiliation = users_dict[jid].get('affiliation') reason = users_dict[jid].get('reason') nick = users_dict[jid].get('nick') item_tag = item.addChild('item', { 'jid': jid, 'affiliation': affiliation }) if reason is not None: item_tag.setTagData('reason', reason) if nick is not None: item_tag.setAttr('nick', nick) return iq
def _make_blocking_list_request(): iq = Iq('get', Namespace.BLOCKING) iq.setQuery('blocklist') return iq
def _make_unblock_request(jids): iq = Iq('set', Namespace.BLOCKING) query = iq.setQuery(name='unblock') for jid in jids: query.addChild(name='item', attrs={'jid': jid}) return iq
def _make_unregister_request(jid): iq = Iq('set', to=jid) query = iq.setQuery() query.setNamespace(Namespace.REGISTER) query.addChild('remove') return iq
def make_set_config_request(room_jid, form): iq = Iq(typ='set', to=room_jid, queryNS=Namespace.MUC_OWNER) query = iq.setQuery() form.setAttr('type', 'submit') query.addChild(node=form) return iq
def make_affiliation_request(jid, affiliation): iq = Iq(typ='get', to=jid, queryNS=Namespace.MUC_ADMIN) item = iq.setQuery().setTag('item') item.setAttr('affiliation', affiliation) return iq
def _make_pref_request(): iq = Iq('get', queryNS=Namespace.MAM_2) iq.setQuery('prefs') return iq