Client¶
Client¶
-
class
gd.Client(*, load_after_post: bool = True, **http_args)[source]¶ Main class in gd.py, used for interacting with the servers of Geometry Dash.
- Parameters
load_after_post (
bool) –Whether to load comments/messages/requests after sending them.
Note
Defaults to
True, in which case the following method calls will return entities:send_message();send_friend_request();comment_level();post_comment().
Otherwise, if
Falseor not found, these methods will returnNone.**http_args – Arguments to pass to
HTTPClientconstructor.
-
database¶ Client’s database, used for working with saves. There is an alias for it called
db.- Type
-
edit(**attrs) → gd.client.Client[source]¶ Edit attributes of the client.
- Parameters
**attrs – Attributes to add.
- Returns
Current client.
- Return type
-
is_logged() → bool[source]¶ Check wether the client is logged in.
- Returns
Trueif client is logged in,Falseotherwise.- Return type
-
run(maybe_awaitable: Union[Awaitable[T], T]) → T[source]¶ Run given maybe awaitable object and return the result.
- Parameters
maybe_awaitable (Union[Awaitable[
T],T]) – Maybe awaitable object to execute.- Returns
Result of the execution.
- Return type
T
-
property
http¶ Same as
gd.Session.http.- Type
-
async
logout() → None[source]¶ Logout from account.
Example
>>> await client.login("user", "password") >>> await client.logout() >>> client.id 0
-
login(name: str, password: str) → gd.client.LoginContextManager[source]¶ - Async-with
Return context manager that can be used to temporarily log in, logging out on exit.
Awaiting on the context manager will act the same as actually logging in.
Example
>>> async with client.login("user", "password"): ... async for friend in client.get_friends(): ... print(friend)
-
async
do_login(name: str, password: str) → None[source]¶ Login into an account and update client’s settings.
Example
>>> await client.do_login("user", "password") >>> client.name "user" >>> client.password "password"
-
unsafe_login(name: str, password: str) → gd.client.LoginContextManager[source]¶ - Async-with
Return context manager that can be used to temporarily log in unsafely, logging out on exit.
Awaiting on the context manager will act the same as actually logging in.
Example
>>> await client.unsafe_login("user", "password") >>> client.name "user" >>> client.password "password"
-
async
do_unsafe_login(name: str, password: str) → None[source]¶ Login into an account and update client’s settings.
This function is not safe, because it does not use login endpoint.
Instead, it assumes that credentials are correct, and only searches for ID and Account ID.
Example
>>> await client.do_unsafe_login("user", "password") >>> client.name "user" >>> client.password "password"
-
load() → gd.api.database.Database[source]¶ Load cloud save and process it.
This returns a
Database, and setsclient.databaseto it.Example
>>> await client.login("user", "password") >>> database = await client.load() # load current save >>> print(database.user_name) # print current user name
- Raises
MissingAccess – Failed to load the save.
HTTPStatusError – Server returned error status code.
HTTPError – Failed to process the request.
- Returns
Loaded database.
- Return type
-
save(database: Optional[gd.api.database.Database] = None) → None[source]¶ Send save to the cloud.
Example
>>> await client.login("user", "password") >>> await client.load() # load current save >>> client.database.set_bootups(0) # set "bootups" value to "0" >>> await client.save()
- Parameters
database (Optional[
Database]) – Database to save. If not given orNone, tries to usedatabase.- Raises
MissingAccess – Failed to save the database, or it is empty (i.e. not changed).
HTTPStatusError – Server returned error status code.
HTTPError – Failed to process the request.
-
update_profile(stars: Optional[int] = None, diamonds: Optional[int] = None, coins: Optional[int] = None, user_coins: Optional[int] = None, demons: Optional[int] = None, icon_type: Optional[Union[int, str, gd.enums.IconType]] = None, icon: Optional[int] = None, color_1_id: Optional[int] = None, color_2_id: Optional[int] = None, has_glow: Optional[bool] = None, cube: Optional[int] = None, ship: Optional[int] = None, ball: Optional[int] = None, ufo: Optional[int] = None, wave: Optional[int] = None, robot: Optional[int] = None, spider: Optional[int] = None, death_effect: Optional[int] = None, special: int = 0, *, set_as_user: Optional[gd.user.User] = None) → None[source]¶ Update profile of the client.
Example
>>> await client.update_profile(has_glow=True) # enable glow outline
- Parameters
stars (Optional[
int]) – Amount of stars to set.diamonds (Optional[
int]) – Amount of diamonds to set.coins (Optional[
int]) – Amount of coins to set.user_coins (Optional[
int]) – Amount of user coins to set.demons (Optional[
int]) – Amount of demons to set.icon_type (Optional[Union[
int,str,IconType]]) – Icon type to use. SeeIconTypefor more info.icon (Optional[
int]) – Icon ID to set.color_1_id (Optional[
int]) – ID of primary color to use.color_2_id (Optional[
int]) – ID of secondary color to use.has_glow (Optional[
bool]) – Whether to use glow outline.cube (Optional[
int]) – ID of cube to use.ship (Optional[
int]) – ID of ship to use.ball (Optional[
int]) – ID of ball to use.ufo (Optional[
int]) – ID of ufo to use.wave (Optional[
int]) – ID of wave to use.robot (Optional[
int]) – ID of robot to use.spider (Optional[
int]) – ID of spider to use.death_effect (Optional[
int]) – ID of death effect to use.special (
int) – Special number to use. Default is0.set_as_user (Optional[
User]) –User to get all missing parameters from. If not given or
None,useris used, which implies that:await client.update_profile()
Will cause no effect.
-
update_settings(message_state: Optional[Union[int, str, gd.enums.MessageState]] = None, friend_request_state: Optional[Union[int, str, gd.enums.FriendRequestState]] = None, comment_state: Optional[Union[int, str, gd.enums.CommentState]] = None, youtube: Optional[str] = None, twitter: Optional[str] = None, twitch: Optional[str] = None, *, set_as_user: Optional[gd.user.User] = None) → None[source]¶ Update profile of the client.
Example
>>> await client.update_settings(comment_state="open_to_all") # open comments to everyone
- Parameters
message_state (Optional[Union[
int,str,MessageState]]) – Message state to set. SeeMessageState.friend_request_state (Optional[Union[
int,str,FriendRequestState]]) – Friend request state to set. SeeFriendRequestState.comment_state (Optional[Union[
int,str,CommentState]]) – Comment state to set. SeeCommentState.youtube (Optional[
str]) – YouTube channel ID to set. In link:https://youtube.com/channel/{youtube}.twitter (Optional[
str]) – Twitter ID to set. In link:https://twitter.com/{twitter}.twitch (Optional[
str]) – Twitch ID to set. In linkhttps://twitch.tv/{twitch}.set_as_user (Optional[
User]) –User to get all missing parameters from. If not given or
None,useris used, which implies that:await client.update_settings()
Will cause no effect.
-
async
on_daily(level: gd.level.Level) → T[source]¶ This is the event that is fired when a new daily level is set. See Event Reference for more info.
-
async
on_weekly(level: gd.level.Level) → T[source]¶ This is the event that is fired when a new weekly demon is assigned. See Event Reference for more info.
-
async
on_rate(level: gd.level.Level) → T[source]¶ This is the event that is fired when a new level is rated. See Event Reference for more info.
-
async
on_unrate(level: gd.level.Level) → T[source]¶ This is the event that is fired when a level is unrated. See Event Reference for more info.
-
async
on_message(message: gd.message.Message) → T[source]¶ This is the event that is fired when a logged in client gets a message. See Event Reference for more info.
-
async
on_friend_request(friend_request: gd.friend_request.FriendRequest) → T[source]¶ This is the event that is fired when a logged in client gets a friend request. See Event Reference for more info.
-
async
on_level_comment(level: gd.level.Level, comment: gd.comment.Comment) → T[source]¶ This is the event that is fired when a comment is posted on some level. See Event Reference for more info.
-
async
dispatch(event_name: str, *args, **kwargs) → None[source]¶ Dispatch an event given by
event_namewith*argsand**kwargs.- Parameters
event_name (
str) – Name of event to dispatch withouton_prefix, e.g."new_daily".*args – Args to call handler with.
**kwargs – Keyword args to call handler with.