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]
to_dict()Dict[str, Any][source]

Convert the entity to a dictionary.

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, args and kwargs.

property name

String representing name of the user.

Type

str

property account_id

Account ID of the user.

Type

int

is_registered()bool[source]

bool: Indicates whether user is registered or not.

property stars

Amount of stars the user has.

Type

int

property demons

Amount of demons the user has beaten.

Type

int

property cp

Amount of Creator Points the user has.

Type

int

property diamonds

Amount of diamonds the user has.

Type

int

property coins

Number of coins the user has.

Type

int

property user_coins

Amount of User Coins user has.

Type

int

get_place()int[source]

int: User’s place in leaderboard. 0 if not set.

set_place(place: int = 0)None[source]

Set the self.place to place argument.

property place

User’s place in leaderboard. 0 if not set.

Type

int

has_cp()bool[source]

bool: Indicates if a user has Creator Points.

property role

A status level of the user.

Type

Role

property rank

A global rank of the user. None if the user is not on the leaderboard.

Type

Optional[int]

property youtube

A youtube name of the user.

Type

str

A link to the user’s youtube channel.

Type

str

property twitter

A twitter name of the user.

Type

str

A link to the user’s twitter page.

Type

str

property twitch

A twitch name of the user.

Type

str

A link to the user’s twitch channel.

Type

str

property message_state

A type indicating user’s message inbox state.

Type

MessageState

property friend_request_state

A type indicating user’s friend requests state.

Type

FriendRequestState

property comment_state

A type indicating user’s comment history policy.

Type

CommentState

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() -> True and robtop.is_mod("elder_moderator") -> True.

property banned

Indicates whether the user is banned.

Type

bool

is_banned()bool[source]

Indicates whether the user is banned.

property percent

Record percentage. -1 if not in the level leaderboard.

Type

int

property recorded_at

Record timestamp. None if not in the level leaderboard.

Type

Optional[datetime.datetime]

property icon_type

Type of user’s main icon.

Type

IconType

property icon

ID of user’s icon.

Type

int

property cube

ID of user’s cube.

Type

int

property ship

ID of user’s ship.

Type

int

property ball

ID of user’s ball.

Type

int

property ufo

ID of user’s UFO.

Type

int

property wave

ID of user’s wave.

Type

int

property robot

ID of user’s robot.

Type

int

property spider

ID of user’s spider.

Type

int

property death_effect

ID of user’s death effect.

Type

int

property color_1_id

ID of user’s primary color.

Type

int

property color_2_id

ID of user’s secondary color.

Type

int

property color_1

User’s primary color.

Type

Color

property color_2

User’s secondary color.

Type

Color

has_glow()bool[source]

Whether the user has glow outline enabled.

has_glow_outline()bool

Whether the user has glow outline enabled.

async get_user()gd.user.User[source]

Get the user by account_id.

Raises
Returns

Fetched user.

Return type

User

async update()gd.user.User[source]

Update the user.

Raises
Returns

Refreshed user. (self)

Return type

User

async send(subject: Optional[str] = None, body: Optional[str] = None)Optional[Message][source]

Send the message to self. Requires logged client.

Parameters
  • subject (str) – The subject of the message.

  • body (str) – The body of the message.

Raises
Returns

Sent message.

Return type

Optional[Message]

async block()None[source]

Block a user. Requires logged in client.

Raises
async unblock()None[source]

Unblock a user. Requires logged in client.

Raises
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
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
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
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
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
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
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
  • pages (Iterable[int]) – Pages to search on.

  • concurrent (bool) – Whether to run comment searching concurrently or sequentially.

Raises
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
  • pages (Iterable[int]) – Pages to search on.

  • concurrent (bool) – Whether to run comment searching concurrently or sequentially.

Raises
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
  • pages (Iterable[int]) – Pages to search on.

  • concurrent (bool) – Whether to run comment searching concurrently or sequentially.

Raises
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.

Parameters
  • type (Optional[Union[int, str, IconType]]) – Type of an icon to generate. If not given or "icon", picks current icon.

  • as_image (bool) – Whether to return an image or bytes of an image. True by default.

Returns

Bytes or an image, based on as_image.

Return type

Union[bytes, Image]

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
  • *types (Union[int, str, IconType]) – Types of icons to generate. If "icon" is given, picks current main icon.

  • as_image (bool) – Whether to return images or bytes of images. True by default.

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.

Parameters
  • *types (Iterable[Optional[Union[int, str, IconType]]]) – Types of icons to generate. If "icon" is given, picks current main icon.

  • as_image (bool) – Whether to return an image or bytes of an image.

Returns

Bytes or an image, based on as_image.

Return type

Union[bytes, Image]

async generate_full(as_image: bool = True)Union[bytes, PIL.Image.Image][source]

Generate an image of the full icon set.

Parameters

as_image (bool) – Whether to return an image or bytes of an image.

Returns

Bytes or an image, based on as_image.

Return type

Union[bytes, Image]

attach_client(client: Optional[Client] = None)AbstractEntityT

Attach client to self.

Parameters

client (Optional[gd.Client]) – Client to attach. If None or not given, will be detached.

Returns

This abstract entity.

Return type

AbstractEntity

property client

Client attached to this object. This checks if client is not present, and raises ClientException in that case.

Type

Client

property client_unchecked

Client attached to this object.

Type

Optional[Client]

detach_client()AbstractEntityT

Detach client from self.

Same as calling:

self.attach_client(None)
Returns

This abstract entity.

Return type

AbstractEntity

classmethod from_dict(*data: Dict[str, Any], client: Optional[Client] = None, **kwargs)AbstractEntityT

Create new entity from dictionaries in data, with client and kwargs.

classmethod from_dicts(*data: Dict[str, Any], client: Optional[Client] = None, **kwargs)AbstractEntityT

Create new entity from dictionaries in data, with client and kwargs.

classmethod from_models(*models: gd.model_backend.Model, **kwargs)AbstractEntityT

Create new entity from given models by calling from_model with kwargs.

property hash_str

String used for hashing, with format <Class(ID->id)>.

Type

str

property id

ID of the Entity.

Type

int

update_inner(**options: Any)AbstractEntityT

Update self.options with options.

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).

value

The raw integer colour value.

Type

int

property id

Returns ID that represents position of the color. None if not a default one.

Type

Optional[int]

property r

Returns the red component of the colour.

Type

int

property g

Returns the green component of the colour.

Type

int

property b

Returns the blue component of the colour.

Type

int

to_hex()str[source]

str: Returns the colour in hex format.

to_rgb()Tuple[int, int, int][source]

Return a tuple representing the color.

Returns

(r, g, b) tuple representing the color.

Return type

Tuple[int, int, int]

to_rgba(alpha: int = 255)Tuple[int, int, int, int][source]

Same as gd.Color.to_rgb(), but contains alpha component.

Parameters

alpha (int) – Value of an alpha channel to use. Defaults to 255, meaning full value.

Returns

(r, g, b, a) tuple representing the color.

Return type

Tuple[int, int, int, int]

ansi_escape(string: Optional[str] = None)str[source]

Color string using ANSI representation of the color. If not given, to_hex() is used.

paint(string: Optional[str] = None)str

Color string using ANSI representation of the color. If not given, to_hex() is used.

classmethod from_hex(hex_str: str)gd.color.Color[source]

Constructs Color from hex string, e.g. 0x7289da or #000000.

classmethod from_rgb(r: int, g: int, b: int)gd.color.Color[source]

Constructs a Color from an RGB tuple.

classmethod from_hsv(h: float, s: float, v: float)gd.color.Color[source]

Constructs a Color from an HSV (HSB) tuple.

classmethod from_rgb_string(string: str, delim: str = ',')gd.color.Color[source]

Constructs a Color from RGB string, e.g. 255,255,255.

classmethod with_id(id: int, default: Optional[gd.color.Color] = None)gd.color.Color[source]

Creates a Color with in-game ID of id.

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.