def find_groups_suggestions(self, search_query): if search_query.startswith("#"): search_query = search_query[1:] self._log("[+] Searching groups with query '{}'...".format(search_query)) encoded_search_query = base64.b64encode(("\x0a" + chr(len(search_query)) + search_query).encode(), b"-_").decode() if encoded_search_query.endswith("="): encoded_search_query = encoded_search_query[:encoded_search_query.index("=")] data = ('<iq type="set" id="{}">' '<query xmlns="kik:iq:xiphias:bridge" service="mobile.groups.v1.GroupSearch" method="FindGroups">' '<body>{}</body></query></iq>') \ .format(CryptographicUtils.make_kik_uuid(), encoded_search_query) self._make_request(data) response = self._get_response() if response.error: self._log("[-] Error when trying to get groups suggestions:", DebugLevel.ERROR) self._log(response.error.prettify(), DebugLevel.ERROR) raise KikErrorException(response.error, "Unable to get group suggestions. query: " + str(search_query)) if response.find("body") is None: self._log("[-] Can't find results") return None encoded_results = base64.b64decode(response.find("body").text.encode(), b"-_") results = group_search_service_pb2.FindGroupsResponse() results.ParseFromString(encoded_results) if len(results.match) == 0: self._log("[!] Found no matching groups") else: self._log("[+] Okay") return results
def __init__(self, data: BeautifulSoup): super().__init__(data) encoded_results = base64.b64decode( data.find("body").text.encode(), b"-_") results = group_search_service_pb2.FindGroupsResponse() results.ParseFromString(encoded_results) self.groups = [] # type: List[self.GroupSearchEntry] for result in results.match: self.groups.append(self.GroupSearchEntry(result))