2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-28 12:57:52 +00:00

Update pin/unpin_chat_message

It is now possible to pin messages in basic groups as well as in the
own user's chat.
This commit is contained in:
Dan 2018-12-23 01:00:31 +01:00
parent 84fef9ecf1
commit 7ee89c94cb
2 changed files with 15 additions and 31 deletions

View File

@ -18,7 +18,7 @@
from typing import Union from typing import Union
from pyrogram.api import functions, types from pyrogram.api import functions
from ...ext import BaseClient from ...ext import BaseClient
@ -27,7 +27,7 @@ class PinChatMessage(BaseClient):
chat_id: Union[int, str], chat_id: Union[int, str],
message_id: int, message_id: int,
disable_notification: bool = None) -> bool: disable_notification: bool = None) -> bool:
"""Use this method to pin a message in a supergroup or a channel. """Use this method to pin a message in a group, channel or your own chat.
You must be an administrator in the chat for this to work and must have the "can_pin_messages" admin right in You must be an administrator in the chat for this to work and must have the "can_pin_messages" admin right in
the supergroup or "can_edit_messages" admin right in the channel. the supergroup or "can_edit_messages" admin right in the channel.
@ -49,19 +49,10 @@ class PinChatMessage(BaseClient):
:class:`Error <pyrogram.Error>` in case of a Telegram RPC error. :class:`Error <pyrogram.Error>` in case of a Telegram RPC error.
``ValueError`` if a chat_id doesn't belong to a supergroup or a channel. ``ValueError`` if a chat_id doesn't belong to a supergroup or a channel.
""" """
peer = self.resolve_peer(chat_id) self.send(
functions.messages.UpdatePinnedMessage(
if isinstance(peer, types.InputPeerChannel): peer=self.resolve_peer(chat_id),
self.send( id=message_id,
functions.channels.UpdatePinnedMessage( silent=disable_notification or None
channel=peer,
id=message_id,
silent=disable_notification or None
)
) )
elif isinstance(peer, types.InputPeerChat): )
raise ValueError("The chat_id \"{}\" belongs to a basic group".format(chat_id))
else:
raise ValueError("The chat_id \"{}\" belongs to a user".format(chat_id))
return True

View File

@ -18,14 +18,14 @@
from typing import Union from typing import Union
from pyrogram.api import functions, types from pyrogram.api import functions
from ...ext import BaseClient from ...ext import BaseClient
class UnpinChatMessage(BaseClient): class UnpinChatMessage(BaseClient):
def unpin_chat_message(self, def unpin_chat_message(self,
chat_id: Union[int, str]) -> bool: chat_id: Union[int, str]) -> bool:
"""Use this method to unpin a message in a supergroup or a channel. """Use this method to unpin a message in a group, channel or your own chat.
You must be an administrator in the chat for this to work and must have the "can_pin_messages" admin You must be an administrator in the chat for this to work and must have the "can_pin_messages" admin
right in the supergroup or "can_edit_messages" admin right in the channel. right in the supergroup or "can_edit_messages" admin right in the channel.
@ -40,18 +40,11 @@ class UnpinChatMessage(BaseClient):
:class:`Error <pyrogram.Error>` in case of a Telegram RPC error. :class:`Error <pyrogram.Error>` in case of a Telegram RPC error.
``ValueError`` if a chat_id doesn't belong to a supergroup or a channel. ``ValueError`` if a chat_id doesn't belong to a supergroup or a channel.
""" """
peer = self.resolve_peer(chat_id) self.send(
functions.messages.UpdatePinnedMessage(
if isinstance(peer, types.InputPeerChannel): peer=self.resolve_peer(chat_id),
self.send( id=0
functions.channels.UpdatePinnedMessage(
channel=peer,
id=0
)
) )
elif isinstance(peer, types.InputPeerChat): )
raise ValueError("The chat_id \"{}\" belongs to a basic group".format(chat_id))
else:
raise ValueError("The chat_id \"{}\" belongs to a user".format(chat_id))
return True return True