-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Add stickers * Add 'image not valid' error * fix docstrings * Update changelog Co-authored-by: MGorbachev <[email protected]>
- Loading branch information
Showing
43 changed files
with
1,854 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
"""Mixin for shortcut for users resource requests.""" | ||
|
||
from typing import List, Optional, Tuple | ||
from uuid import UUID | ||
|
||
from botx.bots.mixins.requests.call_protocol import BotXMethodCallProtocol | ||
from botx.clients.methods.v3.stickers.add_sticker import AddSticker | ||
from botx.clients.methods.v3.stickers.create_sticker_pack import CreateStickerPack | ||
from botx.clients.methods.v3.stickers.delete_sticker import DeleteSticker | ||
from botx.clients.methods.v3.stickers.delete_sticker_pack import DeleteStickerPack | ||
from botx.clients.methods.v3.stickers.edit_sticker_pack import EditStickerPack | ||
from botx.clients.methods.v3.stickers.sticker import GetSticker | ||
from botx.clients.methods.v3.stickers.sticker_pack import GetStickerPack | ||
from botx.clients.methods.v3.stickers.sticker_pack_list import GetStickerPackList | ||
from botx.models.messages.sending.credentials import SendingCredentials | ||
from botx.models.stickers import ( | ||
Sticker, | ||
StickerFromPack, | ||
StickerPack, | ||
StickerPackList, | ||
StickerPackPreview, | ||
) | ||
|
||
|
||
class StickersMixin: # noqa: WPS214 | ||
"""Mixin for shortcut for users resource requests.""" | ||
|
||
async def get_sticker_pack_list( | ||
self: BotXMethodCallProtocol, | ||
credentials: SendingCredentials, | ||
user_huid: Optional[UUID] = None, | ||
limit: int = 1, | ||
after: Optional[str] = None, | ||
) -> Tuple[List[StickerPackPreview], Optional[str]]: | ||
"""Get sticker pack list. | ||
Arguments: | ||
credentials: credentials for making request. | ||
user_huid: author HUID. | ||
limit: returning value count. | ||
after: cursor hash for pagination. | ||
Returns: | ||
Sticker packs list and cursor. | ||
""" | ||
response: StickerPackList = await self.call_method( | ||
GetStickerPackList(user_huid=user_huid, limit=limit, after=after), | ||
credentials=credentials, | ||
) | ||
|
||
return response.packs, response.pagination.after | ||
|
||
async def get_sticker_pack( | ||
self: BotXMethodCallProtocol, | ||
credentials: SendingCredentials, | ||
pack_id: UUID, | ||
) -> StickerPack: | ||
"""Get sticker pack. | ||
Arguments: | ||
credentials: credentials for making request. | ||
pack_id: sticker pack ID. | ||
Returns: | ||
StickerPack entity. | ||
""" | ||
return await self.call_method( | ||
GetStickerPack(pack_id=pack_id), | ||
credentials=credentials, | ||
) | ||
|
||
async def get_sticker_from_pack( | ||
self: BotXMethodCallProtocol, | ||
credentials: SendingCredentials, | ||
pack_id: UUID, | ||
sticker_id: UUID, | ||
) -> StickerFromPack: | ||
"""Get sticker from pack. | ||
Arguments: | ||
credentials: credentials for making request. | ||
pack_id: sticker pack ID. | ||
sticker_id: sticker ID. | ||
Returns: | ||
StickerFromPack entity. | ||
""" | ||
return await self.call_method( | ||
GetSticker(pack_id=pack_id, sticker_id=sticker_id), | ||
credentials=credentials, | ||
) | ||
|
||
async def create_sticker_pack( | ||
self: BotXMethodCallProtocol, | ||
credentials: SendingCredentials, | ||
name: str, | ||
user_huid: UUID, | ||
) -> StickerPack: | ||
"""Create sticker pack. | ||
Arguments: | ||
credentials: credentials for making request. | ||
name: sticker pack name. | ||
user_huid: author HUID. | ||
Returns: | ||
StickerPackPreview entity. | ||
""" | ||
return await self.call_method( | ||
CreateStickerPack(name=name, user_huid=user_huid), | ||
credentials=credentials, | ||
) | ||
|
||
async def add_sticker( | ||
self: BotXMethodCallProtocol, | ||
credentials: SendingCredentials, | ||
pack_id: UUID, | ||
emoji: str, | ||
image: str, | ||
) -> Sticker: | ||
"""Add sticker. | ||
Arguments: | ||
credentials: credentials for making request. | ||
pack_id: sticker pack ID. | ||
emoji: emoji that the sticker will be associated with. | ||
image: sticker image. | ||
Returns: | ||
Sticker entity. | ||
""" | ||
return await self.call_method( | ||
AddSticker(pack_id=pack_id, emoji=emoji, image=image), | ||
credentials=credentials, | ||
) | ||
|
||
async def edit_sticker_pack( # noqa: WPS211 | ||
self: BotXMethodCallProtocol, | ||
credentials: SendingCredentials, | ||
pack_id: UUID, | ||
name: str, | ||
preview: Optional[UUID] = None, | ||
stickers_order: Optional[List[UUID]] = None, | ||
) -> StickerPack: | ||
"""Edit sticker pack. | ||
Arguments: | ||
credentials: credentials for making request. | ||
pack_id: sticker pack ID. | ||
name: sticker pack name. | ||
preview: sticker pack preview. | ||
stickers_order: stickers order in sticker pack. | ||
Returns: | ||
StickerPack entity. | ||
""" | ||
return await self.call_method( | ||
EditStickerPack( | ||
pack_id=pack_id, | ||
name=name, | ||
preview=preview, | ||
stickers_order=stickers_order, | ||
), | ||
credentials=credentials, | ||
) | ||
|
||
async def delete_sticker_pack( | ||
self: BotXMethodCallProtocol, | ||
credentials: SendingCredentials, | ||
pack_id: UUID, | ||
) -> None: | ||
"""Delete sticker pack. | ||
Arguments: | ||
credentials: credentials for making request. | ||
pack_id: sticker pack ID. | ||
""" | ||
await self.call_method( | ||
DeleteStickerPack(pack_id=pack_id), | ||
credentials=credentials, | ||
) | ||
|
||
async def delete_sticker( | ||
self: BotXMethodCallProtocol, | ||
credentials: SendingCredentials, | ||
pack_id: UUID, | ||
sticker_id: UUID, | ||
) -> None: | ||
"""Delete sticker. | ||
Arguments: | ||
credentials: credentials for making request. | ||
pack_id: sticker pack ID. | ||
sticker_id: sticker ID. | ||
""" | ||
await self.call_method( | ||
DeleteSticker(pack_id=pack_id, sticker_id=sticker_id), | ||
credentials=credentials, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Definition for built-in error handlers for responses from BotX API.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"""Definition for "image is not valid" error.""" | ||
from typing import NoReturn | ||
|
||
from botx.clients.methods.base import BotXMethod | ||
from botx.clients.types.http import HTTPResponse | ||
from botx.exceptions import BotXAPIError | ||
|
||
|
||
class ImageNotValidError(BotXAPIError): | ||
"""Error for raising when image is not valid.""" | ||
|
||
message_template = "image is not valid" | ||
|
||
|
||
def handle_error(method: BotXMethod, response: HTTPResponse) -> NoReturn: | ||
"""Handle "image is not valid" error response. | ||
Arguments: | ||
method: method which was made before error. | ||
response: HTTP response from BotX API. | ||
Raises: | ||
ImageNotValidError: raised always. | ||
""" | ||
raise ImageNotValidError( | ||
url=method.url, | ||
method=method.http_method, | ||
response_content=response.json_body, | ||
status_content=response.status_code, | ||
) |
49 changes: 49 additions & 0 deletions
49
botx/clients/methods/errors/stickers/sticker_pack_not_found.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
"""Definition for "sticker pack was not found" error.""" | ||
from typing import NoReturn | ||
from uuid import UUID | ||
|
||
from pydantic import BaseModel | ||
|
||
from botx.clients.methods.base import APIErrorResponse, BotXMethod | ||
from botx.clients.types.http import HTTPResponse | ||
from botx.exceptions import BotXAPIError | ||
|
||
|
||
class StickerPackNotFoundError(BotXAPIError): | ||
"""Error for raising when sticker pack was not found.""" | ||
|
||
message_template = "sticker pack {pack_id} not found" | ||
|
||
#: sticker pack ID. | ||
pack_id: UUID | ||
|
||
|
||
class StickerPackNotFoundData(BaseModel): | ||
"""Data for error when sticker pack was not found.""" | ||
|
||
#: sticker pack ID. | ||
pack_id: UUID | ||
|
||
|
||
def handle_error(method: BotXMethod, response: HTTPResponse) -> NoReturn: | ||
"""Handle "sticker pack getting error" error response. | ||
Arguments: | ||
method: method which was made before error. | ||
response: HTTP response from BotX API. | ||
Raises: | ||
StickerPackNotFoundError: raised always. | ||
""" | ||
parsed_response = APIErrorResponse[StickerPackNotFoundData].parse_obj( | ||
response.json_body, | ||
) | ||
|
||
error_data = parsed_response.error_data | ||
raise StickerPackNotFoundError( | ||
url=method.url, | ||
method=method.http_method, | ||
response_content=response.json_body, | ||
status_content=response.status_code, | ||
pack_id=error_data.pack_id, | ||
) |
Oops, something went wrong.
5c28118
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Published on https://pybotx.netlify.app as production
🚀 Deployed on https://617fa1017d46184f24db2478--pybotx.netlify.app