Skip to content

Commit

Permalink
Black code format + fix syntax errors
Browse files Browse the repository at this point in the history
Signed-off-by: eyMarv <[email protected]>
  • Loading branch information
eyMarv committed Jun 2, 2024
1 parent df60ab2 commit e71d85c
Show file tree
Hide file tree
Showing 49 changed files with 319 additions and 260 deletions.
2 changes: 1 addition & 1 deletion pyrogram/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
BadRequest,
AuthBytesInvalid,
FloodWait,
FloodPremiumWait
FloodPremiumWait,
)
from pyrogram.handlers.handler import Handler
from pyrogram.methods import Methods
Expand Down
6 changes: 4 additions & 2 deletions pyrogram/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,10 @@ async def story_parser(update, users, chats):

async def pre_checkout_query_parser(update, users, chats):
return (
await pyrogram.types.PreCheckoutQuery._parse(self.client, update, users),
PreCheckoutQueryHandler
await pyrogram.types.PreCheckoutQuery._parse(
self.client, update, users
),
PreCheckoutQueryHandler,
)

async def message_bot_na_reaction_parser(update, users, chats):
Expand Down
2 changes: 1 addition & 1 deletion pyrogram/enums/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"ChatMemberStatus",
"ChatMembersFilter",
"ChatType",
'ClientPlatform',
"ClientPlatform",
"ListenerTypes",
"MessageEntityType",
"MessageMediaType",
Expand Down
10 changes: 6 additions & 4 deletions pyrogram/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,7 @@ async def video_chat_members_invited_filter(_, __, m: Message):

# endregion


# region successful_payment_filter
async def successful_payment_filter(_, __, m: Message):
return bool(m.successful_payment)
Expand All @@ -752,6 +753,7 @@ async def successful_payment_filter(_, __, m: Message):

# endregion


# region service_filter
async def service_filter(_, __, m: Message):
return bool(m.service)
Expand Down Expand Up @@ -1139,11 +1141,11 @@ class topic(Filter, set):
"""

def __init__(self, topics: Union[int, List[int]] = None):
topics = [] if topics is None else topics if isinstance(topics, list) else [topics]

super().__init__(
t for t in topics
topics = (
[] if topics is None else topics if isinstance(topics, list) else [topics]
)

super().__init__(t for t in topics)

async def __call__(self, _, message: Message):
return message.topic and message.topic.id in self
14 changes: 9 additions & 5 deletions pyrogram/handlers/message_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ async def check(self, client: "pyrogram.Client", message: Message):
:return: Whether the message has a matching listener or handler and its filters does match with the Message.
"""
listener_does_match = (
await self.check_if_has_matching_listener(client, message)
)[0] if message.chat is not None and message.from_user is not None else False
(await self.check_if_has_matching_listener(client, message))[0]
if message.chat is not None and message.from_user is not None
else False
)

if callable(self.filters):
if iscoroutinefunction(self.filters.__call__):
Expand All @@ -135,9 +137,11 @@ async def resolve_future_or_callback(
:param args: Arguments to call the callback with.
:return: None
"""
listener_does_match, listener = await self.check_if_has_matching_listener(
client, message
) if message.chat is not None and message.from_user is not None else False, None
listener_does_match, listener = (
await self.check_if_has_matching_listener(client, message)
if message.chat is not None and message.from_user is not None
else False
), None

if listener and listener_does_match:
client.remove_listener(listener)
Expand Down
2 changes: 1 addition & 1 deletion pyrogram/methods/bots/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ class Bots(
GetChatMenuButton,
AnswerWebAppQuery,
AnswerPreCheckoutQuery,
GetCollectibleItemInfo
GetCollectibleItemInfo,
):
pass
4 changes: 2 additions & 2 deletions pyrogram/methods/bots/answer_pre_checkout_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async def answer_pre_checkout_query(
self: "pyrogram.Client",
pre_checkout_query_id: str,
success: bool = None,
error: str = None
error: str = None,
):
"""Send answers to pre-checkout queries.
Expand Down Expand Up @@ -60,6 +60,6 @@ async def answer_pre_checkout_query(
raw.functions.messages.SetBotPrecheckoutResults(
query_id=int(pre_checkout_query_id),
success=success or None,
error=error or None
error=error or None,
)
)
8 changes: 2 additions & 6 deletions pyrogram/methods/bots/get_collectible_item_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@

class GetCollectibleItemInfo:
async def get_collectible_item_info(
self: "pyrogram.Client",
username: str = None,
phone_number: str = None
self: "pyrogram.Client", username: str = None, phone_number: str = None
) -> "types.CollectibleInfo":
"""Returns information about a given collectible item that was purchased at https://fragment.com
.. include:: /_includes/usable-by/users.rst
Expand Down Expand Up @@ -55,9 +53,7 @@ async def get_collectible_item_info(
)

r = await self.invoke(
raw.functions.fragment.GetCollectibleInfo(
collectible=input_collectible
)
raw.functions.fragment.GetCollectibleInfo(collectible=input_collectible)
)

return types.CollectibleItemInfo._parse(r)
6 changes: 2 additions & 4 deletions pyrogram/methods/bots/request_callback_answer.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,15 @@ async def request_callback_answer(
)

if password:
r = await self.invoke(
raw.functions.account.GetPassword()
)
r = await self.invoke(raw.functions.account.GetPassword())
password = utils.compute_password_check(r, password)

return await self.invoke(
raw.functions.messages.GetBotCallbackAnswer(
peer=await self.resolve_peer(chat_id),
msg_id=message_id,
data=data,
password=password
password=password,
),
retries=0,
timeout=timeout,
Expand Down
15 changes: 10 additions & 5 deletions pyrogram/methods/chats/get_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,15 @@ async def get_chat(

if force_full:
if isinstance(peer, raw.types.InputPeerChannel):
r = await self.invoke(raw.functions.channels.GetFullChannel(channel=peer))
r = await self.invoke(
raw.functions.channels.GetFullChannel(channel=peer)
)
elif isinstance(peer, (raw.types.InputPeerUser, raw.types.InputPeerSelf)):
r = await self.invoke(raw.functions.users.GetFullUser(id=peer))
else:
r = await self.invoke(raw.functions.messages.GetFullChat(chat_id=peer.chat_id))
r = await self.invoke(
raw.functions.messages.GetFullChat(chat_id=peer.chat_id)
)

return await types.Chat._parse_full(self, r)
else:
Expand All @@ -94,9 +98,10 @@ async def get_chat(
elif isinstance(peer, (raw.types.InputPeerUser, raw.types.InputPeerSelf)):
r = await self.invoke(raw.functions.users.GetUsers(id=[peer]))
else:
r = await self.invoke(raw.functions.messages.GetChats(id=[peer.chat_id]))
r = await self.invoke(
raw.functions.messages.GetChats(id=[peer.chat_id])
)

return types.Chat._parse_chat(
self,
r.chats[0] if isinstance(r, raw.types.messages.Chats) else r[0]
self, r.chats[0] if isinstance(r, raw.types.messages.Chats) else r[0]
)
2 changes: 1 addition & 1 deletion pyrogram/methods/decorators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ class Decorators(
OnStory,
OnMessageReactionUpdated,
OnMessageReactionCountUpdated,
OnPreCheckoutQuery
OnPreCheckoutQuery,
):
pass
6 changes: 4 additions & 2 deletions pyrogram/methods/decorators/on_pre_checkout_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,17 @@ def on_pre_checkout_query(

def decorator(func: Callable) -> Callable:
if isinstance(self, pyrogram.Client):
self.add_handler(pyrogram.handlers.PreCheckoutQueryHandler(func, filters), group)
self.add_handler(
pyrogram.handlers.PreCheckoutQueryHandler(func, filters), group
)
elif isinstance(self, Filter) or self is None:
if not hasattr(func, "handlers"):
func.handlers = []

func.handlers.append(
(
pyrogram.handlers.PreCheckoutQueryHandler(func, self),
group if filters is None else filters
group if filters is None else filters,
)
)

Expand Down
3 changes: 1 addition & 2 deletions pyrogram/methods/messages/copy_media_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ async def copy_media_group(
file_id=file_id,
has_spoiler=(
has_spoilers[i]
if isinstance(has_spoilers, list)
and i < len(has_spoilers)
if isinstance(has_spoilers, list) and i < len(has_spoilers)
else (
has_spoilers
if isinstance(has_spoilers, bool)
Expand Down
2 changes: 1 addition & 1 deletion pyrogram/methods/messages/copy_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,5 @@ async def copy_message(
schedule_date=schedule_date,
protect_content=protect_content,
invert_media=invert_media,
reply_markup=reply_markup
reply_markup=reply_markup,
)
4 changes: 2 additions & 2 deletions pyrogram/methods/messages/edit_message_caption.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async def edit_message_caption(
parse_mode: Optional["enums.ParseMode"] = None,
caption_entities: List["types.MessageEntity"] = None,
invert_media: bool = False,
reply_markup: "types.InlineKeyboardMarkup" = None
reply_markup: "types.InlineKeyboardMarkup" = None,
) -> "types.Message":
"""Edit the caption of media messages.
Expand Down Expand Up @@ -78,5 +78,5 @@ async def edit_message_caption(
parse_mode=parse_mode,
entities=caption_entities,
invert_media=invert_media,
reply_markup=reply_markup
reply_markup=reply_markup,
)
4 changes: 2 additions & 2 deletions pyrogram/methods/messages/edit_message_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async def edit_message_media(
media: "types.InputMedia",
reply_markup: "types.InlineKeyboardMarkup" = None,
file_name: str = None,
invert_media: bool = False
invert_media: bool = False,
) -> "types.Message":
"""Edit animation, audio, document, photo or video messages.
Expand Down Expand Up @@ -278,7 +278,7 @@ async def edit_message_media(
reply_markup=await reply_markup.write(self) if reply_markup else None,
message=message,
entities=entities,
invert_media=invert_media
invert_media=invert_media,
)
)

Expand Down
2 changes: 1 addition & 1 deletion pyrogram/methods/messages/edit_message_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async def edit_message_text(
entities: List["types.MessageEntity"] = None,
disable_web_page_preview: bool = None,
invert_media: bool = None,
reply_markup: "types.InlineKeyboardMarkup" = None
reply_markup: "types.InlineKeyboardMarkup" = None,
) -> "types.Message":
"""Edit the text of messages.
Expand Down
12 changes: 5 additions & 7 deletions pyrogram/methods/messages/get_available_effects.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

class GetAvailableEffects:
async def get_available_effects(
self: "pyrogram.Client"
self: "pyrogram.Client",
) -> List["types.AvailableEffect"]:
"""Get all available effects.
Expand All @@ -44,17 +44,15 @@ async def get_available_effects(
# Get all available effects
await app.get_available_effects()
"""
r = await self.invoke(
raw.functions.messages.GetAvailableEffects(
hash=0
)
)
r = await self.invoke(raw.functions.messages.GetAvailableEffects(hash=0))

documents = {d.id: d for d in r.documents}

return types.List(
[
await types.AvailableEffect._parse(self, effect, documents.get(effect.effect_sticker_id, None))
await types.AvailableEffect._parse(
self, effect, documents.get(effect.effect_sticker_id, None)
)
for effect in r.effects
]
)
8 changes: 6 additions & 2 deletions pyrogram/methods/messages/send_animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,12 @@ async def progress(current, total):
noforwards=protect_content,
effect=message_effect_id,
invert_media=invert_media,
reply_markup=await reply_markup.write(self) if reply_markup else None,
**await utils.parse_text_entities(self, caption, parse_mode, caption_entities)
reply_markup=(
await reply_markup.write(self) if reply_markup else None
),
**await utils.parse_text_entities(
self, caption, parse_mode, caption_entities
),
)
if business_connection_id is not None:
r = await self.invoke(
Expand Down
4 changes: 2 additions & 2 deletions pyrogram/methods/messages/send_media_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async def send_media_group(
schedule_date: datetime = None,
protect_content: bool = None,
message_effect_id: int = None,
invert_media: bool = None
invert_media: bool = None,
) -> List["types.Message"]:
"""Send a group of photos or videos as an album.
Expand Down Expand Up @@ -515,7 +515,7 @@ async def send_media_group(
schedule_date=utils.datetime_to_timestamp(schedule_date),
noforwards=protect_content,
effect=message_effect_id,
invert_media=invert_media
invert_media=invert_media,
)

if business_connection_id is not None:
Expand Down
19 changes: 14 additions & 5 deletions pyrogram/methods/messages/send_photo.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,18 +217,23 @@ async def send_photo(
media = raw.types.InputMediaPhotoExternal(
url=photo,
ttl_seconds=(1 << 31) - 1 if view_once else ttl_seconds,
spoiler=has_spoiler
spoiler=has_spoiler,
)
else:
media = utils.get_input_media_from_file_id(photo, FileType.PHOTO, ttl_seconds=(1 << 31) - 1 if view_once else ttl_seconds, has_spoiler=has_spoiler)
media = utils.get_input_media_from_file_id(
photo,
FileType.PHOTO,
ttl_seconds=(1 << 31) - 1 if view_once else ttl_seconds,
has_spoiler=has_spoiler,
)
else:
file = await self.save_file(
photo, progress=progress, progress_args=progress_args
)
media = raw.types.InputMediaUploadedPhoto(
file=file,
ttl_seconds=(1 << 31) - 1 if view_once else ttl_seconds,
spoiler=has_spoiler
spoiler=has_spoiler,
)

while True:
Expand All @@ -243,8 +248,12 @@ async def send_photo(
noforwards=protect_content,
effect=message_effect_id,
invert_media=invert_media,
reply_markup=await reply_markup.write(self) if reply_markup else None,
**await utils.parse_text_entities(self, caption, parse_mode, caption_entities)
reply_markup=(
await reply_markup.write(self) if reply_markup else None
),
**await utils.parse_text_entities(
self, caption, parse_mode, caption_entities
),
)
if business_connection_id is not None:
r = await self.invoke(
Expand Down
Loading

0 comments on commit e71d85c

Please sign in to comment.