Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added group_search() to client #93

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
</td>
<td>Searches for users and prints 10 to the console.</td>
</tr>
<tr>
<td>
<a href="./group_search.py">group_search.py</a>
</td>
<td>Searches for groups and prints 10 to the console.</td>
</tr>
<tr>
<td>
<a href="./group_information.py">group_information.py</a>
Expand Down
16 changes: 16 additions & 0 deletions examples/group_search.py
Original file line number Diff line number Diff line change
@@ -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.group_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())
23 changes: 23 additions & 0 deletions roblox/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -291,6 +292,28 @@ def get_base_group(self, group_id: int) -> BaseGroup:
A BaseGroup.
"""
return BaseGroup(client=self, group_id=group_id)

def group_search(self, keyword: str, page_size: int = 10,
max_items: int = None, prioritize_match: bool = True) -> 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, "prioritizeExactMatch": prioritize_match}
handler=lambda shared, data: RequestedGroupnamePartialGroup(shared, data),
)

# Universes
async def get_universes(self, universe_ids: List[int]) -> List[Universe]:
Expand Down
18 changes: 18 additions & 0 deletions roblox/partials/partialgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")