From 2661a28936ae6aa5edff2eedbef4d653f07d5172 Mon Sep 17 00:00:00 2001 From: kapi2289 Date: Fri, 20 Jul 2018 12:42:18 +0200 Subject: [PATCH] Multiple admins adding/removing Changed addGroupAdmin, removeGroupAdmin to addGroupAdmins, removeGroupAdmins --- fbchat/client.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/fbchat/client.py b/fbchat/client.py index 8e5e995..fce4707 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -1081,11 +1081,11 @@ class Client(object): j = self._post(self.req_url.REMOVE_USER, data, fix_request=True, as_json=True) - def addGroupAdmin(self, user_id, thread_id=None): + def addGroupAdmins(self, admin_ids, thread_id=None): """ Sets specifed user as a group admin. - :param user_id: User ID to set admin + :param admin_ids: User ID to set admin :param thread_id: Group ID to remove people from. See :ref:`intro_threads` :raises: FBchatException if request failed """ @@ -1093,17 +1093,25 @@ class Client(object): data = { "add": "true", - "admin_ids[0]": user_id, "thread_fbid": thread_id } + if type(admin_ids) is not list: + admin_ids = [admin_ids] + + # Make list of admins unique + admin_ids = set(admin_ids) + + for i, admin_id in enumerate(admin_ids): + data['admin_ids[' + str(i) + ']'] = str(admin_id) + j = self._post(self.req_url.SAVE_ADMINS, data, fix_request=True, as_json=True) - def removeGroupAdmin(self, user_id, thread_id=None): + def removeGroupAdmins(self, admin_ids, thread_id=None): """ Removes group admin from specifed user. - :param user_id: User ID to remove admin + :param admin_ids: User ID to remove admin :param thread_id: Group ID to remove people from. See :ref:`intro_threads` :raises: FBchatException if request failed """ @@ -1111,10 +1119,18 @@ class Client(object): data = { "add": "false", - "admin_ids[0]": user_id, "thread_fbid": thread_id } + if type(admin_ids) is not list: + admin_ids = [admin_ids] + + # Make list of admins unique + admin_ids = set(admin_ids) + + for i, admin_id in enumerate(admin_ids): + data['admin_ids[' + str(i) + ']'] = str(admin_id) + j = self._post(self.req_url.SAVE_ADMINS, data, fix_request=True, as_json=True) def changeGroupApprovalMode(self, approval_mode, thread_id=None):