mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-28 04:48:06 +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:
parent
84fef9ecf1
commit
7ee89c94cb
@ -18,7 +18,7 @@
|
||||
|
||||
from typing import Union
|
||||
|
||||
from pyrogram.api import functions, types
|
||||
from pyrogram.api import functions
|
||||
from ...ext import BaseClient
|
||||
|
||||
|
||||
@ -27,7 +27,7 @@ class PinChatMessage(BaseClient):
|
||||
chat_id: Union[int, str],
|
||||
message_id: int,
|
||||
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
|
||||
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.
|
||||
``ValueError`` if a chat_id doesn't belong to a supergroup or a channel.
|
||||
"""
|
||||
peer = self.resolve_peer(chat_id)
|
||||
|
||||
if isinstance(peer, types.InputPeerChannel):
|
||||
self.send(
|
||||
functions.channels.UpdatePinnedMessage(
|
||||
channel=peer,
|
||||
id=message_id,
|
||||
silent=disable_notification or None
|
||||
)
|
||||
self.send(
|
||||
functions.messages.UpdatePinnedMessage(
|
||||
peer=self.resolve_peer(chat_id),
|
||||
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
|
||||
)
|
||||
|
@ -18,14 +18,14 @@
|
||||
|
||||
from typing import Union
|
||||
|
||||
from pyrogram.api import functions, types
|
||||
from pyrogram.api import functions
|
||||
from ...ext import BaseClient
|
||||
|
||||
|
||||
class UnpinChatMessage(BaseClient):
|
||||
def unpin_chat_message(self,
|
||||
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
|
||||
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.
|
||||
``ValueError`` if a chat_id doesn't belong to a supergroup or a channel.
|
||||
"""
|
||||
peer = self.resolve_peer(chat_id)
|
||||
|
||||
if isinstance(peer, types.InputPeerChannel):
|
||||
self.send(
|
||||
functions.channels.UpdatePinnedMessage(
|
||||
channel=peer,
|
||||
id=0
|
||||
)
|
||||
self.send(
|
||||
functions.messages.UpdatePinnedMessage(
|
||||
peer=self.resolve_peer(chat_id),
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user