baseuser
roblox.bases.baseuser
¶
This file contains the BaseUser object, which represents a Roblox user ID.
BaseUser (BaseItem)
¶
Represents a Roblox user ID.
Attributes:
Name | Type | Description |
---|---|---|
_shared |
ClientSharedObject |
The ClientSharedObject. |
id |
int |
The user ID. |
Source code in roblox/bases/baseuser.py
class BaseUser(BaseItem):
"""
Represents a Roblox user ID.
Attributes:
_shared: The ClientSharedObject.
id: The user ID.
"""
def __init__(self, shared: ClientSharedObject, user_id: int):
"""
Arguments:
shared: The ClientSharedObject.
user_id: The user ID.
"""
self._shared: ClientSharedObject = shared
self.id: int = user_id
async def get_status(self) -> str:
"""
Grabs the user's status.
Returns:
The user's status.
"""
status_response = await self._shared.requests.get(
url=self._shared.url_generator.get_url(
"users", f"/v1/users/{self.id}/status"
)
)
status_data = status_response.json()
return status_data["status"]
def username_history(
self, page_size: int = 10, sort_order: SortOrder = SortOrder.Ascending, max_items: int = None
) -> PageIterator:
"""
Grabs the user's username history.
Arguments:
page_size: How many members should be returned for each page.
sort_order: Order in which data should be grabbed.
max_items: The maximum items to return when looping through this object.
Returns:
A PageIterator containing the user's username history.
"""
return PageIterator(
shared=self._shared,
url=self._shared.url_generator.get_url(
"users", f"v1/users/{self.id}/username-history"
),
page_size=page_size,
sort_order=sort_order,
max_items=max_items,
handler=lambda shared, data: data["name"],
)
async def get_presence(self) -> Optional[Presence]:
"""
Grabs the user's presence.
Returns:
The user's presence, if they have an active presence.
"""
presences = await self._shared.presence_provider.get_user_presences([self.id])
try:
return presences[0]
except IndexError:
return None
async def get_friends(self) -> List[Friend]:
"""
Grabs the user's friends.
Returns:
A list of the user's friends.
"""
from ..friends import Friend
friends_response = await self._shared.requests.get(
url=self._shared.url_generator.get_url("friends", f"v1/users/{self.id}/friends")
)
friends_data = friends_response.json()["data"]
return [Friend(shared=self._shared, data=friend_data) for friend_data in friends_data]
async def get_currency(self) -> int:
"""
Grabs the user's current Robux amount. Only works on the authenticated user.
Returns:
The user's Robux amount.
"""
currency_response = await self._shared.requests.get(
url=self._shared.url_generator.get_url("economy", f"v1/users/{self.id}/currency")
)
currency_data = currency_response.json()
return currency_data["robux"]
async def has_premium(self) -> bool:
"""
Checks if the user has a Roblox Premium membership.
Returns:
Whether the user has Premium or not.
"""
premium_response = await self._shared.requests.get(
url=self._shared.url_generator.get_url("premiumfeatures", f"v1/users/{self.id}/validate-membership")
)
premium_data = premium_response.text
return premium_data == "true"
async def get_item_instance(self, item_type: InstanceType, item_id: int) -> Optional[ItemInstance]:
"""
Gets an item instance for a specific user.
Arguments:
item_type: The type of item to get an instance for.
item_id: The item's ID.
Returns: An ItemInstance, if it exists.
"""
item_type: str = item_type.value.lower()
# this is so we can have special classes for other types
item_class = instance_classes.get(item_type) or ItemInstance
instance_response = await self._shared.requests.get(
url=self._shared.url_generator.get_url("inventory", f"v1/users/{self.id}/items/{item_type}/{item_id}")
)
instance_data = instance_response.json()["data"]
if len(instance_data) > 0:
return item_class(
shared=self._shared,
data=instance_data[0]
)
else:
return None
async def get_asset_instance(self, asset: AssetOrAssetId) -> Optional[AssetInstance]:
"""
Checks if a user owns the asset, and returns details about the asset if they do.
Returns:
An asset instance, if the user owns this asset.
"""
return await self.get_item_instance(
item_type=InstanceType.asset,
item_id=int(asset)
)
async def get_gamepass_instance(self, gamepass: GamePassOrGamePassId) -> Optional[GamePassInstance]:
"""
Checks if a user owns the gamepass, and returns details about the asset if they do.
Returns:
An gamepass instance, if the user owns this gamepass.
"""
return await self.get_item_instance(
item_type=InstanceType.gamepass,
item_id=int(gamepass)
)
async def get_badge_awarded_dates(self, badges: list[BaseBadge]) -> List[PartialBadge]:
"""
Gets the dates that each badge in a list of badges were awarded to this user.
Returns:
A list of partial badges containing badge awarded dates.
"""
awarded_response = await self._shared.requests.get(
url=self._shared.url_generator.get_url("badges", f"v1/users/{self.id}/badges/awarded-dates"),
params={
"badgeIds": [badge.id for badge in badges]
}
)
awarded_data: list = awarded_response.json()["data"]
return [
PartialBadge(
shared=self._shared,
data=partial_data
) for partial_data in awarded_data
]
async def get_group_roles(self) -> List[Role]:
"""
Gets a list of roles for all groups this user is in.
Returns:
A list of roles.
"""
from ..roles import Role
from ..groups import Group
roles_response = await self._shared.requests.get(
url=self._shared.url_generator.get_url("groups", f"v1/users/{self.id}/groups/roles")
)
roles_data = roles_response.json()["data"]
return [
Role(
shared=self._shared,
data=role_data["role"],
group=Group(
shared=self._shared,
data=role_data["group"]
)
) for role_data in roles_data
]
async def get_primary_group_role(self) -> Optional[Role]:
"""
Gets a role for the primary group this user is in.
Returns:
Role
"""
from ..roles import Role
from ..groups import Group
roles_response = await self._shared.requests.get(
url=self._shared.url_generator.get_url("groups", f"v1/users/{self.id}/groups/primary/role")
)
json = roles_response.json()
if json is None:
return None
return Role(
shared=self._shared,
data=json["role"],
group=Group(
shared=self._shared,
data=json["group"]
)
)
async def get_roblox_badges(self) -> List[RobloxBadge]:
"""
Gets the user's Roblox badges.
Returns:
A list of Roblox badges.
"""
badges_response = await self._shared.requests.get(
url=self._shared.url_generator.get_url("accountinformation", f"v1/users/{self.id}/roblox-badges")
)
badges_data = badges_response.json()
return [RobloxBadge(shared=self._shared, data=badge_data) for badge_data in badges_data]
async def get_promotion_channels(self) -> UserPromotionChannels:
"""
Gets the user's promotion channels.
Returns:
The user's promotion channels.
"""
channels_response = await self._shared.requests.get(
url=self._shared.url_generator.get_url("accountinformation", f"v1/users/{self.id}/promotion-channels")
)
channels_data = channels_response.json()
return UserPromotionChannels(
data=channels_data
)
async def _get_friend_channel_count(self, channel: str) -> int:
count_response = await self._shared.requests.get(
url=self._shared.url_generator.get_url("friends", f"v1/users/{self.id}/{channel}/count")
)
return count_response.json()["count"]
def _get_friend_channel_iterator(
self,
channel: str,
page_size: int = 10,
sort_order: SortOrder = SortOrder.Ascending, max_items: int = None
) -> PageIterator:
from ..friends import Friend
return PageIterator(
shared=self._shared,
url=self._shared.url_generator.get_url("friends", f"v1/users/{self.id}/{channel}"),
page_size=page_size,
sort_order=sort_order,
max_items=max_items,
handler=lambda shared, data: Friend(shared=shared, data=data)
)
async def get_friend_count(self) -> int:
"""
Gets the user's friend count.
Returns:
The user's friend count.
"""
return await self._get_friend_channel_count("friends")
async def get_follower_count(self) -> int:
"""
Gets the user's follower count.
Returns:
The user's follower count.
"""
return await self._get_friend_channel_count("followers")
async def get_following_count(self) -> int:
"""
Gets the user's following count.
Returns:
The user's following count.
"""
return await self._get_friend_channel_count("followings")
def get_followers(
self,
page_size: int = 10,
sort_order: SortOrder = SortOrder.Ascending, max_items: int = None
) -> PageIterator:
"""
Gets the user's followers.
Returns:
A PageIterator containing everyone who follows this user.
"""
return self._get_friend_channel_iterator(
channel="followers",
page_size=page_size,
sort_order=sort_order,
max_items=max_items,
)
def get_followings(
self,
page_size: int = 10,
sort_order: SortOrder = SortOrder.Ascending, max_items: int = None
) -> PageIterator:
"""
Gets the user's followings.
Returns:
A PageIterator containing everyone that this user is following.
"""
return self._get_friend_channel_iterator(
channel="followings",
page_size=page_size,
sort_order=sort_order,
max_items=max_items,
)
__init__(self, shared: ClientSharedObject, user_id: int)
special
¶
Parameters:
Name | Type | Description | Default |
---|---|---|---|
shared |
ClientSharedObject |
The ClientSharedObject. |
required |
user_id |
int |
The user ID. |
required |
Source code in roblox/bases/baseuser.py
def __init__(self, shared: ClientSharedObject, user_id: int):
"""
Arguments:
shared: The ClientSharedObject.
user_id: The user ID.
"""
self._shared: ClientSharedObject = shared
self.id: int = user_id
get_asset_instance(self, asset: AssetOrAssetId) -> Optional[AssetInstance]
async
¶
Checks if a user owns the asset, and returns details about the asset if they do.
Returns:
Type | Description |
---|---|
Optional[AssetInstance] |
An asset instance, if the user owns this asset. |
Source code in roblox/bases/baseuser.py
async def get_asset_instance(self, asset: AssetOrAssetId) -> Optional[AssetInstance]:
"""
Checks if a user owns the asset, and returns details about the asset if they do.
Returns:
An asset instance, if the user owns this asset.
"""
return await self.get_item_instance(
item_type=InstanceType.asset,
item_id=int(asset)
)
get_badge_awarded_dates(self, badges: list[BaseBadge]) -> List[PartialBadge]
async
¶
Gets the dates that each badge in a list of badges were awarded to this user.
Returns:
Type | Description |
---|---|
List[PartialBadge] |
A list of partial badges containing badge awarded dates. |
Source code in roblox/bases/baseuser.py
async def get_badge_awarded_dates(self, badges: list[BaseBadge]) -> List[PartialBadge]:
"""
Gets the dates that each badge in a list of badges were awarded to this user.
Returns:
A list of partial badges containing badge awarded dates.
"""
awarded_response = await self._shared.requests.get(
url=self._shared.url_generator.get_url("badges", f"v1/users/{self.id}/badges/awarded-dates"),
params={
"badgeIds": [badge.id for badge in badges]
}
)
awarded_data: list = awarded_response.json()["data"]
return [
PartialBadge(
shared=self._shared,
data=partial_data
) for partial_data in awarded_data
]
get_currency(self) -> int
async
¶
Grabs the user's current Robux amount. Only works on the authenticated user.
Returns:
Type | Description |
---|---|
int |
The user's Robux amount. |
Source code in roblox/bases/baseuser.py
async def get_currency(self) -> int:
"""
Grabs the user's current Robux amount. Only works on the authenticated user.
Returns:
The user's Robux amount.
"""
currency_response = await self._shared.requests.get(
url=self._shared.url_generator.get_url("economy", f"v1/users/{self.id}/currency")
)
currency_data = currency_response.json()
return currency_data["robux"]
get_follower_count(self) -> int
async
¶
Gets the user's follower count.
Returns:
Type | Description |
---|---|
int |
The user's follower count. |
Source code in roblox/bases/baseuser.py
async def get_follower_count(self) -> int:
"""
Gets the user's follower count.
Returns:
The user's follower count.
"""
return await self._get_friend_channel_count("followers")
get_followers(self, page_size: int = 10, sort_order: SortOrder = <SortOrder.Ascending: 'Asc'>, max_items: int = None) -> PageIterator
¶
Gets the user's followers.
Returns:
Type | Description |
---|---|
PageIterator |
A PageIterator containing everyone who follows this user. |
Source code in roblox/bases/baseuser.py
def get_followers(
self,
page_size: int = 10,
sort_order: SortOrder = SortOrder.Ascending, max_items: int = None
) -> PageIterator:
"""
Gets the user's followers.
Returns:
A PageIterator containing everyone who follows this user.
"""
return self._get_friend_channel_iterator(
channel="followers",
page_size=page_size,
sort_order=sort_order,
max_items=max_items,
)
get_following_count(self) -> int
async
¶
Gets the user's following count.
Returns:
Type | Description |
---|---|
int |
The user's following count. |
Source code in roblox/bases/baseuser.py
async def get_following_count(self) -> int:
"""
Gets the user's following count.
Returns:
The user's following count.
"""
return await self._get_friend_channel_count("followings")
get_followings(self, page_size: int = 10, sort_order: SortOrder = <SortOrder.Ascending: 'Asc'>, max_items: int = None) -> PageIterator
¶
Gets the user's followings.
Returns:
Type | Description |
---|---|
PageIterator |
A PageIterator containing everyone that this user is following. |
Source code in roblox/bases/baseuser.py
def get_followings(
self,
page_size: int = 10,
sort_order: SortOrder = SortOrder.Ascending, max_items: int = None
) -> PageIterator:
"""
Gets the user's followings.
Returns:
A PageIterator containing everyone that this user is following.
"""
return self._get_friend_channel_iterator(
channel="followings",
page_size=page_size,
sort_order=sort_order,
max_items=max_items,
)
get_friend_count(self) -> int
async
¶
Gets the user's friend count.
Returns:
Type | Description |
---|---|
int |
The user's friend count. |
Source code in roblox/bases/baseuser.py
async def get_friend_count(self) -> int:
"""
Gets the user's friend count.
Returns:
The user's friend count.
"""
return await self._get_friend_channel_count("friends")
get_friends(self) -> List[Friend]
async
¶
Grabs the user's friends.
Returns:
Type | Description |
---|---|
List[Friend] |
A list of the user's friends. |
Source code in roblox/bases/baseuser.py
async def get_friends(self) -> List[Friend]:
"""
Grabs the user's friends.
Returns:
A list of the user's friends.
"""
from ..friends import Friend
friends_response = await self._shared.requests.get(
url=self._shared.url_generator.get_url("friends", f"v1/users/{self.id}/friends")
)
friends_data = friends_response.json()["data"]
return [Friend(shared=self._shared, data=friend_data) for friend_data in friends_data]
get_gamepass_instance(self, gamepass: GamePassOrGamePassId) -> Optional[GamePassInstance]
async
¶
Checks if a user owns the gamepass, and returns details about the asset if they do.
Returns:
Type | Description |
---|---|
Optional[GamePassInstance] |
An gamepass instance, if the user owns this gamepass. |
Source code in roblox/bases/baseuser.py
async def get_gamepass_instance(self, gamepass: GamePassOrGamePassId) -> Optional[GamePassInstance]:
"""
Checks if a user owns the gamepass, and returns details about the asset if they do.
Returns:
An gamepass instance, if the user owns this gamepass.
"""
return await self.get_item_instance(
item_type=InstanceType.gamepass,
item_id=int(gamepass)
)
get_group_roles(self) -> List[Role]
async
¶
Gets a list of roles for all groups this user is in.
Returns:
Type | Description |
---|---|
List[Role] |
A list of roles. |
Source code in roblox/bases/baseuser.py
async def get_group_roles(self) -> List[Role]:
"""
Gets a list of roles for all groups this user is in.
Returns:
A list of roles.
"""
from ..roles import Role
from ..groups import Group
roles_response = await self._shared.requests.get(
url=self._shared.url_generator.get_url("groups", f"v1/users/{self.id}/groups/roles")
)
roles_data = roles_response.json()["data"]
return [
Role(
shared=self._shared,
data=role_data["role"],
group=Group(
shared=self._shared,
data=role_data["group"]
)
) for role_data in roles_data
]
get_item_instance(self, item_type: InstanceType, item_id: int) -> Optional[ItemInstance]
async
¶
Gets an item instance for a specific user.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
item_type |
InstanceType |
The type of item to get an instance for. |
required |
item_id |
int |
The item's ID. |
required |
Source code in roblox/bases/baseuser.py
async def get_item_instance(self, item_type: InstanceType, item_id: int) -> Optional[ItemInstance]:
"""
Gets an item instance for a specific user.
Arguments:
item_type: The type of item to get an instance for.
item_id: The item's ID.
Returns: An ItemInstance, if it exists.
"""
item_type: str = item_type.value.lower()
# this is so we can have special classes for other types
item_class = instance_classes.get(item_type) or ItemInstance
instance_response = await self._shared.requests.get(
url=self._shared.url_generator.get_url("inventory", f"v1/users/{self.id}/items/{item_type}/{item_id}")
)
instance_data = instance_response.json()["data"]
if len(instance_data) > 0:
return item_class(
shared=self._shared,
data=instance_data[0]
)
else:
return None
get_presence(self) -> Optional[Presence]
async
¶
Grabs the user's presence.
Returns:
Type | Description |
---|---|
Optional[Presence] |
The user's presence, if they have an active presence. |
Source code in roblox/bases/baseuser.py
async def get_presence(self) -> Optional[Presence]:
"""
Grabs the user's presence.
Returns:
The user's presence, if they have an active presence.
"""
presences = await self._shared.presence_provider.get_user_presences([self.id])
try:
return presences[0]
except IndexError:
return None
get_primary_group_role(self) -> Optional[Role]
async
¶
Gets a role for the primary group this user is in.
Returns:
Type | Description |
---|---|
Optional[Role] |
Role |
Source code in roblox/bases/baseuser.py
async def get_primary_group_role(self) -> Optional[Role]:
"""
Gets a role for the primary group this user is in.
Returns:
Role
"""
from ..roles import Role
from ..groups import Group
roles_response = await self._shared.requests.get(
url=self._shared.url_generator.get_url("groups", f"v1/users/{self.id}/groups/primary/role")
)
json = roles_response.json()
if json is None:
return None
return Role(
shared=self._shared,
data=json["role"],
group=Group(
shared=self._shared,
data=json["group"]
)
)
get_promotion_channels(self) -> UserPromotionChannels
async
¶
Gets the user's promotion channels.
Returns:
Type | Description |
---|---|
UserPromotionChannels |
The user's promotion channels. |
Source code in roblox/bases/baseuser.py
async def get_promotion_channels(self) -> UserPromotionChannels:
"""
Gets the user's promotion channels.
Returns:
The user's promotion channels.
"""
channels_response = await self._shared.requests.get(
url=self._shared.url_generator.get_url("accountinformation", f"v1/users/{self.id}/promotion-channels")
)
channels_data = channels_response.json()
return UserPromotionChannels(
data=channels_data
)
get_roblox_badges(self) -> List[RobloxBadge]
async
¶
Gets the user's Roblox badges.
Returns:
Type | Description |
---|---|
List[RobloxBadge] |
A list of Roblox badges. |
Source code in roblox/bases/baseuser.py
async def get_roblox_badges(self) -> List[RobloxBadge]:
"""
Gets the user's Roblox badges.
Returns:
A list of Roblox badges.
"""
badges_response = await self._shared.requests.get(
url=self._shared.url_generator.get_url("accountinformation", f"v1/users/{self.id}/roblox-badges")
)
badges_data = badges_response.json()
return [RobloxBadge(shared=self._shared, data=badge_data) for badge_data in badges_data]
get_status(self) -> str
async
¶
Grabs the user's status.
Returns:
Type | Description |
---|---|
str |
The user's status. |
Source code in roblox/bases/baseuser.py
async def get_status(self) -> str:
"""
Grabs the user's status.
Returns:
The user's status.
"""
status_response = await self._shared.requests.get(
url=self._shared.url_generator.get_url(
"users", f"/v1/users/{self.id}/status"
)
)
status_data = status_response.json()
return status_data["status"]
has_premium(self) -> bool
async
¶
Checks if the user has a Roblox Premium membership.
Returns:
Type | Description |
---|---|
bool |
Whether the user has Premium or not. |
Source code in roblox/bases/baseuser.py
async def has_premium(self) -> bool:
"""
Checks if the user has a Roblox Premium membership.
Returns:
Whether the user has Premium or not.
"""
premium_response = await self._shared.requests.get(
url=self._shared.url_generator.get_url("premiumfeatures", f"v1/users/{self.id}/validate-membership")
)
premium_data = premium_response.text
return premium_data == "true"
username_history(self, page_size: int = 10, sort_order: SortOrder = <SortOrder.Ascending: 'Asc'>, max_items: int = None) -> PageIterator
¶
Grabs the user's username history.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
page_size |
int |
How many members should be returned for each page. |
10 |
sort_order |
SortOrder |
Order in which data should be grabbed. |
<SortOrder.Ascending: 'Asc'> |
max_items |
int |
The maximum items to return when looping through this object. |
None |
Returns:
Type | Description |
---|---|
PageIterator |
A PageIterator containing the user's username history. |
Source code in roblox/bases/baseuser.py
def username_history(
self, page_size: int = 10, sort_order: SortOrder = SortOrder.Ascending, max_items: int = None
) -> PageIterator:
"""
Grabs the user's username history.
Arguments:
page_size: How many members should be returned for each page.
sort_order: Order in which data should be grabbed.
max_items: The maximum items to return when looping through this object.
Returns:
A PageIterator containing the user's username history.
"""
return PageIterator(
shared=self._shared,
url=self._shared.url_generator.get_url(
"users", f"v1/users/{self.id}/username-history"
),
page_size=page_size,
sort_order=sort_order,
max_items=max_items,
handler=lambda shared, data: data["name"],
)