From 839b47009c819f3b425f71d07796d2911313b2ca Mon Sep 17 00:00:00 2001 From: FrostX <76787958+FrostX-Official@users.noreply.github.com> Date: Thu, 2 Mar 2023 10:41:48 +0300 Subject: [PATCH 1/7] added requested partial group thing --- roblox/partials/partialgroup.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/roblox/partials/partialgroup.py b/roblox/partials/partialgroup.py index fa4574a7..2c9a6117 100644 --- a/roblox/partials/partialgroup.py +++ b/roblox/partials/partialgroup.py @@ -72,3 +72,21 @@ def __init__(self, client: Client, data: dict): def __repr__(self): return f"<{self.__class__.__name__} id={self.id} name={self.name!r}>" + +class RequestedGroupnamePartialGroup(UniversePartialGroup): + """ + Represents a partial group in the context of a search query. + + Attributes: + requested_groupname: Group name they requested + """ + + def __init__(self, shared: ClientSharedObject, data: dict): + """ + Arguments: + shared: The ClientSharedObject. + data: The data form the endpoint. + """ + super().__init__(shared=shared, data=data) + + self.requested_groupname: str = data.get("requestedGroupname") From 8153ce7e2c83c750f9cec9a777e5524e1ebecf8b Mon Sep 17 00:00:00 2001 From: FrostX <76787958+FrostX-Official@users.noreply.github.com> Date: Thu, 2 Mar 2023 10:41:59 +0300 Subject: [PATCH 2/7] added group search --- roblox/client.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/roblox/client.py b/roblox/client.py index fbea3a43..53979b8c 100644 --- a/roblox/client.py +++ b/roblox/client.py @@ -21,6 +21,7 @@ from .delivery import DeliveryProvider from .groups import Group from .partials.partialuser import PartialUser, RequestedUsernamePartialUser, PreviousUsernamesPartialUser +from .partials.partialgroup import UniversePartialGroup, RequestedGroupnamePartialGroup from .places import Place from .plugins import Plugin from .presence import PresenceProvider @@ -291,6 +292,28 @@ def get_base_group(self, group_id: int) -> BaseGroup: A BaseGroup. """ return BaseGroup(client=self, group_id=group_id) + + def groups_search(self, keyword: str, page_size: int = 10, + max_items: int = None) -> PageIterator: + """ + Search for users with a keyword. + + Arguments: + keyword: A keyword to search for. + page_size: How many members should be returned for each page. + max_items: The maximum items to return when looping through this object. + + Returns: + A PageIterator containing RequestedUsernamePartialUser. + """ + return PageIterator( + shared=self._shared, + url=self._shared.url_generator.get_url("groups", f"v1/groups/search"), + page_size=page_size, + max_items=max_items, + extra_parameters={"keyword": keyword}, + handler=lambda shared, data: RequestedGroupnamePartialGroup(shared, data), + ) # Universes async def get_universes(self, universe_ids: List[int]) -> List[Universe]: From 681cc55970d5bb9e0b2991c5ecd2067cd0e42a1f Mon Sep 17 00:00:00 2001 From: FrostX <76787958+FrostX-Official@users.noreply.github.com> Date: Thu, 2 Mar 2023 10:50:41 +0300 Subject: [PATCH 3/7] Create group_search.py --- examples/group_search.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 examples/group_search.py diff --git a/examples/group_search.py b/examples/group_search.py new file mode 100644 index 00000000..0099cd58 --- /dev/null +++ b/examples/group_search.py @@ -0,0 +1,16 @@ +""" +Searches for groups which have a keyword in their name. +""" + +import asyncio +from roblox import Client +client = Client() + +async def main(): + users = client.groups_search("Roblox", max_items=10) + + async for user in users: + print("ID:", group.id) + print("\tName:", group.name) + +asyncio.get_event_loop().run_until_complete(main()) From df9678ea98b2e4dac706834bcb1418a3e69947cd Mon Sep 17 00:00:00 2001 From: FrostX <76787958+FrostX-Official@users.noreply.github.com> Date: Thu, 2 Mar 2023 10:51:43 +0300 Subject: [PATCH 4/7] added group_search.py to readme --- examples/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/examples/README.md b/examples/README.md index fa4716e1..47697c85 100644 --- a/examples/README.md +++ b/examples/README.md @@ -41,6 +41,12 @@