Comments, Friend Requests and Messages¶
gd.py implements reading, sending and interacting with comments, friend requests and messages:
client = gd.Client()
# we can only read comments if we are not logged in.
await client.login("username", "password")
nekit = await client.search_user("nekitdev")
# <User name='nekitdev' id=17876467 account_id=5509312>
async for comment in nekit.get_profile_comments():
print(comment.body)
# find some featured level by user
level = await nekit.search_levels().find(lambda level: level.is_featured())
# if found, print comments
if level is not None:
async for comment in level.get_comments():
print(comment)
# print some messages
async for message in client.get_messages():
print(message.author.name, message.subject)
# send a friend request
await nekit.send_friend_request("Sent from gd.py")
# post a comment
await client.post_comment("This comment is posted using gd.py")
Comment¶
-
class
gd.Comment(*, client: Optional[Client] = None, **options)[source]¶ Class that represents a Profile/Level comment in Geometry Dash. This class is derived from
AbstractEntity.-
x == y Check if two objects are equal. Compared by hash and type.
-
x != y Check if two objects are not equal.
-
str(x) Return content of the comment.
-
repr(x) Return representation of the comment, useful for debugging.
-
hash(x) Returns
hash(self.hash_str).
-
classmethod
from_model(model: gd.model.CommentModel, *, client: Optional[Client] = None, user: Optional[gd.user.User] = None) → Comment[source]¶ Initialize
CommentfromCommentModel.
An author of the comment.
- Type
-
property
type¶ Whether comment is on profile or on a level.
- Type
-
is_spam() → bool[source]¶ bool: Indicates whether a comment is marked as spam.Falseif profile comment.
-
async
like() → None[source]¶ Likes a comment.
- Raises
MissingAccess – Failed to like a comment.
HTTPStatusError – Server returned error status code.
HTTPError – Failed to process the request.
-
async
dislike() → None[source]¶ Dislikes a comment.
- Raises
MissingAccess – Failed to dislike a comment.
HTTPStatusError – Server returned error status code.
HTTPError – Failed to process the request.
-
async
delete() → None[source]¶ Deletes a comment from Geometry Dash servers.
- Raises
MissingAccess – Comment was not deleted.
HTTPStatusError – Server returned error status code.
HTTPError – Failed to process the request.
-
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.
-
Friend Request¶
-
class
gd.FriendRequest(*, client: Optional[Client] = None, **options)[source]¶ Class that represents a friend request. This class is derived from
AbstractEntity.-
x == y Check if two objects are equal. Compared by hash and type.
-
x != y Check if two objects are not equal.
-
str(x) Return content of the friend request.
-
repr(x) Return representation of the friend request, useful for debugging.
-
hash(x) Returns
hash(self.hash_str).
-
classmethod
from_model(model: gd.model.FriendRequestModel, *, client: Optional[Client] = None, other_user: Optional[gd.user.User] = None, type: gd.enums.FriendRequestType = <FriendRequestType.INCOMING: 0>) → FriendRequest[source]¶ Create new entity from given
model,argsandkwargs.
Author of the friend request.
- Type
-
property
type¶ Whether request is incoming or sent.
- Type
-
async
read() → None[source]¶ Read a friend request. Sets
is_readtoTrueon success.- Raises
MissingAccess – Failed to read a request.
HTTPStatusError – Server returned error status code.
HTTPError – Failed to process the request.
-
async
delete() → None[source]¶ Delete a friend request.
- Raises
MissingAccess – Failed to delete a request.
HTTPStatusError – Server returned error status code.
HTTPError – Failed to process the request.
-
async
accept() → None[source]¶ Accept a friend request.
- Raises
MissingAccess – Failed to accept a request.
HTTPStatusError – Server returned error status code.
HTTPError – Failed to process the request.
-
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.
-
Message¶
-
class
gd.Message(*, client: Optional[Client] = None, **options)[source]¶ Class that represents private messages in Geometry Dash. This class is derived from
AbstractEntity.-
x == y Check if two objects are equal. Compared by hash and type.
-
x != y Check if two objects are not equal.
-
str(x) Return content of the message. Empty if the message was not read yet.
-
repr(x) Return representation of the message, useful for debugging.
-
hash(x) Returns
hash(self.hash_str).
-
classmethod
from_model(model: gd.model.MessageModel, *, client: Optional[Client] = None, other_user: Optional[gd.user.User] = None, type: gd.enums.MessageType = <MessageType.INCOMING: 0>) → Message[source]¶ Create new entity from given
model,argsandkwargs.
Author of the message.
- Type
-
property
type¶ Whether a message is sent or incoming.
- Type
-
async
read() → str[source]¶ Read a message. Set the body of the message to the content.
- Raises
MissingAccess – Failed to read a message.
HTTPStatusError – Server returned error status code.
HTTPError – Failed to process the request.
- Returns
The content of the message.
- Return type
-
async
reply(content: str, schema: Optional[str] = None) → Optional[gd.message.Message][source]¶ Reply to the message. Format the subject according to schema.
Schema format can only contain
{message.attribute}elements.Content also allows schema format.
Example:
await message.reply( content="Replying to message by {message.author.name}." schema="Re: {message.subject} ({message.rating})" )
- Raises
MissingAccess – Failed to read a message.
HTTPStatusError – Server returned error status code.
HTTPError – Failed to process the request.
- Returns
Sent message, or
Noneifload_after_postisFalse.- Return type
Optional[
Message]
-
async
delete() → None[source]¶ Delete a message.
- Raises
gd.MissingAccess – Failed to delete a message.
HTTPStatusError – Server returned error status code.
HTTPError – Failed to process the request.
-
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.
-