mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-25 19:03:46 +03:00
Add a friendly method to react to messages (#3681)
This commit is contained in:
parent
af0ea638b4
commit
c45b919109
|
@ -747,3 +747,44 @@ async def _pin(self, entity, message, *, unpin, notify=False, pm_oneside=False):
|
|||
|
||||
# Pinning a message that doesn't exist would RPC-error earlier
|
||||
return self._get_response_message(request, result, entity)
|
||||
|
||||
async def send_reaction(
|
||||
self: 'TelegramClient',
|
||||
entity: 'hints.EntityLike',
|
||||
message: 'hints.MessageIDLike',
|
||||
reaction: typing.Optional[str] = None,
|
||||
big: bool = False
|
||||
):
|
||||
message = utils.get_message_id(message) or 0
|
||||
if not reaction:
|
||||
get_default_request = _tl.fn.help.GetAppConfig()
|
||||
app_config = await self(get_default_request)
|
||||
reaction = (
|
||||
next(
|
||||
(
|
||||
y for y in app_config.value
|
||||
if "reactions_default" in y.key
|
||||
)
|
||||
)
|
||||
).value.value
|
||||
request = _tl.fn.messages.SendReaction(
|
||||
big=big,
|
||||
peer=entity,
|
||||
msg_id=message,
|
||||
reaction=reaction
|
||||
)
|
||||
result = await self(request)
|
||||
for update in result.updates:
|
||||
if isinstance(update, _tl.UpdateMessageReactions):
|
||||
return update.reactions
|
||||
if isinstance(update, _tl.UpdateEditMessage):
|
||||
return update.message.reactions
|
||||
|
||||
async def set_quick_reaction(
|
||||
self: 'TelegramClient',
|
||||
reaction: str
|
||||
):
|
||||
request = _tl.fn.messages.SetDefaultReaction(
|
||||
reaction=reaction
|
||||
)
|
||||
return await self(request)
|
||||
|
|
|
@ -1251,6 +1251,19 @@ class Message(ChatGetter, SenderGetter):
|
|||
return await self._client.unpin_message(
|
||||
await self.get_input_chat(), self.id)
|
||||
|
||||
async def react(self, reaction=None):
|
||||
"""
|
||||
Reacts on the given message. Shorthand for
|
||||
`telethon.client.messages.MessageMethods.send_reaction`
|
||||
with both ``entity`` and ``message`` already set.
|
||||
"""
|
||||
if self._client:
|
||||
return await self._client.send_reaction(
|
||||
await self.get_input_chat(),
|
||||
self.id,
|
||||
reaction
|
||||
)
|
||||
|
||||
# endregion Public Methods
|
||||
|
||||
# region Private Methods
|
||||
|
|
Loading…
Reference in New Issue
Block a user