Expose more raw API params in friendly methods (#3104)

This commit is contained in:
Devesh Pal 2021-08-05 14:24:07 +05:30 committed by GitHub
parent ad55b945c1
commit e5599c178b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 12 deletions

View File

@ -608,6 +608,7 @@ class MessageMethods:
clear_draft: bool = False, clear_draft: bool = False,
buttons: 'hints.MarkupLike' = None, buttons: 'hints.MarkupLike' = None,
silent: bool = None, silent: bool = None,
background: bool = None,
supports_streaming: bool = False, supports_streaming: bool = False,
schedule: 'hints.DateLike' = None, schedule: 'hints.DateLike' = None,
comment_to: 'typing.Union[int, types.Message]' = None comment_to: 'typing.Union[int, types.Message]' = None
@ -701,6 +702,9 @@ class MessageMethods:
channel or not. Defaults to `False`, which means it will channel or not. Defaults to `False`, which means it will
notify them. Set it to `True` to alter this behaviour. notify them. Set it to `True` to alter this behaviour.
background (`bool`, optional):
Whether the message should be send in background.
supports_streaming (`bool`, optional): supports_streaming (`bool`, optional):
Whether the sent video supports streaming or not. Note that Whether the sent video supports streaming or not. Note that
Telegram only recognizes as streamable some formats like MP4, Telegram only recognizes as streamable some formats like MP4,
@ -788,7 +792,7 @@ class MessageMethods:
buttons=buttons, clear_draft=clear_draft, silent=silent, buttons=buttons, clear_draft=clear_draft, silent=silent,
schedule=schedule, supports_streaming=supports_streaming, schedule=schedule, supports_streaming=supports_streaming,
formatting_entities=formatting_entities, formatting_entities=formatting_entities,
comment_to=comment_to comment_to=comment_to, background=background
) )
entity = await self.get_input_entity(entity) entity = await self.get_input_entity(entity)
@ -811,6 +815,7 @@ class MessageMethods:
message.media, message.media,
caption=message.message, caption=message.message,
silent=silent, silent=silent,
background=background,
reply_to=reply_to, reply_to=reply_to,
buttons=markup, buttons=markup,
formatting_entities=message.entities, formatting_entities=message.entities,
@ -821,6 +826,7 @@ class MessageMethods:
peer=entity, peer=entity,
message=message.message or '', message=message.message or '',
silent=silent, silent=silent,
background=background,
reply_to_msg_id=utils.get_message_id(reply_to), reply_to_msg_id=utils.get_message_id(reply_to),
reply_markup=markup, reply_markup=markup,
entities=message.entities, entities=message.entities,
@ -846,6 +852,7 @@ class MessageMethods:
reply_to_msg_id=utils.get_message_id(reply_to), reply_to_msg_id=utils.get_message_id(reply_to),
clear_draft=clear_draft, clear_draft=clear_draft,
silent=silent, silent=silent,
background=background,
reply_markup=self.build_reply_markup(buttons), reply_markup=self.build_reply_markup(buttons),
schedule_date=schedule schedule_date=schedule
) )
@ -874,6 +881,8 @@ class MessageMethods:
messages: 'typing.Union[hints.MessageIDLike, typing.Sequence[hints.MessageIDLike]]', messages: 'typing.Union[hints.MessageIDLike, typing.Sequence[hints.MessageIDLike]]',
from_peer: 'hints.EntityLike' = None, from_peer: 'hints.EntityLike' = None,
*, *,
background: bool = None,
with_my_score: bool = None,
silent: bool = None, silent: bool = None,
as_album: bool = None, as_album: bool = None,
schedule: 'hints.DateLike' = None schedule: 'hints.DateLike' = None
@ -906,6 +915,12 @@ class MessageMethods:
the person has the chat muted). Set it to `True` to alter the person has the chat muted). Set it to `True` to alter
this behaviour. this behaviour.
background (`bool`, optional):
Whether the message should be forwarded in background.
with_my_score (`bool`, optional):
Whether forwarded should contain your game score.
as_album (`bool`, optional): as_album (`bool`, optional):
This flag no longer has any effect. This flag no longer has any effect.
@ -980,6 +995,8 @@ class MessageMethods:
id=chunk, id=chunk,
to_peer=entity, to_peer=entity,
silent=silent, silent=silent,
background=background,
with_my_score=with_my_score,
schedule_date=schedule schedule_date=schedule
) )
result = await self(req) result = await self(req)

View File

@ -112,6 +112,7 @@ class UploadMethods:
video_note: bool = False, video_note: bool = False,
buttons: 'hints.MarkupLike' = None, buttons: 'hints.MarkupLike' = None,
silent: bool = None, silent: bool = None,
background: bool = None,
supports_streaming: bool = False, supports_streaming: bool = False,
schedule: 'hints.DateLike' = None, schedule: 'hints.DateLike' = None,
comment_to: 'typing.Union[int, types.Message]' = None, comment_to: 'typing.Union[int, types.Message]' = None,
@ -249,6 +250,9 @@ class UploadMethods:
the person has the chat muted). Set it to `True` to alter the person has the chat muted). Set it to `True` to alter
this behaviour. this behaviour.
background (`bool`, optional):
Whether the message should be send in background.
supports_streaming (`bool`, optional): supports_streaming (`bool`, optional):
Whether the sent video supports streaming or not. Note that Whether the sent video supports streaming or not. Note that
Telegram only recognizes as streamable some formats like MP4, Telegram only recognizes as streamable some formats like MP4,
@ -347,7 +351,7 @@ class UploadMethods:
progress_callback=progress_callback, reply_to=reply_to, progress_callback=progress_callback, reply_to=reply_to,
parse_mode=parse_mode, silent=silent, schedule=schedule, parse_mode=parse_mode, silent=silent, schedule=schedule,
supports_streaming=supports_streaming, clear_draft=clear_draft, supports_streaming=supports_streaming, clear_draft=clear_draft,
force_document=force_document force_document=force_document, background=background,
) )
file = file[10:] file = file[10:]
captions = captions[10:] captions = captions[10:]
@ -360,7 +364,7 @@ class UploadMethods:
attributes=attributes, thumb=thumb, voice_note=voice_note, attributes=attributes, thumb=thumb, voice_note=voice_note,
video_note=video_note, buttons=buttons, silent=silent, video_note=video_note, buttons=buttons, silent=silent,
supports_streaming=supports_streaming, schedule=schedule, supports_streaming=supports_streaming, schedule=schedule,
clear_draft=clear_draft, clear_draft=clear_draft, background=background,
**kwargs **kwargs
)) ))
@ -389,7 +393,8 @@ class UploadMethods:
request = functions.messages.SendMediaRequest( request = functions.messages.SendMediaRequest(
entity, media, reply_to_msg_id=reply_to, message=caption, entity, media, reply_to_msg_id=reply_to, message=caption,
entities=msg_entities, reply_markup=markup, silent=silent, entities=msg_entities, reply_markup=markup, silent=silent,
schedule_date=schedule, clear_draft=clear_draft schedule_date=schedule, clear_draft=clear_draft,
background=background
) )
return self._get_response_message(request, await self(request), entity) return self._get_response_message(request, await self(request), entity)
@ -397,7 +402,7 @@ class UploadMethods:
progress_callback=None, reply_to=None, progress_callback=None, reply_to=None,
parse_mode=(), silent=None, schedule=None, parse_mode=(), silent=None, schedule=None,
supports_streaming=None, clear_draft=None, supports_streaming=None, clear_draft=None,
force_document=False): force_document=False, background=None):
"""Specialized version of .send_file for albums""" """Specialized version of .send_file for albums"""
# We don't care if the user wants to avoid cache, we will use it # We don't care if the user wants to avoid cache, we will use it
# anyway. Why? The cached version will be exactly the same thing # anyway. Why? The cached version will be exactly the same thing
@ -456,7 +461,8 @@ class UploadMethods:
# Now we can construct the multi-media request # Now we can construct the multi-media request
request = functions.messages.SendMultiMediaRequest( request = functions.messages.SendMultiMediaRequest(
entity, reply_to_msg_id=reply_to, multi_media=media, entity, reply_to_msg_id=reply_to, multi_media=media,
silent=silent, schedule_date=schedule, clear_draft=clear_draft silent=silent, schedule_date=schedule, clear_draft=clear_draft,
background=background
) )
result = await self(request) result = await self(request)

View File

@ -245,17 +245,29 @@ class Button:
resize=resize, single_use=single_use, selective=selective) resize=resize, single_use=single_use, selective=selective)
@staticmethod @staticmethod
def clear(): def clear(selective=None):
""" """
Clears all keyboard buttons after sending a message with this markup. Clears all keyboard buttons after sending a message with this markup.
When used, no other button should be present or it will be ignored. When used, no other button should be present or it will be ignored.
``selective`` is as documented in `text`.
""" """
return types.ReplyKeyboardHide() return types.ReplyKeyboardHide(selective=selective)
@staticmethod @staticmethod
def force_reply(): def force_reply(single_use=None, selective=None, placeholder=None):
""" """
Forces a reply to the message with this markup. If used, Forces a reply to the message with this markup. If used,
no other button should be present or it will be ignored. no other button should be present or it will be ignored.
``single_use`` and ``selective`` are as documented in `text`.
Args:
placeholder (str):
text to show the user at typing place of message.
""" """
return types.ReplyKeyboardForceReply() return types.ReplyKeyboardForceReply(
single_use=single_use,
selective=selective,
placeholder=placeholder)

View File

@ -103,7 +103,8 @@ class InlineResult:
return self.result.document return self.result.document
async def click(self, entity=None, reply_to=None, comment_to=None, async def click(self, entity=None, reply_to=None, comment_to=None,
silent=False, clear_draft=False, hide_via=False): silent=False, clear_draft=False, hide_via=False,
background=None):
""" """
Clicks this result and sends the associated `message`. Clicks this result and sends the associated `message`.
@ -132,6 +133,10 @@ class InlineResult:
hide_via (`bool`, optional): hide_via (`bool`, optional):
Whether the "via @bot" should be hidden or not. Whether the "via @bot" should be hidden or not.
Only works with certain bots (like @bing or @gif). Only works with certain bots (like @bing or @gif).
background (`bool`, optional):
Whether the message should be send in background.
""" """
if entity: if entity:
entity = await self._client.get_input_entity(entity) entity = await self._client.get_input_entity(entity)
@ -150,6 +155,7 @@ class InlineResult:
query_id=self._query_id, query_id=self._query_id,
id=self.result.id, id=self.result.id,
silent=silent, silent=silent,
background=background,
clear_draft=clear_draft, clear_draft=clear_draft,
hide_via=hide_via, hide_via=hide_via,
reply_to_msg_id=reply_id reply_to_msg_id=reply_id