Skip to content

Commit

Permalink
black code format
Browse files Browse the repository at this point in the history
Signed-off-by: eyMarv <[email protected]>
  • Loading branch information
eyMarv committed Aug 27, 2024
1 parent eee164e commit cb2b132
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 71 deletions.
7 changes: 3 additions & 4 deletions pyrogram/methods/invite_links/export_chat_invite_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async def export_chat_invite_link(
self: "pyrogram.Client",
chat_id: Union[int, str],
subscription_period: int = None,
subscription_price: int = None
subscription_price: int = None,
) -> "types.ChatInviteLink":
"""Generate a new primary invite link for a chat; any previously generated primary link is revoked.
Expand Down Expand Up @@ -71,9 +71,8 @@ async def export_chat_invite_link(
peer=await self.resolve_peer(chat_id),
legacy_revoke_permanent=True,
subscription_pricing=raw.types.StarsSubscriptionPricing(
period=subscription_period,
amount=subscription_price
)
period=subscription_period, amount=subscription_price
),
)
)

Expand Down
1 change: 1 addition & 0 deletions pyrogram/methods/messages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
from .vote_poll import VotePoll
from .translate_text import TranslateText


class Messages(
DeleteMessages,
EditMessageCaption,
Expand Down
6 changes: 5 additions & 1 deletion pyrogram/methods/messages/edit_message_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ async def edit_message_media(
message, entities = None, None

if caption is not None:
message, entities = (await utils.parse_text_entities(self, caption, parse_mode, caption_entities)).values()
message, entities = (
await utils.parse_text_entities(
self, caption, parse_mode, caption_entities
)
).values()

if isinstance(media, types.InputMediaPhoto):
if isinstance(media.media, io.BytesIO) or os.path.isfile(media.media):
Expand Down
11 changes: 8 additions & 3 deletions pyrogram/methods/messages/send_paid_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ async def send_paid_media(
self: "pyrogram.Client",
chat_id: Union[int, str],
stars_amount: int,
media: List[Union["types.InputMediaAnimation", "types.InputMediaPhoto", "types.InputMediaVideo"]],
media: List[
Union[
"types.InputMediaAnimation",
"types.InputMediaPhoto",
"types.InputMediaVideo",
]
],
business_connection_id: str = None,
caption: str = "",
caption_entities: List["types.MessageEntity"] = None,
Expand Down Expand Up @@ -304,8 +310,7 @@ async def send_paid_media(
if business_connection_id is not None:
r = await self.invoke(
raw.functions.InvokeWithBusinessConnection(
connection_id=business_connection_id,
query=rpc
connection_id=business_connection_id, query=rpc
)
)
else:
Expand Down
27 changes: 10 additions & 17 deletions pyrogram/methods/messages/translate_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async def translate_message_text(
message_ids: Optional[Union[int, List[int]]] = None,
text: Optional[str] = None,
parse_mode: Optional["enums.ParseMode"] = None,
entities: Optional[List["types.MessageEntity"]] = None
entities: Optional[List["types.MessageEntity"]] = None,
) -> Union["types.TranslatedText", List["types.TranslatedText"]]:
"""Translates a text or message(s) to the given language. If the current user is a Telegram Premium user, then text formatting is preserved.
Expand Down Expand Up @@ -62,23 +62,17 @@ async def translate_message_text(
"""
if text is not None:
message, entities = (
await utils.parse_text_entities(
self,
text,
parse_mode,
entities
)
await utils.parse_text_entities(self, text, parse_mode, entities)
).values()

r = await self.invoke(
raw.functions.messages.TranslateText(
to_lang=to_language_code,
text=[
raw.types.TextWithEntities(
text=message,
entities=entities or []
text=message, entities=entities or []
)
]
],
)
)

Expand All @@ -89,17 +83,16 @@ async def translate_message_text(
raw.functions.messages.TranslateText(
to_lang=to_language_code,
peer=await self.resolve_peer(chat_id),
id=ids
id=ids,
)
)
else:
raise ValueError("Either 'text' or both 'chat_id' and 'message_ids' must be provided.")
raise ValueError(
"Either 'text' or both 'chat_id' and 'message_ids' must be provided."
)

return (
types.TranslatedText._parse(self, r.result[0])
if len(r.result) == 1
else [
types.TranslatedText._parse(self, i)
for i in r.result
]
)
else [types.TranslatedText._parse(self, i) for i in r.result]
)
15 changes: 8 additions & 7 deletions pyrogram/methods/stickers/add_sticker_to_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,11 @@ async def add_sticker_to_set(
user_id or "me",
sticker,
force_document=True,
disable_notification=True
disable_notification=True,
)
uploaded_media = utils.get_input_media_from_file_id(
document.document.file_id, FileType.DOCUMENT
)
uploaded_media = utils.get_input_media_from_file_id(document.document.file_id, FileType.DOCUMENT)
media = uploaded_media.id
_ = await document.delete()
else:
Expand All @@ -95,12 +97,11 @@ async def add_sticker_to_set(
if self.me.is_bot and user_id is None:
raise ValueError("user_id is required for bots")
document = await self.send_document(
user_id or "me",
sticker,
force_document=True,
disable_notification=True
user_id or "me", sticker, force_document=True, disable_notification=True
)
uploaded_media = utils.get_input_media_from_file_id(
document.document.file_id, FileType.DOCUMENT
)
uploaded_media = utils.get_input_media_from_file_id(document.document.file_id, FileType.DOCUMENT)
media = uploaded_media.id
_ = await document.delete()

Expand Down
15 changes: 8 additions & 7 deletions pyrogram/methods/stickers/create_sticker_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,11 @@ async def create_sticker_set(
user_id or "me",
sticker,
force_document=True,
disable_notification=True
disable_notification=True,
)
uploaded_media = utils.get_input_media_from_file_id(
document.document.file_id, FileType.DOCUMENT
)
uploaded_media = utils.get_input_media_from_file_id(document.document.file_id, FileType.DOCUMENT)
media = uploaded_media.id
_ = await document.delete()
else:
Expand All @@ -113,12 +115,11 @@ async def create_sticker_set(
)
else:
document = await self.send_document(
user_id or "me",
sticker,
force_document=True,
disable_notification=True
user_id or "me", sticker, force_document=True, disable_notification=True
)
uploaded_media = utils.get_input_media_from_file_id(
document.document.file_id, FileType.DOCUMENT
)
uploaded_media = utils.get_input_media_from_file_id(document.document.file_id, FileType.DOCUMENT)
media = uploaded_media.id
_ = await document.delete()

Expand Down
12 changes: 7 additions & 5 deletions pyrogram/types/bots_and_keyboards/bot_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ class BotInfo(Object):
Privacy policy URL of the bot.
"""

def __init__(self, name: str, about: str, description: str, privacy_policy_url: str = None):
def __init__(
self, name: str, about: str, description: str, privacy_policy_url: str = None
):
super().__init__()

self.name = name
Expand All @@ -50,8 +52,8 @@ def __init__(self, name: str, about: str, description: str, privacy_policy_url:
@staticmethod
def _parse(bot_info: "raw.types.bots.BotInfo") -> "BotInfo":
return BotInfo(
name=getattr(bot_info,"name", None),
about=getattr(bot_info,"about", None),
description=getattr(bot_info,"description", None),
privacy_policy_url=getattr(bot_info,"privacy_policy_url", None)
name=getattr(bot_info, "name", None),
about=getattr(bot_info, "about", None),
description=getattr(bot_info, "description", None),
privacy_policy_url=getattr(bot_info, "privacy_policy_url", None),
)
6 changes: 4 additions & 2 deletions pyrogram/types/messages_and_media/giveaway.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __init__(
quantity: int,
months: int,
expire_date: datetime,
new_subscribers : bool,
new_subscribers: bool,
additional_price: str = None,
allowed_countries: List[str] = None,
private_channel_ids: List[int] = None,
Expand Down Expand Up @@ -107,7 +107,9 @@ async def _parse(client, message: "raw.types.Message") -> "Giveaway":
expire_date=utils.timestamp_to_datetime(giveaway.until_date),
new_subscribers=giveaway.only_new_subscribers,
additional_price=giveaway.prize_description,
allowed_countries=giveaway.countries_iso2 if len(giveaway.countries_iso2) > 0 else None,
allowed_countries=(
giveaway.countries_iso2 if len(giveaway.countries_iso2) > 0 else None
),
private_channel_ids=private_ids if len(private_ids) > 0 else None,
client=client,
)
13 changes: 4 additions & 9 deletions pyrogram/types/messages_and_media/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ def __init__(
] = None,
reactions: List["types.Reaction"] = None,
chat_join_type: "enums.ChatJoinType" = None,
raw: "raw.types.Message" = None
raw: "raw.types.Message" = None,
):
super().__init__(client)

Expand Down Expand Up @@ -1012,7 +1012,7 @@ async def _parse(
join_request_approved=join_request_approved,
raw=message,
chat_join_type=chat_join_type,
client=client
client=client,
# TODO: supergroup_chat_created
)
if parsed_message.chat.type is not enums.ChatType.CHANNEL:
Expand Down Expand Up @@ -5495,10 +5495,7 @@ async def pay(self) -> bool:
chat_id=self.chat.id, message_id=self.id
)

async def translate(
self,
to_language_code: str
) -> "types.TranslatedText":
async def translate(self, to_language_code: str) -> "types.TranslatedText":
"""Bound method *translate* of :obj:`~pyrogram.types.Message`.
Use as a shortcut for:
.. code-block:: python
Expand All @@ -5520,7 +5517,5 @@ async def translate(
RPCError: In case of a Telegram RPC error.
"""
return await self._client.translate_message_text(
chat_id=self.chat.id,
message_ids=self.id,
to_language_code=to_language_code
chat_id=self.chat.id, message_ids=self.id, to_language_code=to_language_code
)
13 changes: 4 additions & 9 deletions pyrogram/types/messages_and_media/translated_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,13 @@ class TranslatedText(Object):
Entities of the text.
"""

def __init__(
self,
*,
text: str,
entities: List["types.MessageEntity"] = None
):
def __init__(self, *, text: str, entities: List["types.MessageEntity"] = None):
self.text = text
self.entities = entities

@staticmethod
def _parse(
client,
translate_result: "raw.types.TextWithEntities"
client, translate_result: "raw.types.TextWithEntities"
) -> "TranslatedText":
entities = [
types.MessageEntity._parse(client, entity, {})
Expand All @@ -58,5 +52,6 @@ def _parse(
entities = types.List(filter(lambda x: x is not None, entities))

return TranslatedText(
text=Str(translate_result.text).init(entities) or None, entities=entities or None
text=Str(translate_result.text).init(entities) or None,
entities=entities or None,
)
6 changes: 2 additions & 4 deletions pyrogram/types/user_and_chats/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1096,9 +1096,7 @@ async def leave(self):
return await self._client.leave_chat(self.id)

async def export_invite_link(
self,
subscription_period: int = None,
subscription_price: int = None
self, subscription_period: int = None, subscription_price: int = None
):
"""Bound method *export_invite_link* of :obj:`~pyrogram.types.Chat`.
Expand Down Expand Up @@ -1131,7 +1129,7 @@ async def export_invite_link(
return await self._client.export_chat_invite_link(
self.id,
subscription_period=subscription_period,
subscription_price=subscription_price
subscription_price=subscription_price,
)

async def get_member(
Expand Down
14 changes: 11 additions & 3 deletions pyrogram/types/user_and_chats/chat_invite_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def __init__(
pending_join_request_count: int = None,
subscription_expired: int = None,
subscription_period: int = None,
subscription_price: int = None
subscription_price: int = None,
):
super().__init__()

Expand Down Expand Up @@ -145,6 +145,14 @@ def _parse(
member_count=invite.usage,
pending_join_request_count=invite.requested,
subscription_expired=invite.subscription_expired,
subscription_period=subscription_pricing.period if subscription_pricing is not None else None,
subscription_price=subscription_pricing.amount if subscription_pricing is not None else None
subscription_period=(
subscription_pricing.period
if subscription_pricing is not None
else None
),
subscription_price=(
subscription_pricing.amount
if subscription_pricing is not None
else None
),
)

0 comments on commit cb2b132

Please sign in to comment.