mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-01-25 00:34:19 +03:00
Add comment_to parameter to more easily post comments
This commit is contained in:
parent
6f7640af18
commit
ea57db7aad
|
@ -577,6 +577,19 @@ class MessageMethods:
|
||||||
|
|
||||||
# region Message sending/editing/deleting
|
# region Message sending/editing/deleting
|
||||||
|
|
||||||
|
async def _get_comment_data(
|
||||||
|
self: 'TelegramClient',
|
||||||
|
entity: 'hints.EntityLike',
|
||||||
|
message: 'typing.Union[int, types.Message]'
|
||||||
|
):
|
||||||
|
r = await self(functions.messages.GetDiscussionMessageRequest(
|
||||||
|
peer=entity,
|
||||||
|
msg_id=utils.get_message_id(message)
|
||||||
|
))
|
||||||
|
m = r.messages[0]
|
||||||
|
chat = next(c for c in r.chats if c.id == m.peer_id.channel_id)
|
||||||
|
return utils.get_input_peer(chat), m.id
|
||||||
|
|
||||||
async def send_message(
|
async def send_message(
|
||||||
self: 'TelegramClient',
|
self: 'TelegramClient',
|
||||||
entity: 'hints.EntityLike',
|
entity: 'hints.EntityLike',
|
||||||
|
@ -591,7 +604,8 @@ class MessageMethods:
|
||||||
clear_draft: bool = False,
|
clear_draft: bool = False,
|
||||||
buttons: 'hints.MarkupLike' = None,
|
buttons: 'hints.MarkupLike' = None,
|
||||||
silent: bool = None,
|
silent: bool = None,
|
||||||
schedule: 'hints.DateLike' = None
|
schedule: 'hints.DateLike' = None,
|
||||||
|
comment_to: 'typing.Union[int, types.Message]' = None
|
||||||
) -> 'types.Message':
|
) -> 'types.Message':
|
||||||
"""
|
"""
|
||||||
Sends a message to the specified user, chat or channel.
|
Sends a message to the specified user, chat or channel.
|
||||||
|
@ -672,6 +686,14 @@ class MessageMethods:
|
||||||
it will be scheduled to be automatically sent at a later
|
it will be scheduled to be automatically sent at a later
|
||||||
time.
|
time.
|
||||||
|
|
||||||
|
comment_to (`int` | `Message <telethon.tl.custom.message.Message>`, optional):
|
||||||
|
Similar to ``reply_to``, but replies in the linked group of a
|
||||||
|
broadcast channel instead (effectively leaving a "comment to"
|
||||||
|
the specified message).
|
||||||
|
|
||||||
|
This parameter takes precedence over ``reply_to``. If there is
|
||||||
|
no linked chat, `telethon.errors.sgIdInvalidError` is raised.
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
The sent `custom.Message <telethon.tl.custom.message.Message>`.
|
The sent `custom.Message <telethon.tl.custom.message.Message>`.
|
||||||
|
|
||||||
|
@ -740,6 +762,9 @@ class MessageMethods:
|
||||||
)
|
)
|
||||||
|
|
||||||
entity = await self.get_input_entity(entity)
|
entity = await self.get_input_entity(entity)
|
||||||
|
if comment_to is not None:
|
||||||
|
entity, reply_to = await self._get_comment_data(entity, comment_to)
|
||||||
|
|
||||||
if isinstance(message, types.Message):
|
if isinstance(message, types.Message):
|
||||||
if buttons is None:
|
if buttons is None:
|
||||||
markup = message.reply_markup
|
markup = message.reply_markup
|
||||||
|
|
|
@ -114,6 +114,7 @@ class UploadMethods:
|
||||||
silent: bool = None,
|
silent: 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,
|
||||||
**kwargs) -> 'types.Message':
|
**kwargs) -> 'types.Message':
|
||||||
"""
|
"""
|
||||||
Sends message with the given file to the specified entity.
|
Sends message with the given file to the specified entity.
|
||||||
|
@ -260,6 +261,14 @@ class UploadMethods:
|
||||||
it will be scheduled to be automatically sent at a later
|
it will be scheduled to be automatically sent at a later
|
||||||
time.
|
time.
|
||||||
|
|
||||||
|
comment_to (`int` | `Message <telethon.tl.custom.message.Message>`, optional):
|
||||||
|
Similar to ``reply_to``, but replies in the linked group of a
|
||||||
|
broadcast channel instead (effectively leaving a "comment to"
|
||||||
|
the specified message).
|
||||||
|
|
||||||
|
This parameter takes precedence over ``reply_to``. If there is
|
||||||
|
no linked chat, `telethon.errors.sgIdInvalidError` is raised.
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
The `Message <telethon.tl.custom.message.Message>` (or messages)
|
The `Message <telethon.tl.custom.message.Message>` (or messages)
|
||||||
containing the sent file, or messages if a list of them was passed.
|
containing the sent file, or messages if a list of them was passed.
|
||||||
|
@ -317,6 +326,12 @@ class UploadMethods:
|
||||||
if not caption:
|
if not caption:
|
||||||
caption = ''
|
caption = ''
|
||||||
|
|
||||||
|
entity = await self.get_input_entity(entity)
|
||||||
|
if comment_to is not None:
|
||||||
|
entity, reply_to = await self._get_comment_data(entity, comment_to)
|
||||||
|
else:
|
||||||
|
reply_to = utils.get_message_id(reply_to
|
||||||
|
|
||||||
# First check if the user passed an iterable, in which case
|
# First check if the user passed an iterable, in which case
|
||||||
# we may want to send grouped.
|
# we may want to send grouped.
|
||||||
if utils.is_list_like(file):
|
if utils.is_list_like(file):
|
||||||
|
@ -351,9 +366,6 @@ class UploadMethods:
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
entity = await self.get_input_entity(entity)
|
|
||||||
reply_to = utils.get_message_id(reply_to)
|
|
||||||
|
|
||||||
if formatting_entities is not None:
|
if formatting_entities is not None:
|
||||||
msg_entities = formatting_entities
|
msg_entities = formatting_entities
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -235,6 +235,7 @@ class _Message(ChatGetter, SenderGetter):
|
||||||
self._via_bot = None
|
self._via_bot = None
|
||||||
self._via_input_bot = None
|
self._via_input_bot = None
|
||||||
self._action_entities = None
|
self._action_entities = None
|
||||||
|
self._linked_chat = None
|
||||||
|
|
||||||
sender_id = None
|
sender_id = None
|
||||||
if from_id is not None:
|
if from_id is not None:
|
||||||
|
@ -295,6 +296,11 @@ class _Message(ChatGetter, SenderGetter):
|
||||||
self._action_entities = [entities.get(utils.get_peer_id(
|
self._action_entities = [entities.get(utils.get_peer_id(
|
||||||
types.PeerChat(self.action.chat_id)))]
|
types.PeerChat(self.action.chat_id)))]
|
||||||
|
|
||||||
|
if self.replies and self.replies.channel_id:
|
||||||
|
self._linked_chat = entities.get(utils.get_peer_id(
|
||||||
|
types.PeerChannel(self.replies.channel_id)))
|
||||||
|
|
||||||
|
|
||||||
# endregion Initialization
|
# endregion Initialization
|
||||||
|
|
||||||
# region Public Properties
|
# region Public Properties
|
||||||
|
|
Loading…
Reference in New Issue
Block a user