Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

publish yaylib 1.5.0 beta 2 #71

Merged
merged 2 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion yaylib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# 1.0.0rc1 Release Candidate
# 1.0.0 Final Release
# 1.0.0.post1 Post Release
__version__ = "1.5.0.b1"
__version__ = "1.5.0.b2"

from .client import Client
from .constants import *
Expand Down
18 changes: 10 additions & 8 deletions yaylib/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,8 @@ async def restore_user(self, **params) -> LoginUserResponse:
Returns:
LoginUserResponse:
"""
return await self.__client.request(
"POST",
config.API_HOST + "/v2/users/restore",
json={
params.update(
{
"api_key": config.API_KEY,
"uuid": self.__client.device_uuid,
"timestamp": int(datetime.now().timestamp()),
Expand All @@ -206,7 +204,12 @@ async def restore_user(self, **params) -> LoginUserResponse:
int(datetime.now().timestamp()),
False,
),
}.update(params),
}
)
return await self.__client.request(
"POST",
config.API_HOST + "/v2/users/restore",
json=params,
)

async def save_account_with_email(self, **params) -> LoginUpdateResponse:
Expand All @@ -221,11 +224,10 @@ async def save_account_with_email(self, **params) -> LoginUpdateResponse:
Returns:
LoginUpdateResponse:
"""
params.update({"api_key": config.API_KEY})
return await self.__client.request(
"POST",
config.API_HOST + "/v3/users/login_update",
json={
"api_key": config.API_KEY,
}.update(params),
json=params,
return_type=LoginUpdateResponse,
)
26 changes: 16 additions & 10 deletions yaylib/api/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,20 @@ async def create_group(self, **params) -> CreateGroupResponse:
Returns:
CreateGroupResponse:
"""
return await self.__client.request(
"POST",
config.API_HOST + "/v3/groups/new",
json={
params.update(
{
"uuid": self.__client.device_uuid,
"api_key": config.API_KEY,
"timestamp": int(datetime.now().timestamp()),
"signed_info": md5(
self.__client.device_uuid, int(datetime.now().timestamp()), True
),
}.update(params),
}
)
return await self.__client.request(
"POST",
config.API_HOST + "/v3/groups/new",
json=params,
return_type=CreateGroupResponse,
)

Expand Down Expand Up @@ -744,17 +747,20 @@ async def update_group(self, group_id: int, **params) -> GroupResponse:
Returns:
GroupResponse:
"""
return await self.__client.request(
"POST",
config.API_HOST + f"/v3/groups/{group_id}/update",
json={
params.update(
{
"uuid": self.__client.device_uuid,
"api_key": config.API_KEY,
"timestamp": int(datetime.now().timestamp()),
"signed_info": md5(
self.__client.device_uuid, int(datetime.now().timestamp()), True
),
}.update(params),
}
)
return await self.__client.request(
"POST",
config.API_HOST + f"/v3/groups/{group_id}/update",
json=params,
return_type=GroupResponse,
)

Expand Down
102 changes: 66 additions & 36 deletions yaylib/api/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,27 @@ async def create_call_post(self, text: str = None, **params) -> CreatePostRespon
Returns:
CreatePostResponse:
"""
text, message_tags = build_message_tags(text)
result = build_message_tags(text)
if result is not None:
text, message_tags = result

return await self.__client.request(
"POST",
config.API_HOST + "/v1/posts/new_conference_call",
json={
params.update(
{
"text": text,
"uuid": self.__client.device_uuid,
"api_key": config.API_KEY,
"timestamp": int(datetime.now().timestamp()),
"signed_info": md5(
self.__client.device_uuid, int(datetime.now().timestamp()), False
),
"message_tags": [] if message_tags is None else message_tags,
}.update(params),
"message_tags": [] if result is None else message_tags,
}
)

return await self.__client.request(
"POST",
config.API_HOST + "/v1/posts/new_conference_call",
json=params,
return_type=CreatePostResponse,
)

Expand Down Expand Up @@ -188,7 +194,9 @@ async def create_post(self, text: str = None, **params) -> Post:
Returns:
Post:
"""
text, message_tags = build_message_tags(text)
result = build_message_tags(text)
if result is not None:
text, message_tags = result

post_type = get_post_type(
choices=params.get("choices"),
Expand All @@ -197,7 +205,8 @@ async def create_post(self, text: str = None, **params) -> Post:
attachment_filename=params.get("attachment_filename"),
)

if params.get("shared_url") is not None:
shared_url = params.get("shared_url")
if shared_url is not None:
try:
shared_url = (
await self.get_url_metadata(url=params.get("shared_url"))
Expand All @@ -206,15 +215,19 @@ async def create_post(self, text: str = None, **params) -> Post:
self.__client.logger.error("Unable to get the URL metadata.")
shared_url = None

return await self.__client.request(
"POST",
config.API_HOST + "/v3/posts/new",
json={
params.update(
{
"text": text,
"post_type": post_type,
"shared_url": shared_url,
"message_tags": [] if message_tags is None else message_tags,
}.update(params),
"message_tags": [] if result is None else message_tags,
}
)

return await self.__client.request(
"POST",
config.API_HOST + "/v3/posts/new",
json=params,
return_type=Post,
jwt_required=True,
)
Expand Down Expand Up @@ -249,7 +262,9 @@ async def create_repost(
Returns:
CreatePostResponse:
"""
text, message_tags = build_message_tags(text)
result = build_message_tags(text)
if result is not None:
text, message_tags = result

post_type = get_post_type(
choices=params.get("choices"),
Expand All @@ -267,16 +282,20 @@ async def create_repost(
self.__client.logger.error("Unable to get the URL metadata.")
shared_url = None

return await self.__client.request(
"POST",
config.API_HOST + "/v3/posts/repost",
json={
params.update(
{
"post_id": post_id,
"text": text,
"post_type": post_type,
"shared_url": shared_url,
"message_tags": [] if message_tags is None else message_tags,
}.update(params),
"message_tags": [] if result is None else message_tags,
}
)

return await self.__client.request(
"POST",
config.API_HOST + "/v3/posts/repost",
json=params,
return_type=CreatePostResponse,
jwt_required=True,
)
Expand All @@ -297,10 +316,8 @@ async def create_share_post(
Returns:
Post:
"""
return await self.__client.request(
"POST",
config.API_HOST + "/v2/posts/new_share_post",
json={
params.update(
{
"shareable_type": shareable_type,
"shareable_id": shareable_id,
"text": text,
Expand All @@ -310,7 +327,12 @@ async def create_share_post(
"signed_info": md5(
self.__client.device_uuid, int(datetime.now().timestamp()), False
),
}.update(params),
}
)
return await self.__client.request(
"POST",
config.API_HOST + "/v2/posts/new_share_post",
json=params,
return_type=Post,
)

Expand Down Expand Up @@ -344,7 +366,9 @@ async def create_thread_post(
Returns:
Post:
"""
text, message_tags = build_message_tags(text)
result = build_message_tags(text)
if result is not None:
text, message_tags = result

post_type = get_post_type(
choices=params.get("choices"),
Expand All @@ -369,7 +393,7 @@ async def create_thread_post(
"text": text,
"post_type": post_type,
"shared_url": shared_url,
"message_tags": [] if message_tags is None else message_tags,
"message_tags": [] if result is None else message_tags,
},
return_type=Post,
jwt_required=True,
Expand Down Expand Up @@ -921,20 +945,26 @@ async def update_post(
Returns:
Post:
"""
text, message_tags = build_message_tags(text)
result = build_message_tags(text)
if result is not None:
text, message_tags = result

return await self.__client.request(
"PUT",
config.API_HOST + f"/v3/posts/{post_id}",
json={
params.update(
{
"text": text,
"message_tags": [] if message_tags is None else message_tags,
"message_tags": [] if result is None else message_tags,
"api_key": config.API_KEY,
"timestamp": int(datetime.now().timestamp()),
"signed_info": md5(
self.__client.device_uuid, int(datetime.now().timestamp()), False
),
}.update(params),
}
)

return await self.__client.request(
"PUT",
config.API_HOST + f"/v3/posts/{post_id}",
json=params,
)

async def view_video(self, video_id: int) -> Response:
Expand Down
39 changes: 24 additions & 15 deletions yaylib/api/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,10 +444,8 @@ async def register(self, **params) -> CreateUserResponse:
Returns:
CreateUserResponse:
"""
return await self.__client.request(
"POST",
config.API_HOST + "/v3/users/register",
json={
params.update(
{
"app_version": config.API_VERSION_NAME,
"api_key": config.API_KEY,
"signed_version": sha256(),
Expand All @@ -456,7 +454,12 @@ async def register(self, **params) -> CreateUserResponse:
self.__client.device_uuid, int(datetime.now().timestamp()), False
),
"uuid": self.__client.device_uuid,
}.update(params),
}
)
return await self.__client.request(
"POST",
config.API_HOST + "/v3/users/register",
json=params,
return_type=CreateUserResponse,
)

Expand Down Expand Up @@ -555,18 +558,21 @@ async def set_follow_permission_enabled(self, **params) -> Response:
Returns:
Response:
"""
return await self.__client.request(
"POST",
config.API_HOST + "/v2/users/edit",
json={
params.update(
{
"uuid": self.__client.device_uuid,
"api_key": config.API_KEY,
"timestamp": int(datetime.now().timestamp()),
"signed_info": md5(
self.__client.device_uuid, int(datetime.now().timestamp()), True
),
"signed_version": sha256(),
}.update(params),
}
)
return await self.__client.request(
"POST",
config.API_HOST + "/v2/users/edit",
json=params,
return_type=Response,
)

Expand Down Expand Up @@ -630,18 +636,21 @@ async def update_user(self, nickname: str, **params) -> Response:
Returns:
Response:
"""
return await self.__client.request(
"POST",
config.API_HOST + "/v3/users/edit",
json={
params.update(
{
"nickname": nickname,
"uuid": self.__client.device_uuid,
"api_key": config.API_KEY,
"timestamp": int(datetime.now().timestamp()),
"signed_info": md5(
self.__client.device_uuid, int(datetime.now().timestamp()), True
),
}.update(params),
}
)
return await self.__client.request(
"POST",
config.API_HOST + "/v3/users/edit",
json=params,
return_type=Response,
)

Expand Down
2 changes: 1 addition & 1 deletion yaylib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def build_message_tags(text: str) -> tuple[str, list[dict[str, Any]]]:

offset_adjustment += full_match_length - display_name_length

text: str = re.sub(r"<@>(\d+):([^<]+)<@/>", r"\2", text)
text = re.sub(r"<@>(\d+):([^<]+)<@/>", r"\2", text)
return text, message_tags


Expand Down
Loading