Users¶
User system is one of the main parts of GD Server API. gd.py provides convenient interface for simplifying interaction with them via modern pythonic code.
Here is a quick example of interacting with users:
client = gd.Client()
user = await client.get_user(71)
# <User name='RobTop' id=16 account_id=71>
async for comment in user.get_comment_history(pages=range(20)):
print(comment.id, comment.rating, comment.body)
User¶
-
class
gd.User(*, client: Optional[Client] = None, **options)[source]¶ -
-
classmethod
from_model(model: Union[gd.model.CommentUserModel, gd.model.CreatorModel, gd.model.LeaderboardUserModel, gd.model.LevelLeaderboardUserModel, gd.model.ListUserModel, gd.model.ProfileUserModel, gd.model.SearchUserModel], *, client: Optional[Client] = None) → User[source]¶ Create new entity from given
model,argsandkwargs.
-
property
rank¶ A global rank of the user.
Noneif the user is not on the leaderboard.- Type
Optional[
int]
-
property
message_state¶ A type indicating user’s message inbox state.
- Type
-
property
friend_request_state¶ A type indicating user’s friend requests state.
- Type
-
property
comment_state¶ A type indicating user’s comment history policy.
- Type
-
property
friend_state¶ A type indicating relation between client and user.
- Type
FriendState
-
is_mod(role: Optional[Union[int, str, gd.enums.Role]] = None) → bool[source]¶ bool: Indicates if a user is Geometry Dash (Elder) Moderator. For instance, RobTop is an Elder Moderator, that means:robtop.is_mod() -> Trueandrobtop.is_mod("elder_moderator") -> True.
-
property
recorded_at¶ Record timestamp.
Noneif not in the level leaderboard.- Type
Optional[
datetime.datetime]
-
async
get_user() → gd.user.User[source]¶ Get the user by
account_id.- Raises
MissingAccess – Failed to find the user.
HTTPStatusError – Server returned error status code.
HTTPError – Failed to process the request.
- Returns
Fetched user.
- Return type
-
async
update() → gd.user.User[source]¶ Update the user.
- Raises
MissingAccess – Failed to find the user.
HTTPStatusError – Server returned error status code.
HTTPError – Failed to process the request.
- Returns
Refreshed user. (
self)- Return type
-
async
send(subject: Optional[str] = None, body: Optional[str] = None) → Optional[Message][source]¶ Send the message to
self. Requires logged client.- Parameters
- Raises
MissingAccess – Failed to send a message.
HTTPStatusError – Server returned error status code.
HTTPError – Failed to process the request.
- Returns
Sent message.
- Return type
Optional[
Message]
-
async
block() → None[source]¶ Block a user. Requires logged in client.
- Raises
MissingAccess – Failed to block a user.
HTTPStatusError – Server returned error status code.
HTTPError – Failed to process the request.
-
async
unblock() → None[source]¶ Unblock a user. Requires logged in client.
- Raises
MissingAccess – Failed to unblock a user.
HTTPStatusError – Server returned error status code.
HTTPError – Failed to process the request.
-
async
unfriend() → None[source]¶ Try to unfriend a user. Requires logged in client.
- Raises
MissingAccess – Failed to unfriend a user.
-
async
send_friend_request(message: Optional[str] = None) → Optional[FriendRequest][source]¶ Send a friend request to a user.
Note
This function does not raise any error if request was already sent.
- Parameters
message (Optional[
str]) – A message to attach to a request.- Raises
MissingAccess – Failed to send a friend request to user.
HTTPStatusError – Server returned error status code.
HTTPError – Failed to process the request.
- Returns
Sent friend request.
- Return type
Optional[
FriendRequest]
-
get_levels_on_page(page: int = 0) → AsyncIterator[Level][source]¶ Fetches user’s levels on a given page.
- Parameters
page (
int) – Page to look for levels at.- Raises
MissingAccess – Failed to get levels on page.
HTTPStatusError – Server returned error status code.
HTTPError – Failed to process the request.
- Returns
All levels found.
- Return type
AsyncIterator[
Level]
-
get_levels(pages: Iterable[int] = range(0, 10), concurrent: bool = True) → AsyncIterator[Level][source]¶ Gets levels on specified pages.
- Parameters
pages (Iterable[
int]) – Pages to look at, represented as a finite iterable.- Raises
HTTPStatusError – Server returned error status code.
HTTPError – Failed to process the request.
- Returns
All levels found.
- Return type
AsyncIterator[
Level]
-
get_profile_comments_on_page(page: int = 0) → AsyncIterator[Comment][source]¶ Gets user’s profile comments on a specific page.
- Parameters
page (
int) – Page to search on.- Raises
MissingAccess – Failed to get profile comments on page.
HTTPStatusError – Server returned error status code.
HTTPError – Failed to process the request.
- Returns
Comments found.
- Return type
AsyncIterator[
Comment]
-
get_comments_on_page(page: int = 0) → AsyncIterator[Comment]¶ Gets user’s profile comments on a specific page.
- Parameters
page (
int) – Page to search on.- Raises
MissingAccess – Failed to get profile comments on page.
HTTPStatusError – Server returned error status code.
HTTPError – Failed to process the request.
- Returns
Comments found.
- Return type
AsyncIterator[
Comment]
-
get_comment_history_on_page(strategy: Union[int, str, gd.enums.CommentStrategy] = <CommentStrategy.RECENT: 0>, page: int = 0) → AsyncIterator[Comment][source]¶ Retrieves user’s level comments. (history)
- Parameters
page (
int) – Page to search on.- Raises
MissingAccess – Failed to get comment history on page.
HTTPStatusError – Server returned error status code.
HTTPError – Failed to process the request.
- Returns
Comments found.
- Return type
AsyncIterator[
Comment]
-
get_profile_comments(pages: Iterable[int] = range(0, 10), concurrent: bool = True) → AsyncIterator[Comment][source]¶ Gets user’s profile comments on specific pages.
- Parameters
- Raises
HTTPStatusError – Server returned error status code.
HTTPError – Failed to process the request.
- Returns
Comments found.
- Return type
AsyncIterator[
Comment]
-
get_comments(pages: Iterable[int] = range(0, 10), concurrent: bool = True) → AsyncIterator[Comment]¶ Gets user’s profile comments on specific pages.
- Parameters
- Raises
HTTPStatusError – Server returned error status code.
HTTPError – Failed to process the request.
- Returns
Comments found.
- Return type
AsyncIterator[
Comment]
-
get_comment_history(strategy: Union[int, str, gd.enums.CommentStrategy] = <CommentStrategy.RECENT: 0>, pages: Iterable[int] = range(0, 10), concurrent: bool = True) → AsyncIterator[Comment][source]¶ Gets user’s level (history) comments on specific pages.
- Parameters
- Raises
HTTPStatusError – Server returned error status code.
HTTPError – Failed to process the request.
- Returns
Comments found.
- Return type
AsyncIterator[
Comment]
-
async
generate(type: Union[int, str, gd.enums.IconType] = 'icon', as_image: bool = True) → Union[bytes, PIL.Image.Image][source]¶ Generate an image of an icon.
-
generate_many(*types: Union[int, str, gd.enums.IconType], as_image: bool = True) → Union[AsyncIterator[bytes], AsyncIterator[PIL.Image.Image]][source]¶ Generate images of icons.
- Parameters
- Returns
Bytes or images, based on
as_image.- Return type
Union[AsyncIterator[
bytes], AsyncIterator[Image]]
-
async
generate_image(*types: Union[int, str, gd.enums.IconType], as_image: bool = True) → Union[bytes, PIL.Image.Image][source]¶ Generate images of icons and connect them into one image.
-
async
generate_full(as_image: bool = True) → Union[bytes, PIL.Image.Image][source]¶ Generate an image of the full icon set.
-
attach_client(client: Optional[Client] = None) → AbstractEntityT¶ Attach
clienttoself.- Parameters
client (Optional[
gd.Client]) – Client to attach. IfNoneor not given, will be detached.- Returns
This abstract entity.
- Return type
-
property
client¶ Client attached to this object. This checks if client is not present, and raises
ClientExceptionin that case.- Type
-
detach_client() → AbstractEntityT¶ Detach
clientfromself.Same as calling:
self.attach_client(None)
- Returns
This abstract entity.
- Return type
-
classmethod
from_dict(*data: Dict[str, Any], client: Optional[Client] = None, **kwargs) → AbstractEntityT¶ Create new entity from dictionaries in
data, withclientandkwargs.
-
classmethod
from_dicts(*data: Dict[str, Any], client: Optional[Client] = None, **kwargs) → AbstractEntityT¶ Create new entity from dictionaries in
data, withclientandkwargs.
-
classmethod
from_models(*models: gd.model_backend.Model, **kwargs) → AbstractEntityT¶ Create new entity from given
modelsby callingfrom_modelwithkwargs.
-
update_inner(**options: Any) → AbstractEntityT¶ Update
self.optionswithoptions.
-
classmethod
gd.py also provides interface to users’ icons and colors:
nekit = await client.get_user(5509312)
# <User name='nekitdev' id=17876467 account_id=5509312>
image = await nekit.generate_full(as_image=True) # generate full icon set image
image.save("nekit.png")
Color¶
-
class
gd.Color(value: int = 0)[source]¶ Represents a Color.
-
x == y Check if two colors are equal.
-
x != y Check if two colors are not equal.
-
str(x) Return hex of the color, e.g.
#ffffff.
-
repr(x) Return representation of the color, useful for debugging.
-
hash(x) Returns
hash(self.value).
-
property
id¶ Returns ID that represents position of the color.
Noneif not a default one.- Type
Optional[
int]
-
to_rgba(alpha: int = 255) → Tuple[int, int, int, int][source]¶ Same as
gd.Color.to_rgb(), but containsalphacomponent.
-
ansi_escape(string: Optional[str] = None) → str[source]¶ Color
stringusing ANSI representation of the color. If not given,to_hex()is used.
-
paint(string: Optional[str] = None) → str¶ Color
stringusing ANSI representation of the color. If not given,to_hex()is used.
-
classmethod
from_hex(hex_str: str) → gd.color.Color[source]¶ Constructs
Colorfrom hex string, e.g.0x7289daor#000000.
-
classmethod
from_rgb(r: int, g: int, b: int) → gd.color.Color[source]¶ Constructs a
Colorfrom an RGB tuple.
-
classmethod
from_hsv(h: float, s: float, v: float) → gd.color.Color[source]¶ Constructs a
Colorfrom an HSV (HSB) tuple.
-
classmethod
from_rgb_string(string: str, delim: str = ',') → gd.color.Color[source]¶ Constructs a
Colorfrom RGB string, e.g.255,255,255.
-
classmethod
with_id(id: int, default: Optional[gd.color.Color] = None) → gd.color.Color[source]¶ Creates a
Colorwith in-game ID ofid.
-
classmethod
iter_colors() → Iterator[gd.color.Color][source]¶ Returns an iterator over all in-game colors.
-
classmethod
list_colors() → List[gd.color.Color][source]¶ Same as
iter_colors(), but returns a list.
-